2 // An ambiguious grammar with ambiguity resolved using precedence rules
5 datatype T :: lexeme = IDENT | INTEGER ;
7 syntax class Expressions {};
11 // '*' and '/' bind tighter to the left
12 // '+' and '-' have lower precedence
16 E(int) : E '+' E { $$ = $1 + $3; }
17 | E '-' E { $$ = $1 - $3; }
18 | E '*' E { $$ = $1 * $3; }
19 | E '/' E { $$ = $1 / $3; }
20 | '(' E ')' { $$ = $2; }