CIS 505/705 Assignment 5

Use SML/NJ to write an interpreter for a simple imperative language with procedures that take parameters. Its syntax is given by the grammar

Your interpreter should take a program written in that syntax, and return a list of the values printed. To allow you to focus on the semantic aspects, a parser has been provided for you. It converts an input string into operator trees that are represented using SML datatypes.

As an example program, consider the following that computes the factorial of 4:

Given the above program as input, your interpreter should thus return the list [1,24].

As another example, consider the following program that also computes the factorial of 4:

Here your interpreter should return the list [4,3,2,1,0,1,2,3,4,24].

You need to make several decisions about the semantics of the language. In comments, you should explain and motivate your choices, but you must allow mutual recursion and must not allow an integer variable to be called. If the input program contains one or more errors, your interpreter should still terminate normally but with an informative message as designed by you (use exceptions for that).

You may do this exercise solo or with a partner. If you choose the latter, you and your partner will submit one and the same program.

Submit to K-State Online a .sml-file containing the interpreter. You should also construct some test programs (in addition to the one above), and include a text-file log of those and their outputs.

Torben Amtoft