Python –
Lisp –
Prolog –
Snobol –
VRML –
Chapter 5 – Binding, types, Scopes
Chapter 6 – Data types
Chapter 7 – Expressions and Assignments
int fun(int *k){
*k += 4;
return 3 * (*k) -1;
}
void main(){
int i = 10, j=10, sum1, sum2;
sum1 = (i / 2) + fun(&i);
sum2 = fun(&j) + (j / 2);
}
Answer if left -> right evaluation
right -> left evaluation
highest: *, /, not
+, -, &, mod
-(unary)
=, /=, <, <=, >=, >
And
Or, xor
Left to right associativity
a * b -1 + c
a > b xor c or d <= 17
BNF for the precedence and associativity rules defined above:
<expr> ® <expr> or <e1> | <expr> xor <e1> | <e1>
<e1> ® <e1> and <e2> | <e2>
<e2> ® <e2> = <e3> | <e2> /= <e3> | <e2> < <e3>
| <e2> <= <e3> | <e2> > <e3> | <e2> >= <e3> | <e3>
<e3> ® <e4>
<e4> ® <e4> + <e5> | <e4> - <e5> | <e4> & <e5> | <e4> mod <e5> | <e5>
<e5> ® <e5> * <e6> | <e5> / <e6> | not <e5> | <e6>
<e6> ® a | b | c | d | e | const | ( <expr> )
Draw a parse tree for the two equations above to show the BNF holds the precedence.