- WAE
The WAE language has numbers, two arithmetic operators (
+,-), identifiers andwithexpressions. Of course, to handle identifiers andwithexpressions you'll have to implement substitution.- Binary arithmetic operators
In place of having separate rules for
+and-, define a single syntactic rule for all binary arithmetic operators. Parse these into abinopdatatype variant. Define a table that maps operator names (symbols) to actual functions (Scheme procedures) that perform the corresponding operation. Having a single rule like this, accompanied by a table, makes your language easier to extend: once you have modified your parser and interpreter once to support binary operators, you won't need to touch either one to add any number of new ones. To demonstrate this, define multiplication and division (using*and/to represent them in the language's concrete syntax).- Multi-armed
with Each identifier bound by the
withexpression is bound only in its body. There will be zero or more identifiers bound by eachwithexpression. If there are multiple bindings of the same identifier in a singlewithexpression's bindings list, your interpreter should halt with an error message. An example:{with {{x 2} {y 3}} {with {{z {+ x y}}} {+ x z}}}will evaluate to
7, while{with {{x 2} {x 3}} {+ x 2}}will halt with an error message.