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.
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.
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.
CallStack
as a link-based implementation, and vice-versa.CallStack
that takes a SimulationComponent
as an argument, and saves a reference to the SimulationComponent
as an instance variable.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.removeMethodFromGraphicalStack()
method of your SimulationComponent
.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.
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!
CallStack
— 8 points