Assignment 4 -- PTT13


Always make sure to pull/clone/download the latest 101simplejava repo.

See the instructions here:

Starting point

Either of the following contributions:


The task consists of two milestones. First, revise the chosen contribution to use a flat (denormalized) representation of companies, as described in the previous assignment. Second, revise the chosen contribution to implement Feature:Depth.


Invoking ANTLR

Whenever you change Company.g, you need to invoke ANTLR to get up-to-date files and Note that you need to "refresh" in Eclipse if you have generated code outside Eclipse.

There are two major ways as to how you can invoke ANTLR. One option is to run "gradle build" on the revised project. Another option is to invoke ANTLR on the command line:

java -cp ".:antlr-3.2.jar" org.antlr.Tool Company.g

This command line generates and in the same directory. Here is assumed that the ANTLR jar iand Company.g are in the current directory. If you ran gradle, you do have ANTLR already on your system (somewhere), but it may be tricky to find it. (Also, you make need to add more jars to the classpath, as ANTLR may be split up.) You can download a "complete" ANTLR jar from here:

Picking the right starting point

Any of the three projects is sort of equally suitable, but consider the following tradeoffs. If you pick antlrAcceptor, then it is easy to just focus initially on changing the grammar to model the flat representation. If you pick antlrParser, then it is easy to revise the semantic actions for Feature:Total to do Feature:Depth instead. If you pick antlrObjects then it is easy to just do Feature:Depth in plain Java code, but you still need to revise semantic actions for AST construction.


A test is needed to parse some input and compute the nesting depth of departments. Other tests (be it for Feature:Total or Feature:Cut or others, depending on the chosen starting point), do not need to be preserved.