Project 6: Interpreting 'RayJay

By now you're all old hat at writing interpeters and other language systems using the visitor pattern. After spring break, you'll be ready for some really hard ones. To coast our way to spring break, here's a softball.

In class Monday and Wednesday we talked about implementing FunJay and looked at the code for the interpreter. On Friday we talked about adding arrays (and therefore specialized pointers) to FunJay to produce 'RayJay. You task is to write an interpreter for 'RayJay, extending the interpreter for FunJay.

1. Set up

Once again I'm giving you the parser, syntax tree and abstract syntax tree classes, and generic visitors for both the syntax trees and the abstract syntax trees.

Copy the file from the class directory and untar it.

cp /cslab/class/cs365/proj6.tar .
tar xvf proj6.tar

A driver program is also provided in Main.java.

2. Writing the visitor

A class rayjay.astvisitor.InterpretingVisitor is given to you. It is identical to the interpreter for FunJay, except that it has stubs for visitng indexed variables and creations. Your primary task is to write those two methods.

Remember that arrays are to be heap-allocated. You need to allocate them from the other end of memory. Memory, remember is the array mu. You will need another instance variable to keep track of the beginning of the heap, just as the variable a keeps track of the end of the stack.

3. Special considerations and requirements

All arrays are dynamic, like in Java. This means two array variables can be aliases of the same array. Also a method could create an array and return it. Thus arrays must be allocated on the heap.

Unlike Java, 'RayJay will do no bounds checking on array accesses, on either end. If the program contains, for example someArray[-5], the we will simply let it trample on memory, as in C. Remember, however, that this is the interpreter's "memory", stored in the array mu. The underlying Java implementation (which you're writing) still should not try to read outside of mu, which would of course throw a ArrayIndexOutOfBoundsException.

Take note that the stack and heap grow towards each other, and we're doing no garbage collection, so it may happen that they may collide and run out of room. It is reasonable that you may want to increase the size of memory (I have it as 1024), but it must be set to a fixed value when you compile InterpretingVisitor, so there is no way to prevent all programs from running out of memory.

Thus there are three possible run-time errors that a 'RayJay program may commit:

The second of these, if left unchecked, would result in your program throwing an ArrayIndexOutOfBoundsException. The others would result in wierd behavior. Rather, you must check for all of these. If the 'RayJay program commits any of these, your interpreter must halt, and an appropriate error message (identifying which of these four errors has occurred) must be displayed.

4. Turn in

To turn in this project, please copy your InterpretingVisitor.java to the turn-in directory I will prepare for you:

/cslab/class/cs365/turnin/proj6/xxxxxx

where "xxxxxx" is [andy|david|tyler|yelemis]. I will grade your project by running it against a collection of test files.

DUE: Friday, March 7, 5:00 pm. Have a nice break.


Thomas VanDrunen
Last modified: Mon Mar 3 11:16:55 CST 2008