This assignment will give you experience using the Visitor Pattern and SableCC to process MiniJava programs. More specifically, your solution will read MiniJava programs and print tables showing the identifiers.
mjava-grammar.txt
to your
minijava grammar file.
andor.mj
ClassLister.java
to your project if you like, but you may find it more convenient to
modify it to just list class names as they are encountered rather than
adding them to an array list.
Alternatively: it is acceptable to
extend ClassLister.java
to handle displaying variables.
ClassLister.java
) to display
all methods in a class, using the variable lister to list all parameters
for methods (other than main
)
and all variables defined within a method. You will likely find it
helpful to modify the grammar to list parameters. The current grammar
simply classifies each (formal) parameter as an id. If you add a
production to the effect of
parameter → id(and change
formal_list
to use that production), then you
get a distinct name that will help you process parameters separately from
other identifiers.
When you are finished, your system will display a very simple symbol table
for MiniJava programs. For example, if the input
is andor.mj
, the output will be
andor main AndOr x AssignX parameter: num parameter: other ComputeIt parameter: stuff result(where the
a
in andor
is in column 0). Note how
scope is captured by indentation in the output.
Ensure your solution meets the coding standards for this course and submit it on esubmit.