Create your submission repository, and copy your dream folder into it, replacing the starter code that is there.
See the Symbol Table notes for more details.
Your SymbolTable must be accessible to multiple tree walker classes, because it will be used both during semantic analysis and code generation. One way to do this is to make it a singleton.
Create a class named SemanticChecker that inherits from the ANTLR-generated cps450.DreamBaseListener. This will be a “Tree Walker” class, whose methods get invoked during a depth-first traversal of the parse tree.
Define a new class named Type, like this:
public class Type {
public static final Type
ERROR = new Type("<error>"),
INT = new Type("int"),
BOOLEAN = new Type("boolean"),
...
protected String name;
protected Type(String name) {
this.name = name;
}
}
This class defines several type constants that you will use in your semantic checker by writing Type.INT, Type.BOOLEAN, etc.
I suggest that you start by writing methods for the following nodes:
For starters, just do variable declaration checks (no type checks) to exercise your SymbolTable class.
Then, add code to your main program to invoke your SemanticChecker on the parse tree (see step 5), and run your program on the test programs in /tests/phase3/semcheck/decls.
After you’ve got that working, you can move on to type checking.
See the examples/interpreter project for an example of how to invoke your semantic checker after the parse has completed.