Parjac2
 
General
About
GIT

Contacts
Robert Olofsson
robo@khelekore.org

 

About


Parjac2 is an experiment in building a java compiler.
It is supposed to be built to be easy to read, easy to run and extend. It may be used for parsing or compiling other things in the future.

The basic parts of parjac are

  • Written with a generic lexer and parser that ought to work for many more languages.
  • Written with modern java in mind and using java 25 as the test bed of functionality and speed.
  • A hand written java lexer. See CharBufferLexer.java.
  • An earley based parser. See Parser.java. This meaans that it is fast and has good error handling.
  • A grammar that tries to stay true to the grammar in §19 of the java 25 jls. See java25.pj.
  • It uses the ClassFile api to actually generate class files.
  • It compiles given source files or full directory structures of input files.

Grabbing the code

git clone http://www.khelekore.org/parjac2/parjac2.git

Compiling and running

  • Building the compiler: mvn package
  • Compiling a simple file: java -jar target/parjac2-1.0-shaded.jar Foo.java
  • Compiling a directory of files: java -jar target/parjac2-1.0-shaded.jar -i src/ -d /tmp/out/
  • If you do not give any command line arguments (as in run with java -jar target/parjac2-1.0-shaded.jar) you will get a usage clause.
  • Complex example: java -jar target/parjac2-1.0-shaded.jar -cp /a/foo_library.jar:/b/bar_library.jar --release 21 -i src -d target/classes

You can of course also use any other maven targets, possibly mvn compile or mvn test

It is also possible to run the current test program from the command line, something like this can be used:
java --module-path=target/classes/ --module org.khelekore.parjac2/org.khelekore.parjac2.java11.TestParser /tmp/some/File.java
java --module-path=target/classes/ --module org.khelekore.parjac2/org.khelekore.parjac2.java11.TestParser -print_syntax /tmp/some/File.java
or
mvn exec:java -Dexec.cleanupDaemonThreads=false -Dexec.mainClass=org.khelekore.parjac2.java11.BatchCompiler -Dexec.args="-i source_directory/ -d destination_directory/"

  • It can compile itself and several other small projects
  • Generics is a work in progress, so programs using advanced generics may not yet compile.
  • It can correctly compile many programs, the test suite has grown quite large