June 27, 2004

ANTLR vs. JavaCC

I have recently had the need for a parser.  The grammar I have to parse is reasonably simple but I have studied and written enough compilers in these past fifteen years to know better than hand-coding a parser myself (actually, the lexer is usually what turns out to be the trickiest part).  I used to use lex, yacc, bison, etc...  in the past so it was only natural to take a look at ANTLR and JavaCC.

Since I am fairly familiar with this family of tools, what I am looking for is pretty simple:  a tutorial that will quickly fill me in on the syntax used to describe the lexer and the parser and how to invoke the tool.

ANTLR provided me just that.  The home page leads you to a Getting Started guide that tells me exactly what I want to know.  After ten minutes of research and reading, I feel qualified to start writing my first ANTLR grammar.

The experience with JavaCC was...  quite different.

First of all, JavaCC's home page doesn't make the documentation link very obvious. Scroll to the bottom to find a few links, but even this doesn't turn out very useful pointers:  FAQ, repository of grammars, installation and getting started (which actually only tells you how to install the software but not how to use it) and finally the complete documentation.

I am not looking for the complete documentation but I am running out of options, so that's what I end up clicking.  The page itself is still not the "complete documentation" but yet another collection of links that I have to wade through in order to find what I am looking for.  Needless to say my patience is running thin at this point and I am about to give up, especially when I see that the only tutorials on this page are about how the "lookahead processing" is performed and how the token manager works.

At this point, I just give up and I know I'll be using ANTLR.

Here is a quick advice to everyone who wants to make their software appealing:  I know how tempting it is to expose the technical brilliance of the internals of your software, but just don't give in to it.  Think carefully about your users, ask yourself why they would want to use your software and make sure that you design your documentation and your Web site with that in mind.

Posted by cedric at June 27, 2004 11:46 AM
Comments

Hi,

I recently wrote a compiler for a Template Engine myself and went through the same process you did. I however decided to use JavaCC after a while mainly because I didn't want to have an antlr.jar in my classpath, cause unfortunatly antlr requires it at runtime. The grammar syntax is almost the same, JavaCC just needs better docs.

There might be a way arround the runtime dependency but I didn't look any further into that, JavaCC is also more "java-like" if you ask me, and JJTree makes a nice extension too.

Posted by: Thomas Heller at June 28, 2004 06:02 AM

you might want to also consider SableCC.

Posted by: Jonathan Ellis at June 28, 2004 09:10 AM

+1 SableCC.

Posted by: Andreas Mueller at June 28, 2004 12:29 PM

I write all grammars that I need (which are quite a few) with ANTLR, and I'm quite satisfied with it. The grammar syntax is closer to EBNF than JavaCC, the mailing list is quite helpful, and I can write a single grammar for multiple target languages. It's also reasonably fast, and Ter is actively working on it - in fact Antlr 3 will probably become the best parser generator ever from what I know of the planned features. Also I don't mind the runtime dependency (I can include all necessary classes in my own project as Antlr is Public Domain).

Posted by: Thomas Dudziak at July 1, 2004 06:55 AM

i too like antlr, and dislike the runtime dependency.
how come they have no antlr-client.jar? this seems to be the obvious way to do it.

sincerely
morten wilken

Posted by: morten wilken at July 8, 2004 01:53 AM

Robert Watkins (scroll down to the very bottom of his website) :)

Posted by: Richard Thomas at July 9, 2004 01:45 AM

Cedric, you are right on the money. I've just gone through the same process you have.

JavaCC is a great tool with terrible docs. Sun ought to do better. I'm guessing they took over management of JavaCC as a "favor" to the community and have no one working on it hoping that somebody from outside the company will help out.

Posted by: Andy Streich at July 10, 2004 11:24 AM

You guys use antlr for your JMS selectors don't you?

Posted by: at July 10, 2004 07:54 PM

fdeitau yoowiwcara.

Posted by: Elizeus at July 27, 2004 12:15 PM

I agree with cedric' views in the top., whats ironic is inspite of using javacc for over a month now & I still struggle for docs & finding out simple tweaks in the Tool.

Posted by: priyatam at November 26, 2004 01:15 AM

I am doing my final year project on refactoring and I've looked at both JavaCC and ANTLR. I have no knowledge of programs like Lisp or Yacc (where most documentation assumes some knowledge of these), and I dont have the time to spend learning any program fully as well as writing a grammar. ANTLR is easy to pick up and has much better documentation than JavaCC, much better for us students

Posted by: Jonathan Nicholson at January 4, 2005 03:36 AM

