ExtendJ: The JastAdd Extensible Java Compiler
ExtendJ is an extensible compiler for Java, implemented using JastAdd. The compiler consists of basic modules for Java 1.4, 1.5, 6, 7, and 8.
The following OOPSLA 2007 paper describes the architecture of the ExtendJ 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 module was 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.
- Jesper Öqvist, Görel Hedin: Extending the JastAdd extensible Java compiler to Java 7. PPPJ 2013:147-152, Proceedings of the 2013 International Conference on Principles and Practices of Programming on the Java Platform: Virtual Machines, Languages, and Tools, September 2013, Stuttgart, Germany.
The Java 8 module was implemented as a M.Sc. project, and are described in the following report:
- Erik Hogeman: Extending JastAddJ to Java 8. Master's Thesis LU-CS-EX: 2014-14, Dept of Computer Science, Lund University, 2014.
Note that ExtendJ was previously called "JastAddJ".
Although ExtendJ 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 ExtendJ to build your own languages on top of Java, or to build program analyses for Java. See ExtendJ-Extensions for examples.
Licenses
ExtendJ is licensed under the Modified BSD License:
Copyright (c) 2005-2015, ExtendJ Committers
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
3. The name of the author may not be used to endorse or promote
products derived from this software without specific prior
written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Components
ExtendJ contains these top-level directories:
- src: Contains generic Java source files, generated source files, and resource files. The
src/java
subdirectory 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 1.5.
- java6: Java 6 extension. The semantic difference between Java 1.5 and 6 is minimal, so this extension is very small.
- java7: Java 7 extension.
- java8: Java 8 extension.
Each javaN directory contains extensions to the Java support based on the java(N-1) modules. Each such directory also contains
the subdirectories grammar
, frontend
, parser
, 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,
parser
and scanner
include the parser and scanner specifications respectively.
Download
You can get the latest ExtendJ version from ExtendJ's bitbucket. ExtendJ can either be downloaded from bitbucket as a compressed archive or using Git:
> git clone git@bitbucket.org:extendj/extendj.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.
> # Old 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
and adding the
name of the Java version you want to build the compiler for:
> ant java7 jar
> ant java8 jar
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:
> java -cp extendj.jar org.extendj.JavaChecker $JAVA_SOURCE_FILES
> java -cp extendj.jar org.extendj.JavaPrettyPrinter $JAVA_SOURCE_FILES
How to run the program JavaCompiler
:
> java -jar extendj.jar $OPTIONS $JAVA_SOURCE_FILES
See what options are available:
> java -jar extendj.jar -help