CS 4980 CC: Assignment 3: Symbol Table Display

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.

Steps:

  1. Add the productions from mjava-grammar.txt to your minijava grammar file.
  2. Check that your code parses andor.mj
  3. Following the construction for the SableCC Class Lister, extend your solution to list class names. You can just copy 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.
  4. Write a visitor to display all variables and use it to display all of the variables in each class. This will mean creating an instance of the variable lister and applying it to the class members. Note this code will also be useful for listing method information; see below.

    Alternatively: it is acceptable to extend ClassLister.java to handle displaying variables.

  5. Write a visitor (or extend 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.