CS 2135 (A01) Homework 4: Interpreters

Due: September 27 (Thursday) at 11:59pm via turnin (assignment name hwk4).

Assignment Goals


The Assignment

Our current Curly language and interpreter support only simple arithmetic functions. In order to support interesting programs, Curly must at least support recursion and some more complex data. In this assignment, we add lists and simple if-statements to the language.

For lists, we want to add support for the following Curly expressions:

For if-statements, we want to add a simple version of if that will allow us to avoid adding booleans to the language. We are therefore going to add a form of if (called if-empty) whose test expression evaluates to a list. If the list is empty, the then branch is taken, otherwise the else branch is taken.

Given lists and if-empty, the following would now be a valid Curly program:

    {define sum {proc {numlist}
      { if-empty numlist
        then return{0}
        else return{ head{numlist} + sum{ tail{numlist} , n}}}}
    }

  1. Augment the data definition for Curly to include the four list expressions described above (emptylist, cons, head, and tail) and if-empty expressions.

  2. Modify the interpreter to handle your augmented Curly data definitions. Your modified interpreter should work on recursive programs over lists (such as sum).


What to Turn In

Turn in a single file hwk4.ss (or hwk4.scm) containing all code and documentation for this assignment. Make sure that both students' names are in a comment at the top of the file.


Hints and Guidelines


Back to the Assignments page