Happy Context-Dependent Operator Precedence
I have two snippets of Happy code here, one that uses normal precedence rules, and one that uses context-dependent precedence rules (both of which are described here ). Normal: %left '+' %left '*' %% Exp :: { Exp } : Exp '+' Exp { Plus $1 $3 } | Exp '*' Exp { Times $1 $3 } | var { Var $1 } Context-dependent: %left PLUS %left TIMES %% Exp :: { Exp } : Exp '+' Exp %prec PLUS { Plus $1 $3 } | Exp '*' Exp %prec TIMES { Times $1 $3 } | var { Var $1 } Given the input: a * b + c * d The normal version gives: Plus (Times (Var "a") (Var "b")) (Times (Var "c") (Var "d")) whereas the context-dependent