Ch 23, Exercise 2. In this exercise you will define Language
Four, an extension of Language Three listed below:
<exp> ::= fn <var> => <exp> | <addexp>
<addexp> ::= <addexp> + <mulexp> | <mulexp>
<mulexp> ::= <mulexp> * <funexp> | <funexp>
<funexp> ::= <funexp> <rootexp> | <rootexp>
<rootexp> ::= let val <var> = <exp> in <exp> end
| ( <exp> ) | <var> | <const>
Here is a sample program in Language Four, showing all the new
constructs:
let
val fact = fn x => if x < 2 then x else x * fact(x-1)
in
fact 5
end
As you can see, Language Four extends Language Three with three new
constructs: the < operator for comparison, the
- operator for subtraction, and the conditional
(if-then-else) expression. The sample program above
defines a recursive factorial function and uses it to compute the
factorial of 5. Define the syntax of Languague Four by extending
the syntax of Language Three and give a natural semantics for
Language Four.