CS170

Project Assignment 2

TARGET DATE : Thursday 4/9.

The goal of this assignment is to begin the semantic analysis function of your interpreter. The first step is to represent the lists internally via a tree structure. Once this is done, it is easy to implement basic functions quote, car, cdr, cons, and symbol?, as will be done in the next assignment.

Internal Representation of Lists

Modify your S_Expression() function so that it returns the underlying "cons-cell" structure of the list that it parses. For example, if your interpreter reads the list (a b c), then S_Expression() should return the structure:

                                          (links image)

To complement this, write a function printList() that, given a pointer to such a cons-cell structure, will print out the list in parenthesized form. Thus, given a pointer to the above structure, printList() will print out:

                                         (a b c)

Note that what you have now is a way to read the list in and represent it as the cons-cell structure, and a way to write that cons-cell structure back out so that the list looked like what you put in. This may seem silly, but trust me... the alternative is an extremely unwieldy interpreter. At this point, your interpreter should just take an s-expression and echo it back out, as in the sample run given right here. Of course, there is a trivial way to get the same effect (simply echo the string), but the only thing that matters in this assignment is what happens "behind the scenes."

A few tips on the cons-cell structure:


As stated above, once this is in place, it isn't too hard to get car, cdr, etc. to work. If you want to forge on ahead to the next assignment here it is; but do so only if you're very confident everything is working as it should!

Submission location is here.

Back to CS170 Assignments.

https://athena.clarku.edu/assignment/167