In this assignment, you will build an evaluator for MiniML, which is a subset of SML. You will start from a partial implementation that already includes a read-eval-print-loop user interface, a parser from text to abstract syntax trees (ASTs), a representation of the possible values resulting from evaluation, and various pretty-printing functions for ASTs and values. The partial implementation is available from your UW CSE account in the directory /cse/courses/csep505/03au/hw1; it also is available as a zip file for download. There is a skeleton for the evaluator (in file eval.sml), with a few cases implemented to get you started; you need to complete the implementation of the evaluator. The current evaluator raises ImplementMe in all cases that you need to write; your finished solution should not raise ImplementMe anywhere. (In future assignments, you'll add a type checker and a type inferencer.)
Here is a quick tour through the files of the MiniML implementation:
sml @SMLload=MiniML.x86-linuxThis will automatically start up the read-eval-print loop. There are similar sample solutions available for Solaris (MiniML.sparc-solaris) and Windows (MiniML.x86-win32).
The files are implemented in SML structures (a.k.a. modules). Local open declarations (a.k.a. imports) are used to allow the body of one structure to reference things declared in a different structure conveniently. You don't really need to know anything about structures, local, or open for this project; just write your code inside the body of the Eval structure in eval.sml.
You should turn in your version of the file eval.sml. In addition, we'd like you to answer the following questions:
val x = 3The result of f() is 3, not 4. Explain why.
fun f() = x
val x = 4
f()
fun f(x) = (let val x = 3 in x*x end) + xThe result of f(2) is 11. In this invocation of f, the first two uses of x in the body have value 3, while the last use of x has value 2. How does the binding from x to 3 get removed from the environment in your interpreter?
f(2)