June 27, 2004ANTLR vs. JavaCCI 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 AMComments
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 AMyou 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 PMI 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 AMi too like antlr, and dislike the runtime dependency. sincerely Robert Watkins (scroll down to the very bottom of his website) :) Posted by: Richard Thomas at July 9, 2004 01:45 AMCedric, 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 AMYou guys use antlr for your JMS selectors don't you? Posted by: at July 10, 2004 07:54 PMfdeitau yoowiwcara. Posted by: Elizeus at July 27, 2004 12:15 PMI 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 AMI 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 AMbtw, 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 AMI 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. 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. If you want an introduction for javaCC, you might want to have a look at: 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 AMI 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?
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 AM2 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 AMANTLR documentation is definitely more helpful than JavaCC, it is extremely easy to understand as a student with sufficient examples :) Same for me. Used Javacc for a while then needed antlr because it generates c# code. 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 AMPost a comment
|