|
| 1 | +<SUBSECTION> |
| 2 | + <NAME> |
| 3 | + CSE Machine |
| 4 | + </NAME> |
| 5 | + |
| 6 | + <LABEL NAME="sec:cse-machine"/> |
| 7 | + <INDEX>CSE machine<OPEN/></INDEX> |
| 8 | + |
| 9 | + <SPLIT> |
| 10 | + <JAVASCRIPT> |
| 11 | + <TEXT> |
| 12 | + The environment model as presented so far focuses on how functions can refer |
| 13 | + to their parameters, locally declared names, and names that are declared |
| 14 | + outside the function. We achieve this by evaluating statements and expressions |
| 15 | + with respect to a <EM>current environment</EM>. It does not specify how |
| 16 | + we keep track of environments as computation proceeds. For example, when we |
| 17 | + evaluate an expression <JAVASCRIPTINLINE>f(x) + y</JAVASCRIPTINLINE>, we |
| 18 | + need to evaluate <JAVASCRIPTINLINE>x</JAVASCRIPTINLINE> in the current |
| 19 | + environment, establish as the new current environment the environment of |
| 20 | + <JAVASCRIPTINLINE>f</JAVASCRIPTINLINE> extended by a binding of its |
| 21 | + parameter to the value of <JAVASCRIPTINLINE>x</JAVASCRIPTINLINE>, and |
| 22 | + evaluate the body of <JAVASCRIPTINLINE>f</JAVASCRIPTINLINE> in this |
| 23 | + extended environment. But what environment should we use for evaluating |
| 24 | + <JAVASCRIPTINLINE>y</JAVASCRIPTINLINE> after |
| 25 | + <JAVASCRIPTINLINE>f</JAVASCRIPTINLINE> returns? |
| 26 | + In this section, we extend the |
| 27 | + </TEXT> |
| 28 | + |
| 29 | + <SUBHEADING><NAME>Evaluating arithmetic expressions</NAME></SUBHEADING> |
| 30 | + |
| 31 | + <TEXT> |
| 32 | + Exercise<SPACE/><REF NAME="ex:3_8"/> shows that the presence of |
| 33 | + assignments makes the result of a program depend on the order in which |
| 34 | + the operands of an operator combination are evaluated. To remove |
| 35 | + ambiguities that arise from this, the JavaScript standard specifies |
| 36 | + left-to-right evaluation of operands. |
| 37 | + |
| 38 | + As an example, consider the evaluation of the arithmetic expression statement |
| 39 | + <SNIPPET> |
| 40 | + <JAVASCRIPT> |
| 41 | +1 + (2 * 3); |
| 42 | + </JAVASCRIPT> |
| 43 | + </SNIPPET> |
| 44 | + The expression is decomposed into its operands |
| 45 | + <JAVASCRIPTINLINE>1</JAVASCRIPTINLINE> and |
| 46 | + <JAVASCRIPTINLINE>2 * 3</JAVASCRIPTINLINE>, followed by the |
| 47 | + <EM>instruction</EM> to add their results. |
| 48 | + </TEXT> |
| 49 | + <INDEX>CSE machine<CLOSE/></INDEX> |
| 50 | + </JAVASCRIPT> |
| 51 | + </SPLIT> |
| 52 | +</SUBSECTION> |
0 commit comments