Software and Documentation

Language: Java 1.5.0 ( documentation, API, tutorial, download).

Tools: Sample Main.java

Formatting Visitors: Each formatter can be used to format an AST for output in textual format. Remember to use the -printer option when you run JTB on the jj file, which will generate a few visitors necessary for formatting. Once that's done, a given AST can be output to standard output as follows:
   ast.accept(new PigletFormatter());
   ast.accept(new TreeDumper());

Other Links

Detecting software plagiarism
How to write unmaintainable code

Quick How-to to compile a minijava to piglet compiler

% java -jar jtb132.jar minijava.jj  # generates jtb.out.jj

% javacc jtb.out.jj              # generates a parser with a specified name

# now code the visitors to compile java to piglet.

% javac Main.java                # Main.java contains a call of the parser, and visitors
                                 # you need to download this file or create your own in your 
                                 # working directory. (You might get some warnings about 
                                 # unchecked calls which you can ignore.)

% java Main < p.java > p.pg      # builds a syntax tree for p.java, and  executes 
                                 # the visitors, output a piglet program

% java -jar pgi.jar < p.pg       # run the piglet program. 

JTB Overview

JTB is a syntax tree builder to be used with the Java Compiler Compiler (JavaCC) parser generator.  It takes a plain JavaCC grammar file as input and automatically generates the following:  New visitors, which subclass DepthFirstVisitor or GJDepthFirst, can then override the default methods and perform various operations on and manipulate the generated syntax tree.  For more information about the Visitor design pattern, see the book Design Patterns: Elements of Reusable Object-Oriented Software
 
Usage:   java -jar jtb132.jar [OPTIONS] [input-file]
         java -jar jtb132.jar -h     # to view all available options

Using Interpreters

The Interpreters can be used to test the programs generated by your compiler. The Interpreter should give the same output as the original java program.

To invoke the interpreter use: java -jar [pgi.jar | kgi.jar] < [input-program]

Since Spiglet is a subset of Piglet, the Piglet interpreter can be used to interpret spiglet programs. A Spiglet Parser has been provided which can be used to make sure the program parses as a spiglet program. It can be invoked using java -jar spp.jar < [Input-program]. If your program is a spiglet program it will print "Program parsed successfully". This does not mean that the program will run correctly make sure you run it with the piglet interpreter to check it runs correctly.