Tool Chain
This page deals with the practical aspects of compiler implementation exercises.
Java, Eclipse
We assume you have a recent JDK and an Eclipse >=3.5.
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.2 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.
Ant and the Standard Project Template
Ant is a build tool for Java (not the latest greatest, but solid and boring). The Standard Project Template uses 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 Template contains the Ant build script build.xml and some example code. It expects you to keep your grammar files in grammar/ and your hand-written source code in src/.
The 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.
Starting with sheet 2, you will get a specialized template for each exercise sheet. For sheet 2, read the strategy for test-driven development of grammars.
Version history
- 5.0.1
- Spiglet to Kanga.
- 4.x
- MiniJava to Spiglet
- 3.0
- Test-driven development of typecheckers.
- 2.0
- Test-driven development of grammars. No longer a general project template.
- 1.1
- Fixed generation of JAR files outside Eclipse; put more files into JAR file
- 1.0
- Initial version
Download from the exercises page.
Installing Libraries
The Standard Project Template assumes that the Library Package is installed.
How to install the Library Package on a computer:
- Download the Library Package. Unzip it to some convenient directory. (NEW: with a SableCC with line numbers)
- Create the file compiler-construction-ws2010.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
- compiler-construction-jars.zip, the Library Package
- compiler-construction-ws2010.properties, the config file template
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.