Write a compiler and interpreter for RUM. RUM is an extension of pbrain, which in turn is an extension of brainf--k.
- Also, finish any two of the four tasks defined in Lab1-BF.pdf.
Your source code MUST be based on BF.java, a working partial solution to last year's lab. You source code must also test that it works for valid RUM programs.
First, update the parser, PrintVisitor
and InterpreterVisitor
for the pbrain subset of RUM.
You'll need to add in two new Node types for procedure definition and invocation.
Make sure it works with this program:
(++++++++++<[>+>+<<-]>>[<<+>>-])>::::::::::::::<<<<<<<--------.>>>---------.+++++++..>---------.<<<<<<<------.<--------.>>>>>---.>>>.+++.<.--------.<<<<<<<+.
That program is "Hello, World!" in pbrain.
In the InterpreterVisitor
you'll need this:
private byte[] array;
private int pointer;
public interface Procedure {
void execute();
}
private Procedure[] procedures;
Inside the visit method for Program, add this:
procedures = new Procedure[256];
It is NOT necessary to make multiple passes through the source code.
This language (RUM) is not that complex.
Don't forget to write (and test) the CompilerVisitor
for valid RUM programs!
Also: byte
in Java is signed. To make byte b
unsigned, do: b & 0xFF
You must complete this by the end of final exam time on August 10. However, do not wait until then to start.
This is a final exam. It is individual work. Therefore, submit your solution via email to [email protected]
If you submit your solution, and you do not receive email confirmation from me before August 10 that it works correctly, then you must attend the final exam period.