Example AST generator for
Compilers Fall 2015

This example consists of eight files:

    README                  # this file
    Main.java               # driver program
    AstNode.java            # all the AST node classes
    Tack.g4                 # grammar with semantic actions
    Visitor.java            # superclass for tree traversal
    SyntaxTreePrinter.java  # AST printer
    TreeNormalizer.java     # AST normalizer

To compile and run, do the following:

1. Use the parser generator to translate from Tack.g4 to TackParser.java:

    java -jar /usr/local/lib/antlr-4.5-complete.jar \
    -no-listener -no-visitor Tack.g4

2. Use the Java compiler to translate the *.java files to *.class files:

    javac -g -cp /usr/local/lib/antlr-4.5-complete.jar -Xlint:unchecked *.java

3. Use the AST generator to print an AST for an input file:

    java -ea -cp .:/usr/local/lib/antlr-4.5-complete.jar Main 001.in

4. Clean up intermediate files:

    rm TackParser.java *.class

For example, given the following input file:

    # example for AST generation
    f = fun
    g = fun

The AST generator will print the following output:

    --- Raw AST ----
    Program
      FunDefListHead
        FunDef
          FunId f
        FunDefListTail
          FunDef
            FunId g
          FunDefListTail
    --- Normalized AST ----
    Program
      FunDef
        FunId f
      FunDef
        FunId g
