| Overall Reading | |
|---|---|
| Brookshear: | pp. 255-262 |
| Decker/Hirshfield: | Mod. 6.4 |
Outline:
The goal for this lecture is to examine the program translation process more closely, using examples which involve arithmetic expressions.
Example 1:
W = X + Yvs.
LOD X ADD Y STO W
However, it is common to use an equal sign to designate statements of assignment. In this context,the statement "X=Y" may be interpreted as an instruction that the value of a variable X should be set so that it equals the value currently associated with Y ("let X equal Y").
Different computer programming languages have adopted different syntax to differentiate equality tests versus assignment statements.
Example 2:
W = (X+Y)/(Z+8)vs.
LOD Z ADD 8 STO T1 LOD X ADD Y DIV T1 STO W
Expression: number
or
variable
or
( [Expression] [Operator] [Expression] )
Operator: '+' or '-' or '*' or '/'
Examples of expressions according to that grammer would include:
More General Expressions
From algebra, we are used to dealing with a relaxed definition of
arithmetic expression, that are not so strictly parenthesized. Such
relazed grammers are often used in computing as well. See
Figure 5.14 of [Br], for example.
Avoiding ambiguity Unfortunately, the grammer given in Figure 5.14 is ambiguous (See Question 3 of Ch. 5.4, on p. 264 of [Br]).
How should the following be interpreted?
Let's look at some examples using Rosetta software from the Decker/Hirshfield text.
Let's look at some examples using Rosetta software from the Decker/Hirshfield text.