Java Compiler Compiler

The JavaCompilerCompiler or JavaCC as it is usually called is a parser generator developed in Java by a team originally at Sun.

It is an LL parser and, as such, detects parse errors earlier than LR parsers. This can be especially handy for interpreters, but takes some getting used to if you're accustomed to LR parsers such as yacc.

It works something like this:

  1. First define the grammar for the language you want to parse. This is done in a BackusNaurForm-like manner following a defined syntax and placed in a jj file. You have to know some about how the compiler compiler works to do this correctly.
  2. Then generate the parser classes from your jj file. You will get a number of source files that have all the functionality to perform the parse.
  3. Connect the generated code with whatever controlling class you like.

There is also a preprocessor (JJTree) available that preprocess a grammar and inserts code for generating a parse tree. It can be told to generate code that supports the Visitor pattern and the result is a very powerful way to inspect and mutate the tree.

-- FredrikRubensson
Similar projects

AntlrTranslatorGenerator does something similar. It can also generate C++.

Gobo ( does something similar. It generates Eiffel.
A good book on object oriented java parsers (imperative, logic, database etc) is "Building Parsers With Java" uses UML and comes with CD with all the code.

View edit of May 17, 2006 or FindPage with title or text search