COMPILER TECHNIQUES FOR MATLAB PROGRAMS ... - CiteSeerX
COMPILER TECHNIQUES FOR MATLAB PROGRAMS ... - CiteSeerX
COMPILER TECHNIQUES FOR MATLAB PROGRAMS ... - CiteSeerX
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
[nr,nc] = size(x)<br />
avg = sum(x) / nc<br />
(a)<br />
function avg = mean(x)<br />
[nr,nc] = size(x)<br />
avg = sum(x) / nc<br />
(b)<br />
Figure 3.2: M-le to compute the mean of a vector using (a) script and (b) function.<br />
accept parameters and operates on the scope of the caller. Figure 3.2 (a) shows a script le<br />
to compute the mean of vector x. Notice that the variable avg is updated with the mean of<br />
x, that is a variable in the scope of the program of function that called the script.<br />
A function diers from a script in that arguments may be passed, and that variables<br />
dened and manipulated inside the le are local to the function and do not operate on<br />
the workspace of its caller.<br />
Figure 3.2 (b) shows a function to compute the mean of a<br />
vector. Notice that in this example, the body of the function is the same as the script le<br />
however, the function's input variable is given as an argument, and the output is dened<br />
in the function denition. One important characteristic of M-le functions in <strong>MATLAB</strong> is<br />
that they are side-eect free. This functionality can be used to facilitate the exploitation of<br />
functional parallelism [GP92] and loop parallelism.<br />
To avoid confusion, from here on when the term function is used alone in the text, it will<br />
refer to M-le functions and built-in functions only, and not to script les. Similarly, the<br />
term M-le will refer to M-le functions and not to script les.<br />
3.2.2 Scanner, Parser, and the Symbol Table Generation<br />
Initially, aLALR(1) grammar [ASU85] was dened for <strong>MATLAB</strong>, as there is no publicly<br />
available grammar for the <strong>MATLAB</strong> language. The compiler accepts as input a <strong>MATLAB</strong><br />
script (from here on referred to as main program), that maycontain several M-le calls. The<br />
lexical analyzer, which is generated by lex [LS], reads and converts the main program into a<br />
stream of tokens that are processed by a syntax analyzer, which is generated by yacc [Joh],<br />
15