btw, that post was going to be much more complete, but the system used to post here is ... well not perfect, it was telling me i had questionable content... and eventually figured out after removing most of my msg that it didnt like my uni email address

Posted by: Jonathan Nicholson at January 4, 2005 03:40 AM

I ever had used both javaCC and Antlr. I like javaCC, it is pure java style, and the lexer of antlr is not based on DFA but LL, so it is more easy to write lexer description in javaCC.

Posted by: Evans Zhagn at March 23, 2006 02:07 AM

I ever had used both javaCC and Antlr. I like javaCC, it is pure java style, and the lexer of antlr is not based on DFA but LL, so it is more easy to write lexer description in javaCC.

Posted by: Evans Zhang at March 23, 2006 02:07 AM

If you want an introduction for javaCC, you might want to have a look at:
http://www.javaworld.com/javaworld/jw-12-1996/jw-12-jack.html

It's about jack, the former name of javaCC. The Syntax has slightly changed so the examples won't compile in javaCC without minor adjustments, but nevertheless it helped me getting started with JavaCC.

Posted by: Immo at March 29, 2006 05:53 AM

I have been using javacc, and while the documentation needs significant improvement, I find that the jjtree extension makes walking the parse tree quite easy. Does antlr have a similar parse tree generator? Has anyone any thoughts on how tools like antlr and javacc stack up against JFlex and CUPs?


Posted by: justine at April 21, 2006 08:40 AM

2 Immo

I have had some good expirience with javaCC, and now I'm having quite bad expirience with antlr. And the problem is exactly in walking trees: antlr does not provide an inreface to the parent of the AST node, while javaCC does. And for my application this is a crucial point. The only reason why I turned to antlr is that it generetes C++ code. If javaCC could produce c++ code I would not have bouthored with antlr.

BTW, in my opinion, antlr docs are even less clear and understandable then javaCC docs.

Posted by: Dmitri at July 8, 2006 07:35 AM

2 Immo

I have had some good expirience with javaCC, and now I'm having quite bad expirience with antlr. And the problem is exactly in walking trees: antlr does not provide an inreface to the parent of the AST node, while javaCC does. And for my application this is a crucial point. The only reason why I turned to antlr is that it generetes C++ code. If javaCC could produce c++ code I would not have bouthored with antlr.

BTW, in my opinion, antlr docs are even less clear and understandable then javaCC docs.

Posted by: Dmitri at July 8, 2006 07:35 AM

ANTLR documentation is definitely more helpful than JavaCC, it is extremely easy to understand as a student with sufficient examples :)
cheers to Terr

Posted by: Swati Tiwari at July 2, 2007 04:38 AM

Same for me. Used Javacc for a while then needed antlr because it generates c# code.
I really prefer the JavaCC lexer.

Posted by: Kamel at April 17, 2008 08:22 AM

I have been using both JavaCC and ANTLR for some time now. ANTLR is much easier to pick up and supports many languages. Once you mastered JavaCC and you are only dealing with Java, JavaCC is much better choice than ANTLR. Recently, I needed to create a parser to support TSQL, PLSQL and ISQLPLUS scripts, I could not do it in ANTLR without messy twist. I turned to JavaCC in the end. JavaCC's Lexer is much more powerful than ANTLR's.

Posted by: SL at August 7, 2008 03:23 AM

I am just interested in ANTLR. I study about ANTLR in the homepage. My purpose is building one language translator. I hope you can help me.

Posted by: Missthom at December 11, 2008 12:01 AM

At my master thesis I was working on a task to create a new compiler for my tutor's new theoretic programing language. So, I am student, but I still managed to get started with JavaCC (so the statement, JavaCC is to hard for students is wrong). I had a look into ANTLR as well, documentation is awesome, but ANTLR didnt fit my needs.

JavaCC and especially JJTree were what I was looking for. After some research I was able to find some good documentation for JavaCC and JJTree. Of course, I had good experience due to my study, only the syntax of JavaCC grammars were different. The rules were kinda same then i learnt in CoCo-2. Also a good tip for getting started with JavaCC is the book from Tom Copeland. But with some experience the documentation is kinda enough.

Posted by: Tim at September 9, 2009 07:53 AM

@ Immo:

Thanks for the link.
Nice tutorial.
Before I have only known about the tutorial at
www.engr.mun.ca/~theo/JavaCC-Tutorial/javacc-tutorial.pdf

But the Jack-tutorial is nice, too.

Posted by: Ken at November 9, 2009 09:50 AM
Post a comment






Remember personal info?