next up previous
Next: Left-to-right evaluation Up: Interpreting the Program Previous: Interpreting the Program

   
Expression evaluation

One of the properties of an expression is its value. Every expression has a value, and this section deals only with expressions whose values are determined by local information. A binary operator is regarded as a function taking two values called Left and Right and delivering the result. All values are integers.

Expression evaluation[35] :

ATTR Value, Left, Right: int;

RULE: Exp ::= num
COMPUTE
  Exp.Value=num;
END;

RULE: Exp ::= Exp Binop Exp
COMPUTE
  Exp[1].Value=Binop.Value;
  Binop.Left=Exp[2].Value;
  Binop.Right=Exp[3].Value;
END;

RULE: Exp ::= '(' Stm ',' Exp ')'
COMPUTE
  Exp[1].Value=Exp[2].Value;
END;
This macro is defined in definitions 35 and 37.
This macro is invoked in definition 49.

The dependences among computations in these rules are direct data dependences. For example, the value of a dyadic expression depends on the result of the binary operator because there is a direct assignment of one to the other.

All of the dyadic operations follow a general pattern, which can be described once. Again, the dependence of the result value on the left and right operand values is clear because it is the result of a function having them as arguments:

Implementation of a binary operator[36]  \ensuremath{(\diamond2)}:

RULE: Binop ::= \ensuremath{\diamond1}
COMPUTE
  Binop.Value= \ensuremath{\diamond2}(Binop.Left,Binop.Right);
END;
This macro is invoked in definition 37.

The first parameter is the operator indication, and the second is the built-in LIDO operation implementing the corresponding operation on integer values:

Expression evaluation[37] :

Implementation of a binary operator[36](`'+'',`ADD')
Implementation of a binary operator[36](`'-'',`SUB')
Implementation of a binary operator[36](`'*'',`MUL')
Implementation of a binary operator[36](`'/'',`DIV')
This macro is defined in definitions 35 and 37.
This macro is invoked in definition 49.


next up previous
Next: Left-to-right evaluation Up: Interpreting the Program Previous: Interpreting the Program
William Waite
1998-08-30