Where should I initialize variables for an OO Recursive Descent Parse Tree?
Posted
by Vasto
on Stack Overflow
See other posts from Stack Overflow
or by Vasto
Published on 2010-05-21T04:17:25Z
Indexed on
2010/05/21
4:20 UTC
Read the original article
Hit count: 253
I'd like to preface this by stating that this is for a class, so please don't solve this for me.
One of my labs for my cse class is creating an interpreter for a BNF that was provided. I understand most of the concepts, but I'm trying to build up my tree and I'm unsure where to initialize values. I've tried in both the constructor, and in the methods but Eclipse's debugger still only shows the left branch, even though it runs through completely.
Here is my main procedure so you can get an idea of how I'm calling the methods.
public class Parser {
public static void main(String[] args) throws IOException {
FileTokenizer instance = FileTokenizer.Instance();
FileTokenizer.main(args);
Prog prog = new Prog();
prog.ParseProg();
prog.PrintProg();
prog.ExecProg();
}
Now here is My Prog class:
public class Prog {
private DeclSeq ds;
private StmtSeq ss;
Prog() {
ds = new DeclSeq();
ss = new StmtSeq();
}
public void ParseProg() {
FileTokenizer instance = FileTokenizer.Instance();
instance.skipToken(); //Skips program (1)
// ds = new DeclSeq(); ds.ParseDS(); instance.skipToken(); //Skips begin (2) // ss = new StmtSeq(); ss.ParseSS(); instance.skipToken(); }
I've tried having
Prog() {
ds = null;
ss = null;
}
public void ParseProg() {
FileTokenizer instance = FileTokenizer.Instance();
instance.skipToken(); //Skips program (1)
ds = new DeclSeq();
ds.ParseDS();
...
But it gave me the same error. I need the parse tree built up so I can do a pretty print and an execute command, but like I said, I only get the left branch.
Any help would be appreciated. Explanations why are even more so appreciated.
Thank you, Vasto
© Stack Overflow or respective owner