What's better, ANTLR or JavaCC?

Jason picture Jason · Dec 19, 2008 · Viewed 24.5k times · Source

Concerns are documentation/learnability, eclipse integration, tooling, community support and performance (in roughly that order).

Answer

Wilfred Springer picture Wilfred Springer · Jan 30, 2010

There are a couple of alternatives you shouldn't rule out:

  • JParsec is a parser combinator framework that allows you to construct your parser entirely from code.
  • Scala's parser combinator framework addresses a similar concern; however, Scala's syntax makes all of this much more readable.
  • Then there's also the parser combinator framework done by John Metsker, for his book Building Parsers With Java; I don't remember exactly where the library is, but it was at least floating around on the Internet in the past. It addresses the same concern: you don't define your grammar and token definitions in a separate non-Java file; instead, it's all Java.
  • Fortress, the programming language Sun has been working on for years now seems to be build on this toolkit: Rats. I don't have much information, but I reckon if they use it for their new programming language, it probably has some interesting features.

In general, I get the impression that the years of the code generators are over. If I would be you, I would use Scala's parser combinator toolkit. Basically, any IDE supporting Scala, also 'supports' this parser combinator framework. Performance is good, AFAICT.

By the way, ANTLR has quite decent IDE support, as an Eclipse plugin (but perhaps there's also something in IntelliJ - I don't remember.) So, if you would opt for the classic approach of defining your lexical analyzer and parser outside of your language, then ANTLR should be your choice, I think. It has the biggest mindshare among Java developers, there is tool support, and there is a great book by the author of ANTLR. I don't think any of the other toolkits can claim that.