HW14: Interpreter, Part II

25 points; due Wed 5/21 @ 11am.

Goals

To explore stacks and their uses, to learn some about how compilers and interpreters make sense of source code, and to get experience working with a large body of preexisting code.

Setup and Requirements

If you worked with a partner on Part I of this project, work with the same person. If you worked alone, work alone on this part too.

In this assignment you will continue making changes to the code that you worked with in Part I.

Your Tasks

Step 1: A Stack to Simulate Memory

To simulate memory, create a class CallStack that implements Stack<Method>. Specifically, your class must have the following signature:

public class CallStack implements Stack<Method>

Notice that there is no generic type parameter in the signature of your class. What this signature says is that the class CallStack implements all the methods defined in the interface Stack, with the generic type parameter for this interface replaced by the type Method. In other words, this is a specialized implementation of Stack that only deals with Method objects.

  1. Write your class using a different implementation than the one you used for Part I. So if you used an array-based implementation there, write CallStack as a link-based implementation, and vice-versa.
  2. Create a constructor for CallStack that takes a SimulationComponent as an argument, and saves a reference to the SimulationComponent as an instance variable.
  3. Whenever a Method is pushed onto your call stack, in addition to performing the push, call the addMethodToGraphicalStack() method of your SimulationComponent instance, passing it the Method that was just pushed.
  4. Similarly, whenever a method is popped, in addition to popping it off your call stack, call the removeMethodFromGraphicalStack() method of your SimulationComponent.
  5. Once it is fully working, you should be able to load and run programs, and watch as methods take up space in memory and use up a program’s stack space. You should not need to write any additional code to get this working, as the program will automatically check for the existence of your call stack.

Step 2: Handling Multiline Comments

Make your syntax checker handle multi-line comments, that is, comments within /* and */. Note that a “multi-line” comment may be in the middle of one line:

int a_hundred = 10 + /* 80 + */ 10;

and that it neither has to begin nor end at any special position in the line:

String Mary; /* she had a little lamb
a little lamb, a little lamb;
She had a little lamb,
but what about its fleece? */ Mary = "had a little lamb";

As with single-line comments in Part I, any opening or closing brackets contained within a multi-line comment should be ignored for the purposes of syntax-checking.

Implementing multi-line comments is a bit trickier than single-line comments. You should probably create some of your own “programs” to test your implementation.

Submission and Grading

Zip up all the files that you created or modified in this assignment or the last one into hw14.zip. Namely: your Stack ADT implementation file, CallStack.java, and your modified Program.java. Do not include any other files in your zip file. Submit your zip file on Moodle.

Start early, ask lots of questions, and have fun!

Grading