%{ open Syntax %} %token LPAREN RPAREN SEMISEMI %token PLUS MULT LT %token IF THEN ELSE TRUE FALSE %token INTV %token ID %start toplevel %type toplevel %% toplevel : Expr SEMISEMI { Exp $1 } Expr : IfExpr { $1 } | LTExpr { $1 } LTExpr : PExpr LT PExpr { BinOp (Lt, $1, $3) } | PExpr { $1 } PExpr : PExpr PLUS MExpr { BinOp (Plus, $1, $3) } | MExpr { $1 } MExpr : MExpr MULT AExpr { BinOp (Mult, $1, $3) } | AExpr { $1 } AExpr : INTV { ILit $1 } | TRUE { BLit true } | FALSE { BLit false } | ID { Var $1 } | LPAREN Expr RPAREN { $2 } IfExpr : IF Expr THEN Expr ELSE Expr { IfExp ($2, $4, $6) }