The Grammar |
---|
<expr> |    ::=    | ( if <bool-expr> <expr> <expr> ) |
   |    | ( cond { ( <bool-expr> <expr> ) }* ( else <expr> ) ) | |
<bool-expr> |    ::=    | #t |
   |    | #f | |
   |    | <compare-expr> | |
   |    | <logical-expr> | |
<compare-expr> |    ::=    | ( equal <expr> <expr> ) |
   |    | ( greater <expr> <expr> ) | |
   |    | ( lesser <expr> <expr> ) | |
<logical-expr> |    ::=    | ( and <bool-expr> <bool-expr> ) |
   |    | ( or <bool-expr> <bool-expr> ) | |
   |    | ( xor <bool-expr> <bool-expr> ) |
Parser |
---|
Modify your existing unparse function to work with the new abstract syntax and parse function.
Your scanner specification must now accept Boolean literals "#t" and "#f"; note that these literals must scan into distinct tokens, or you will not be able to tell them apart later.
Interpreter |
---|
The cond construct should evaluate to only the first expression that corresponds to a true condition. If none of the clauses has a true condition, the else clause is always taken to be true.
Notes: