Assignment 2 - Part 3

Ryerson University

Syntax Tree Generation

JJTree Set up

You will be using JJTree for this part of the assignment. JJTree is a JavaCC preprocessor which generates code to construct ASTs. It is bundled with JavaCC.

  1. Once you are satisfied with the work you have done in part 2, make a backup of it before continuing because it is very easy to mess things up with JJTree.

  2. Create a subdirectory called AST in your working directory. This will be used for all your AST classes.

    Explanation: JJTree is going to generate lots of AST classes. You will probably want to delete all of these classes each time you make modifications to your AST. Therefore it is useful to have them all in the same directory, particularly since you won't be modifying them for this assignment. JJTree does have options to generate packages, but there are open tickets on these features and in packaging in general in the JavaCC forum. Try at your own risk. Instead, you can simply set things up to put all the AST modules in one directory.

  3. HL.jjt:

  4. Make: Use this makefile and its associated options file.


  5. Test your set up before proceeding further. If your HL.jj was compiling and working properly before these changes, HL.jjt should continue to do so.

  6. Now you will need to replace 2 files to continue:


Modify your HL.jjt to construct AST's in "multi" mode (i.e. each production generates its own AST node).

Here are some special requirements:

  1. Tokens in AST:

    JJTree will not put any tokens in your AST, but you will want to keep a few from the grammar:

  2. Comparisons:

    You should have one ASTcomparison class (where the nodes have 3 subtrees) to deal with all comparisons.

  3. Operations:

    You should rationalize the names and structures of the AST nodes that represent operations:

  4. Other nodes:

    Since you are building an AST, you should remove useless nodes which only represent syntactic constructs that have no inherent meaning. This means that in addition to the nodes already discussed, you will be left with the following from the grammar:

    var_decl, ident_list, fn_decl, param_decls, param_decl, body, assignment, if_stat, clause, for_stat, foreach_stat, while_stat, fn_call, parameters, stop_stat, return_stat, print_stat, isatype, comparison, indexed, polyn.

    Here are further requirements along with some explanations of the less obvious deletions and modifications to the above structures:

  5. Please check the directory of tests and their results for examples of what was just explained.


This page is maintained by Sophie Quigley (cps710@scs.ryerson.ca)
Last modified Wednesday, 02-Nov-2016 01:45:52 EDT