CS 341 - Survey of Programming Languages
Homework #5

Due: Tuesday 10/4 at the beginning of class

Note: This work is to be done in pairs.  Each pair will submit one assignment.  Although you may divide the work, both team members should be able to present/describe their partner's work upon request.  All written exercises are to be done in a README file.  All Scheme code is to be done in a file hw5.scm.  All exercises should be clearly labeled or commented.

1. EOPL Ex. 2.7 (due Thursday 9/29 in class).  Note: In our previous implementation, lexical-address essentially did parsing (determination of the expression's structure) and substitution of lexical address information for variables.  In this exercise, we separate the parsing/unparsing task from the lexical address substitution task.  Our new lexical-address now works with the expression datatype to substitute lex-info and free-info variants for var-exp variants.  Thus, to do the same computation as our old lexical-address, we (1) parse-expression, (2) lexical-address (transforming environment datatype), and (3) unparse-expression.

In the future, we'll want to do much more with the expression datatype.  The prime lesson here is that we can and should separate parsing-related tasks from abstract syntax tree manipulation tasks.

2. EOPL Ex. 2.10.  Use the grammar of p. 52 (Fig. 2.2)

3. EOPL Ex. 2.11.  Use the grammar of p. 52 (Fig. 2.2)

4. EOPL Ex. 2.13.  Use the procedure name all-term-ids rather than all-ids to avoid name clash with earlier exercises.  As lexical-address worked with expression datatypes in Ex. 2.7, all-term-ids should work with the term data type of Ex. 2.13.

5. EOPL Ex. 2.14.  Clarification: pop merely removes the top element of the stack and does not return it.  That is, the return type of pop is a new stack without the top element.  Hint: For our environment interface specification, we had two constructors (empty-env, extend-env) and one observer (apply-env).  The stack environment has three constructors (empty-stack, push, pop) and two observers (top, empty-stack?).  A suitable mathematical abstraction for a stack is a sequence (e.g. {}, {v1, v2, ..., vn}).  You will find that the stack and the environment interfaces have much in common.

For each programming exercise, you're required to include in your file the test examples given in the text.  In addition, you're encouraged to develop a good test suite beyond the limited text examples.