Project 4: Interpreting 'RayJay

Hopefully by now you've seen enough of the Jay family examples that you understand the basic structure of the Jay interpreters and can think in terms of the visitor pattern. The intent in this project is that you can focus on the new feature we're implementing.

In this project you will complete the 'RayJay interpreter by making a few very specific changes to the old FunJay interpreter.

1. Set up

Copy the file from the class directory and untar it.

cp ~tvandrun/Public/cs365/proj5.tar .
tar xvf proj6.tar

The contents will be similar to previous projects. The class with the main method is rayjay.RayJay.

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 things related to arrays. Your primary task is to fill-in the following methods:

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], then 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.

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

  1. If an array access is so far out of bounds that it actually goes out of bounds of memory (mu) altogether.
  2. If a new procedure call happens or new local scope is entered but there is no more room for it without invading what the heap has already allocated (stack and heap collide when the stack is growing).
  3. If a new array is created, but there is no more room for for it without invading what the stack has already allocated (stack and heap collide when the heap is growing).

The first 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. (Error 2 is already handled for you in the method allocate(). Error 1 needs to be handled in visit(LeftHandSide), visit(IndexedVariable), and visit(Assignment). Error 3 needs to be handled in visit(Creation).)

5. Turn in

Copy your InterpreterVisitor.java to

/cslab/class/cs365/turnin/proj5/xxxxxx

where "xxxxxx" is [lily|chet|christopher|tim|david|ben|caleb]. I will grade your project by running it against a collection of test files.

DUE: Wednesday, Feb 17, 5:00 pm.


Thomas VanDrunen
Last modified: Thu Feb 16 09:46:25 CST 2012