Special Edition 

JTB GJ Home 

  • What's GJ
  • Overview
  • How to Obtain JTB GJ
  • Requirements
  • Using JTB GJ
  • Questionnaire





    Standard JTB Home 

  • JavaCC
  • Design Patterns
  • Javasoft
  • GJ
    Jump to Java!
    JTB GJ1.1.2 was released on May 15, 2000.  It is a special version of JTB, which generates syntax trees that work with GJ

    What's GJ

    GJ is a design that extends the Java programming language with the generic types and methods.  For example, GJ can support the following codes: 
    interface Collection<A> { 
       public void add(A x); 
       public Iterator<A> iterator(); 
    The main benefit of GJ over the current Java programming language lies in the added expressiveness and safety that stems from making type parameters explicit and making type casts implicit.  GJ is designed to be fully backwards compatible with the current Java language, and in particular, one can retrofit existing library classes with generic interfaces without changing their codes.  For details about GJ and downloading GJ compiler, please go to GJ web page


    JTB GJx.x is a syntax tree builder to be used with the Java Compiler Compiler (JavaCC) parser generator.  JTB GJx.x generates type-casting free syntax trees by using gj packages, specifically Vector<A> and Enumeration<A> in gj.util.  It takes a plain JavaCC grammar file as input and automatically generates the following: 
    • A set of syntax tree classes based on the productions in the grammar, utilizing the Visitor design pattern.
    • Four sets of visitors:
      • Visitor.java interface and DepthFirstVisitor.java class
      • GJVisitor interface and GJDepthFirst class
      • GJNoArguVisitor interface and GJNoArguDepthFirst class
      • GJVoidVisitor interface and GJVoidDepthFirst class
    • A JavaCC grammar with the proper annotations to build the syntax tree during parsing.
    • gj packages (gj.util and gj.lang).
    New visitors, which subclass any of the above visitor classes, 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

    How to Obtain JTB GJx.x

    Both compiled executables and source code for the newest version of JTB GJ are available.  You can download them here.  Also available are some examples of its use. 


    JTB GJx.x requires a Java 1.1 or higher virtual machine.  In addition, it is compatible with JavaCC 0.6.x, or higher.  GJ compiler is needed to compile the syntax tree generated by JTB GJx.x. 

    Using JTB GJx.x

    After downloading and installing JTB GJx.x, using it is a matter of running it on your .jj JavaCC grammar file with the command 
      % jtbgj yourgrammar.jj
    This will generate 
    • The subdirectory syntaxtree containing a class for each production in the grammar.
    • The subdirectory visitor:
      • Visitor.java interface and DepthFirstVisitor.java class, which support visitors with neither return value nor additional argument. 
      • GJVisitor.java interface and GJDepthFirst.java class, which support visitors with both return value and an additional argument.
      • GJNoArguVisitor.java interface and GJNoArguDepthFirst.java class, which support visitors with return value but no additional argument.
      • GJVoidVisitor.java interface and GJVoidDepthFirst.java class, which support visitors with an additional argument but no return value.
    • The file jtb.out.jj, the original grammar file now with syntax tree building code inserted.
    • The subdirectory gj containing gj packages (gj.util and gj.lang).
    See the documentation for more information about these files. 

    To generate your parser, simply run JavaCC on jtb.out.jj with the command 

    % javacc jtb.out.jj
    Once you are familiar with the specifics of the tree JTB GJx.x generates (see the documentation for details) as well as programming using the Visitor design pattern, writing your own visitors is a cinch.  Simply subclass DepthFirstVisitor, GJDepthFirst, GJNoArguDepthFirst or GJVoidDepthFirst, overriding the methods you need to. 

    You can compile all the generated classes by executing GJ compiler on your class containing the main() method: 

    % gjc filename.java
    GJ compiler will generate .class files executable on Java Virtual Machine, so you can run your program by: 
    % java filename
    We are interested in your opinion of JTB GJ!  To find out what you think of it, we use the same questionnaire as that of the standard JTB.  We would really appreciate if you took the time to answer. 

    Maintained by Wanjun Wang, wanjun@purdue.edu.
    Created September 4, 1997. 
    Last modified May 15, 2000.