%{ (* Exprpar.grm: parser specification for expression language MRH 4/11 04 *) open Absyn; %} %token INT %token VAR %token LT CONJ DISJ NEGATION %token PLUS MINUS TIMES EQ %token END IN LET %token IF THEN ELSE %token LPAR RPAR %token EOF %left ELSE /* lowest precedence */ %left MINUS PLUS /* middle precedence */ %left TIMES /* highest precedence */ %left DISJ %left CONJ %nonassoc NEGATION %start Main %type Main %type Expr %type <(string * Absyn.expr) list> DLIST %type BExpr %% Main: Expr EOF { eval $1 } ; DLIST: /* empty string */ { [] } | VAR EQ Expr DLIST { ($1, $3) :: $4 } ; BExpr: Expr LT Expr { Lt($1, $3) } | Expr EQ Expr { Eq($1, $3) } | BExpr CONJ BExpr { Conj($1, $3) } | BExpr DISJ BExpr { Disj($1, $3) } | NEGATION BExpr { Negation $2 } | LPAR BExpr RPAR { $2 } Expr: VAR { Var $1 } | INT { Int $1 } | MINUS Expr { Mminus $2 } | LPAR Expr RPAR { $2 } | LET DLIST IN Expr END { Let($2, $4) } | Expr TIMES Expr { Times($1, $3) } | Expr PLUS Expr { Plus($1, $3) } | Expr MINUS Expr { Minus($1, $3) } | IF BExpr THEN Expr ELSE Expr { Ite($2, $4, $6) } ;