1 Assignment
2 NO PARSING
3 Frank Talk About Test Cases
4 Values
5 Language Forms
5.1 A note on mutation of environments
5.2 Where is mutation required?
6 Primitive Functions
7 Incomplete Specification
8 Hints
9 Sample Code
10 Requirements
11 Handin

Assignment 1, CSC431, Spring 2010

1 Assignment

You must implement an interpreter for the language that you’ll later be writing a compiler for. Let’s call this language Footle. I don’t know why I picked that name. Your solution will map Footle programs to answers, as described below.

2 NO PARSING

Your assignment does not need to include a parser.

More specifically, your program will map ASTs (defined below) to Footle Values (also defined below).

The ASTs consumed by your interpreter will be the same ones produced by your parser. This means that you’ll be able to check your parser (when you write it as part of a later assignment) by connecting it to this interpreter.

3 Frank Talk About Test Cases

Do you like writing test cases? How about writing test cases before writing the program? I’m betting the answer is no. So why bother?

In a nutshell, the reason is this: if you’re not sure how to write the test case, you’re really really not sure how to write the program.

Test cases don’t need to be complex. The most important test cases you write are the simple ones. Here’s a simple one:

  should equal (IntV 3) (eval emptyEnv (IntExp 3))

That is, evaluating the expression 3 should produce the number 3.

You should have a simple test case for every simple clause in your interpreter, and then some complex test cases that test everything all together.

Write the simple test cases first. It’s the simplest test cases that are going to show you how to implement the corresponding language forms; the more complex test cases help to isolate more subtle issues. If you start with a giant hairy test case, you’re going to spend hours debugging simple problems.

Finally, if you do discover a problem with a complex test case, don’t just dive into the debugger; debuggers are the fool’s first resort, and you can spend hours just watching the values bounce around. Instead:

The "thinking" part is generally the hardest.

4 Values

The values are the possible results of interpreting an expression. They include the following:

5 Language Forms

In the Footle interpreter, there is no distinction between statements and expressions, or between programs and expressions. Everything is just an expression. This simplifies the interpreter.

The words ’interpret’ and ’evaluate’ are used interchangeably in this text.

The words ’field’ and ’slot’ are used interchangeably in this text.

That’s it! Well, unless we decide to add more things in later assignments.

5.1 A note on mutation of environments

Mutating environments: don’t do it. Your interpreter will wind up buggy. More specifically, make sure that when you extend an environment with new bindings, that references to the old environment are still unchanged, containing all the same bindings. The easiest way to guarantee this is never to mutate a variable that refers to the environment. (Note that mutating the bindings within an environment is not only okay, but in fact required in order to implement variable mutation. I’m just talking about mutating the environment itself.)

5.2 Where is mutation required?

Mutation is required in several places: the value associated with each binding must be mutable, the value associated with each slot must be mutable, and the set of slots associated with an object must be mutable (so you can add fields on the fly).

6 Primitive Functions

You’re required to implement a number of primitive functions. These primitive functions should appear in a base environment used by all calls to the interpreter.

7 Incomplete Specification

I’m sure there are ambiguities, missing primitives, and probably outright errors in this specification. Post to the newsgroup when you discover them.

8 Hints

For Heaven’s sake, develop this project incrementally. For instance, you can develop an interpreter that only handles constants. Then, you can add primitives, and the application of primitives. Don’t try to swallow the elephant in one bite.

9 Sample Code

This assignment comes with an archive containing sample code. This archive includes a number of things that will be important.

Honestly, most of these things can live somewhere else, but the simplest way to deal with them all is just to have them in the same directory. To compile the project, you’ll need to edit the makefile to point to your system’s fsc.exe file. To build sample.exe, run

  make

To run the tests, run

  make sampleruntests

10 Requirements

Develop the ’interp’ function, that accepts an env and an exp and returns an fVal.

11 Handin

Use the directory "Assignment1" in your subdirectory of the class subversion repository to hand in your work. for this assignment. See the course web page for more information on the subversion repository and how to use it.

Your submission should include the following files:

Contents of the TEAM file: one line for each team member with that member’s login id, a comma, and then his or her full name. So, if Benjamin Franklin were working with George Washington, this file might contain:

bfrankli, Benjamin Franklin

gwashing, George Washington

The order of the lines is not important. You must supply this file even if you’re working alone.