Imp Interpreter

The Grammar

program →  cmpd-stmt
stmt-list →  (empty) | stmt | stmt SEMICOLON stmt-list
stmt →  assign-stmt | cmpd-stmt | if-stmt | if-else-stmt |
while-stmt | write-stmt | writeln-stmt
assign-stmt →  IDENTIFIER := expr
cmpd-stmt →  BEGIN stmt-list END
if-stmt →  IF expr THEN stmt
if-else-stmt →  IF expr THEN stmt ELSE stmt
while-stmt →  WHILE expr DO stmt
write-stmt →  WRITE LPAREN expr RPAREN
writeln-stmt →  WRITELN LPAREN RPAREN
expr →  or-expr
or-expr →  and-expr | or-expr OR and-expr
and-expr →  rel-expr | and-expr AND rel-expr
rel-expr →  add-expr | add-expr < add-expr | add-expr <= add-expr |
add-expr > add-expr | add-expr >= add-expr |
add-expr = add-expr | add-expr <> add-expr
add-expr →  mult-expr | add-expr + mult-expr | add-expr - mult-expr
mult-expr →  unary-expr | mult-expr * unary-expr | mult-expr DIV unary-expr |
mult-expr MOD unary-expr
unary-expr →  prim-expr | - unary-expr | + unary-expr | NOT unary-expr
prim-expr →  INTEGER | TRUE | FALSE | IDENTIFIER | LPAREN expr RPAREN

imp.rkt

lexer.rkt

tree.rkt

parser.rkt

exec.rkt

eval.rkt

error.rkt