JastAddJ: The JastAdd Extensible Java Compiler
JastAddJ is an extensible compiler for Java, implemented using JastAdd. The compiler consists of basic modules for Java 1.4, and extension modules for Java 1.5 and Java 7. (The language extensions introduced by Java 6 were very minor, and are included in the Java 1.5 modules.)
The following OOPSLA 2007 paper describes the architecture of the JastAddJ compiler, and the Java 1.4 and Java 1.5 modules:
Torbjörn Ekman, Görel Hedin: [The JastAdd Extensible Java Compiler](http://fileadmin.cs.lth.se/sde/publications/papers/2007-Ekman-OOPSLA.html). OOPSLA 2007: 1-18, Proceedings of the 22nd Annual ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications, October 2007, Montreal, Canada.
The Java 7 modules were implemented as a M.Sc. project, and are described in the following report:
Jesper Öqvist: [Implementation of Java 7 Features in an Extensible Compiler](http://sam.cs.lth.se/ExjobGetFile?id=477). Master's Thesis LU-CS-EX: 2012-13, Dept of Computer Science, Lund University, 2012.
Although JastAddJ is built as a research project, it is a high quality compiler that can compile large Java programs. It is about 3 times slower than javac, which we think is very good for a generated compiler. You can use JastAddJ to build your own languages on top of Java, or to build program analyses for Java. See JastAddJ-Extensions for examples.
Components
The compiler consists of six components, each in a subdirectory, allowing you to build semantic checkers and compilers for Java 1.4, Java 1.5, and Java 7:
Java1.4Frontend: A front-end for Java 1.4 that performs parsing, name analysis, type analysis, and compile-time error checking. A main program,
JavaChecker, reads Java source files and outputs compile-time errors. Another main program,JavaPrettyPrinter, additionally does pretty-printing.Java1.4Backend: An extension of Java1.4Frontend to form a full Java 1.4 compiler. A main program,
JavaCompiler, parses Java source code, outputs compile-time errors and generates bytecode.Java1.5Frontend: An extension of Java1.4Frontend that implements the language extensions defined in Java 1.5, including generics with wildcard support, the enhanced for statement, and static imports. Has main programs
JavaCheckerandJavaPrettyPrinter, like its 1.4 counterpart.Java1.5Backend: An extension of the Java1.5Frontend and the Java1.4Backend to form a full Java 5 compiler, generating Java bytecode. A main program,
JavaCompiler, parses Java source code, outputs compile-time errors and generates bytecode.Java7Frontend: An extension of the Java1.5Frontend that implements the language extensions defined in Java 7, including the try-with-resources statement, strings in switch, the diamond operator, improved numerical literals, multi-catch, more precise rethrow, and safe varargs. This module has main programs
JavaCheckerandJavaPrettyPrinter, like its 1.4 and 1.5 counterparts.Java7Backend: An extension of the Java7Frontend and the Java1.5Backend to form a full Java 7 compiler, generating Java bytecode. A main program,
JavaCompiler, parses Java source code, outputs compile-time errors and generates bytecode.
Download
You can browse and/or check out the latest stable version of JastAddJ from an SVN repository:
> svn checkout http://svn.cs.lth.se/svn/jastadd-oxford/projects/branches/JastAddJ-stable/
Build
All tools needed (jastadd2, jflex, beaver, etc.) are included. You only need to have javac and Apache Ant installed in order to build.
Build the component you are interested in by running ant in its directory. Some components use the specifications in other components, so make sure they are all in sibling directories (as they will be if you check out the complete JastAddJ).
> cd Java7Backend > ant
Note when running on Windows/Cygwin: Make sure that ant is in your PATH environment variable. Why? To build the Java 1.5 components, JastAdd needs to be run with more than the default heap size. This is handled by letting ant call itself using an exec task with a larger heap (see the build.xml files).
Run
How to run the programs JavaChecker, JavaPrettyPrinter in the frontends:
cd Java7Frontend > java JavaChecker java-source-files > java JavaPrettyPrinter java-source-files
How to run the program JavaCompiler in the backends:
cd Java7Backend > java JavaCompiler java-source-files
See what options are available, e.g., for classpath:
> java JavaChecker -help > java JavaPrettyPrinter -help > java JavaCompiler -help
