next up previous contents
Next: Literal Up: Evaluation Rules Previous: Evaluation Rules   Contents

Expr

<

Expr    ::= if Expr then Expr else Expr | Expr1
Expr1   ::= Expr2 {  =>  Expr2 }*
Expr2   ::= Expr3 {  ||  Expr3 }*
Expr3   ::= Expr4 {  &&  Expr4 }*
Expr4   ::= Expr5 [ { == | != | < | > | <= | >= } Expr5 ]
Expr5   ::= Expr6 { AddOp Expr6 }*
AddOp   ::= +  |  ++  |  -
Expr6   ::= Expr7 { MulOp Expr7 }*
MulOp   ::= *
Expr7   ::= [ UnaryOp ] Expr8
UnaryOp ::= -  |  !
Expr8   ::= Primary [ TypeQual ]
Primary ::= ( Expr ) | Literal | Id | List
            | Binding | Select | Block | FuncCall

The grammar lists the operators in increasing order of precedence. The binary operators at each precedence level are left-associative.

<

The evaluation rules for conditional, implication, disjunction, conjunction, comparison, AddOp, MulOp, UnaryOp, and parenthesized expressions are shown in Tables A.4 and A.5. There are seven remaining possibilities for a Primary: Literal, Id, List, Binding, Select, Block, and FuncCall. These are treated separately in subsequent sections.


Table A.4: Evaluation rules for conditional, implication, disjunction, and conjunction expressions. As defined in Section A.3.4.7, _is_bool(b) is true if b is a value of type t_bool and false otherwise.
\begin{table}{\small\begin{verbatim}// conditional expression
Eval( if Expr_1 ...
... , C);
if (_is_bool(b) == false) error;
return b;
}\end{verbatim}}
\end{table}



Table A.5: Evaluation rules for comparison, AddOp, MulOp, UnaryOp, and parenthesized expressions.
\begin{table}{\small\begin{verbatim}// comparison
Eval( Expr_1 == Expr_2 , C) ...
...arenthesization
Eval( ( Expr ) , C) = Eval( Expr , C)\end{verbatim}}
\end{table}




Allan Heydon, Roy Levin, Timothy Mann, Yuan Yu