I am doing a project where I have to make a Facile program that reads and executes statements line by line.
Example would be like:
LET A 5
ADD A 8
PRINT A
END
and that would print 13 to the console
So I have a class for each of the function methods(like ADD, SUB, GOTO,PRINT,MULTI,etc)
I have a ProgramState class that holds all my methods for the function classes.
Below is just the first part of the class, I didnt think it was necessary to paste all
the methods for the function statements
private int programCounter;
private int[] variables;
private Stack<Integer> stack;
public ProgramState()
{
programCounter = 1;
variables = new int[26];
stack = new Stack<Integer>();
}
I also have an abstract class called Statement that all my classes for the function methods extend to
public abstract class Statement
{
public abstract void execute(ProgramState state)
throws FatalException;
}
I have a Parser class that takes in a file, parses it, and returns the info as a arraylist of statements. I included a brief overview of the class
// this reads and parses the file then stores it in an arrayList
public static ArrayList<Statement> parseProgram(String filename)
throws IOException
// this method just contains what to do with the info from the file
// like if the line says "LET" do this if it says "PRINT" then do this, etc.
private static Statement parseLine(String line)
I have a Stack class which is like how you would build a linked list but you can only access the top one at a time. The stack is, at least I think, just for making a stack in the ProgramState to keep track of the line numbers with GOSUB's and REUTRN's
I also have a main class that I am suppose to use to create an Interperator object among other things but obviously I'm not there yet.
So I have to write an Interperator class and I am a bit lost on how to start. Do I create objects of some of my other classes (like Parser / ProgramState) and call some of there methods? Do I write some new methods? I'm not looking for the actual syntax of how to do it, hence why I left out the majority of my code, but just the logic behind it and how to generally start.