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. 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. 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.
JastAddJ contains these top-level directories:
- src: Contains generic Java source files, generated source files, and resource files. The
src/javasubdirectory contains the compiler and semantic checker main classes.
- java4: Contains all Java 1.4-related grammars, aspects, parser and lexer speciications.
- java5: Extends the Java 1.4-support to Java 5.
- java6: Java 6 extension.
- java7: Java 7 extension.
Each javaN directory contains extensions to the Java support based on the java(N-1) modules. Each such directory also contains
scanner. As may be expected the
grammar directory contains the
abstract grammar specifications,
frontend contains frontend modules aspect files,
backend contains the backend aspect files,
scanner include the parser and scanner specifications respectively.
You can get the latest JastAddJ version from JastAddJ's bitbucket. JastAddJ can either be downloaded from bitbucket as a compressed archive or using Git.
Our SVN repository for JastAddJ is still available, though it is no longer updated and we encourage you to switch to our bitbucket repository:
> svn checkout http://svn.cs.lth.se/svn/jastadd-oxford/projects/branches/JastAddJ-stable/
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
> 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
call itself using an
exec task with a larger heap (see the
How to run the programs
JavaPrettyPrinter in the frontends:
> java -cp jastaddj.jar org.jastadd.jastaddj.JavaChecker java-source-files > java -cp jastaddj.jar org.jastadd.jastaddj.JavaPrettyPrinter java-source-files
How to run the program
> java -jar jastaddj.jar options java-source-files
See what options are available:
> java -jar jastaddj.jar -help