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.
#1 by Thomas Heller on June 28, 2004 - 6:02 am
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.
#2 by Jonathan Ellis on June 28, 2004 - 9:10 am
you might want to also consider SableCC.
#3 by Andreas Mueller on June 28, 2004 - 12:29 pm
+1 SableCC.
#4 by Thomas Dudziak on July 1, 2004 - 6:55 am
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).
#5 by morten wilken on July 8, 2004 - 1:53 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
#6 by Richard Thomas on July 9, 2004 - 1:45 am
Robert Watkins (scroll down to the very bottom of his website) 🙂
#7 by Andy Streich on July 10, 2004 - 11:24 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.
#8 by Anonymous on July 10, 2004 - 7:54 pm
You guys use antlr for your JMS selectors don’t you?
#9 by Elizeus on July 27, 2004 - 12:15 pm
fdeitau yoowiwcara.
#10 by priyatam on November 26, 2004 - 1:15 am
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.
#11 by Jonathan Nicholson on January 4, 2005 - 3:36 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
#12 by Jonathan Nicholson on January 4, 2005 - 3:40 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
#13 by Evans Zhagn on March 23, 2006 - 2: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.
#14 by Evans Zhang on March 23, 2006 - 2: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.
#15 by Immo on March 29, 2006 - 5:53 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.
#16 by justine on April 21, 2006 - 8:40 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?
#17 by Dmitri on July 8, 2006 - 7: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.
#18 by Dmitri on July 8, 2006 - 7: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.
#19 by Swati Tiwari on July 2, 2007 - 4:38 am
ANTLR documentation is definitely more helpful than JavaCC, it is extremely easy to understand as a student with sufficient examples 🙂
cheers to Terr
#20 by Kamel on April 17, 2008 - 8:22 am
Same for me. Used Javacc for a while then needed antlr because it generates c# code.
I really prefer the JavaCC lexer.
#21 by SL on August 7, 2008 - 3:23 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.
#22 by Missthom on December 11, 2008 - 12:01 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.
#23 by Tim on September 9, 2009 - 7:53 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.
#24 by Ken on November 9, 2009 - 9:50 am
@ Immo:
Thanks for the link.
Nice tutorial.
Before I have only known about the tutorial at
http://www.engr.mun.ca/~theo/JavaCC-Tutorial/javacc-tutorial.pdf
But the Jack-tutorial is nice, too.