I'm getting quite confused about how I can create an javacc interpreter, particularly how to build a symbol table from an AST tree generated previously.
Something like this, from this AST:
> Program
> Id
> Id
> Id
> VarDecl
> Type
> Id
> Stl
> Id
> NewInt
> IntLit
> Sta
> Id
> IntLit
> ParseArgs
> Id
> IntLit
> Sta
> Id
> IntLit
> ParseArgs
> Id
> IntLit
(…)
To this table
=== Symbol table ===
Name Type Init Values
---- ---- ---- ------
args args[] true 2 12 8
x int[] true 2 4 0
With this Input for example
class gcd {
public static void main(String[] args) {
int[] x;
x = new int[2];
x[0] = Integer.parseInt(args[0]);
x[1] = Integer.parseInt(args[1]);
if (x[0] == 0)
System.out.println(x[1]);
else
while (x[1] > 0) {
if (x[0] > x[1])
x[0] = x[0] - x[1];
else
x[1] = x[1] - x[0];
}
System.out.println(x[0]);
}
}
What i have now, only creates the AST.
My big issue is how to define and then compare the Types on tree, one by one.
Any help would be great, including theory.
Thanks.