Project 6: 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 interpreters we have seen for FunJay and NestFunJay. 'RayJay is an add-on to FunJay, not NestFunJay, but the 'RayJay interpreter will encorporate ideas from the NestFunJay interpreter---for example, static information will be stored in public instance variables in the abssyntree classes.

1. Set up

Copy the file from the class directory and untar it.

cp ~tvandrun/Public/cs365/proj6.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.InterpreterVisitor is given to you. It is similar to the interpreter for NestFunJay, except the parts dealing with nested functions is removed and it has stubs for visitng things related to arrays. Note the following instance variables in the abssyntree classes for storing information computed by the type checker:

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 funjay.AbstractMu.IllegalAccessException. Your code should catch this and display an appropriate error message, not a stack trace. Your error message should indicate whether the illegal access was the target of the assignment, another part of the lefthand side, or an indexed variable.

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 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 exception. 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 visit(CallStmt). 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.all/ubuntu/cs365/turnin/xxxxxx/proj5

where "xxxxxx" is [alisa|andrew|becca|cheney|daniel|drew|johncharles|kendall|turk]. I will grade your project by running it against a collection of test files.


Thomas VanDrunen
Last modified: Thu Feb 23 10:26:11 CST 2012