Uni-Logo
OrganisationExercisesTools and SupportForum

Tool Chain

This page deals with the practical aspects of compiler implementation exercises.

Java, Eclipse

We assume you have a recent JDK (a Java 6 JDK is recommended for Eclipse 4.2) and an Eclipse >= 4.2 (Juno).

SableCC

SableCC is a parser generator for Java. From a grammar specification, it generates Java classes for syntax tree nodes, a parser, a lexer and skeletons for the Visitor pattern.

The stock version 3.6 of SableCC uses plain side-effect-only visitors (where a visitor's per-node methods can only communicate by changing the state of the visitor). We have extended SableCC to generate alternative visitor classes where per-node methods get one extra parameter and a return type, helping you write stateless visitors. You can use either kind of visitor classes. Furthermore, it has support for line number and position information in nodes not just in tokens.

Ant and the Standard Project Templates

Ant is a build tool for Java (not the latest greatest, but solid and boring). The Standard Project Templates use it to generate the parser, compile the parser together with your hand-written code, check your code for style compliance, and to build a submission-ready executable JAR file.

The Standard Project Templates contain the Ant build script build.xml and some example code. They expect you to keep your grammar files in grammar/ and your hand-written source code in src/.

A Standard Project Template is also an Eclipse project, so you should be able to import it into Eclipse using "Import/ General/ Existing Projects into Workspace". Do not use "Import/General/Archive File", that does the wrong thing.

You will get a specialized template for each exercise sheet. From exercise 2 on sheet 1 the corresponding Standard Project Template will support test driven development. Please read the strategy for test-driven development of grammars.

Version history

1.0
Initial version

Download from the exercises page.

Installing Libraries

The Standard Project Templates assume that the Library Package is installed.

How to install the Library Package on a computer:

  1. Download the Library Package. Unzip it to some convenient directory.
  2. Create the file compiler-construction-ws2012.properties from the template. Fill in the directory into which you unpacked the Library Package. Put it into your home directory, which is /home/USERNAME on Linux machines and /Users/USERNAME on Macs. If you'd rather use Windows, fine -- the method for finding out your "home directory" is described in the Ant troubleshooting section. Your "home directory" is then value of user.home.

Download

Building and Running

This section assumes that you have installed everything so far.

Eclipse Ant view

So you've imported your project and changed its name. You can interact with the Ant build file using the Ant view of Eclipse. Open the Ant view ("Window/Views/Ant"). There is a plus-button there. Use it to add the build.xml of your project to the Ant view. The Ant view should now contain a tree of Ant targets.

Building

If you're using Eclipse, double-click on one of the Ant targets. In particular, target compile compiles your grammar and your code. On the command line, just say ant compile to compile.

Submitting

Submissions consist of an executable Jar file with source inside. The Ant target jar generates one (after checking your code style).

Checkstyle Complaints

Before building a Jar file, the jar target checks if your code complies with the Coding Rules. It uses CheckStyle. Take the complaints seriously and fix all of them before submitting.

Debugging the Build

The Ant target printenv will print some of the important configuration variables to stdout. If you ask for setup help, be sure to include its output. If build.xml does not even get as far as printing its settings, use printenv.xml instead.