In each part of the assignment, implement the function parse,
which consumes an expression in the language’s concrete syntax and returns
the abstract syntax representation of that expression, as well as the function
interp, which consumes both an abstract syntax expression (as
returned by the parse function) and an environment and returns a
CFWAE-value. Please include a contract for every function that you
write and include test cases that amply exercise all of the code you’ve
written.
To save the trouble of having to add boolean values and operators over them,
create the construct if0 using the syntax described by the EBNF below.
Note that if0 has three branches:
Evaluation should signal an error for non-numeric test values.
funExtend the fun language feature described in lecture so
that functions can accept a list of zero or more arguments instead of
just one. All arguments to the function must evaluate with the
same deferred substitutions. To simplify your program, you may
assume that the number of arguments in a function invocation always
matches the number in the procedure definition. For example:
{{fun {x y} {* x y}} 2 3}
evaluates to 6.
The syntax of the CFWAE language with these additional features can be captured with the following EBNF:
<CFWAE> ::= <num>
| {+ <CFWAE> <CFWAE>}
| {- <CFWAE> <CFWAE>}
| {* <CFWAE> <CFWAE>}
| <id>
| {if0 <CFWAE> <CFWAE> <CFWAE>}
| {with {{<id> <CFWAE>} ...} <CFWAE>}
| {fun {<id> ...} <CFWAE>}
| {<CFWAE> <CFWAE> ...}
In this grammar, the ellipsis (...) means that the previous
non-terminal is present zero or more times.
This assignment builds on the previous. If you know your rudimentary interpreter had problems, and you fix those problems in your extended interpreter, and you provide test cases to prove this, and you tell us what you fixed, we’ll give you back any points that you lost for functionality.
Describe what you fixed in comments at the top of your program.