Become a fan of Slashdot on Facebook

 



Forgot your password?
typodupeerror
×
Book Reviews Books Media

The Definitive ANTLR Reference 95

Joe Kauzlarich writes "Finally, someone has done us all the great service of publishing a book about the second most well-known compiler compiler, Terence Parr's Antlr, and it was written, moreover, by Parr himself and published as part of the somewhat-usually-reliable Pragmatic Bookshelf series. Take note, while it requires a JVM to run, Antlr is not just for Java developers; it generates compilers in Python, Ruby, C, C++, C# and Objective-C. Also note that this book is more than just an elaborated man-page; it is also an excellent introduction to the concepts of compiler and parser design." Keep reading for the rest of Joe's review.
The Definitive ANTLR Reference
author Terrance Parr
pages 361
publisher Pragmatic Bookshelf
rating 9
reviewer Joe Kauzlarich
ISBN 978-0-9787392-5-6
summary introduction to parser/compiler design using ANTLR
First off, I have no preference between Yacc-style parsers, JavaCC and Antlr; I've never used Yacc, have used JavaCC in college and have since played with Antlr and am just as ignorant in the use of them all. The fundamental difference is that Antlr is a top-down LL(*) (simply-put, variable-lookahead) parser generator while Yacc is a bottom-up LR parser generator. JavaCC is also top-down, but employs a different parsing strategy. The book describes the meanings of these terms in simple detail.

I happen to have learned in my experience that good documentation for any of these products is hard to come by and difficult to follow, simply because the subject matter is obtuse and few, until now, have ventured to write expository literature to explain the myriad concepts to the non-academician. Of the three mentioned above, Antlr appears to be the more 'modern' and can also generate lexers from within the same grammar definition file, so the notions are integrated. Antlr also has a useful IDE called AntlrWorks with visualization features, causing grammar construction to be far simpler for a beginner.

That said, I don't wish to use this review to push Antlr over its alternatives, but only to press the point that this book serves not only to introduce Antlr to the average programmer, but the concepts of parser design as well. The concepts become necessary to understand while writing and debugging grammars, as not everything written in Backus-Naur Form will produce a working parser, and this holds true for any parser generator. Learning what works and what doesn't, as well as what workarounds are available, is key to becoming proficient in Antlr, Yacc or JavaCC. Once proficiency is acheived, you'll have the valuable skill of producing domain-specific languages on demand.

Terence Parr, as mentioned before, is not only the author and maintainer of Antlr, but he wrote the book as well. Antlr is on its long-awaited third version and has been maintained by Parr throughout the project's lifetime. He is a university professor and himself developed the path-breaking LL(*) parsing strategy employed by Antlr.

Parr begins with a one chapter background in computer language design before diving into a simple example of a parser for basic integer expressions. Part II is the meat of the book, describing various aspects of writing grammars for Antlr. Generally speaking, he covers the basic semantics of grammar writing, the many optimization, supplementary and 'workaround' options provided by Antlr, grammar actions and attributes, syntax trees, error reporting and related practical topics.

The third part, Understanding Predicated LL(*) Grammars, is the valuable 'textbook' portion of the book. It gives readers a short and comprehensible introduction to exactly what predicated-LL(*) means as well as a look at how competing parser generators work in contrast.

Both of the second and third parts are scattered with theoretical tidbits to help language designers better understand why grammars must work as they do. Those who can't pick their nose without a rudimentary theoretical overview of the subject can enjoy a few casual browsings through the book before even sitting in front of a computer. It works *almost* that well as a textbook, though it still doesn't approach such classics as Aho, et al's, Compilers: Principles, Techniques, and Tools (if you want to get seriously involved in compiler design). Take it for what it is though, as a chance to learn a tool of possible value without having to dig through old mailing lists and last-minute README's on the one hand, as was much the case a year ago, and on the other hand, devoting pain-staking class and study time to a lot of theory you won't find of practical value.

So I'll recommend this book on the basis that there's nothing else like it available; and don't wait until a project comes along that requires knowledge of compiler design, because there's a heck of a learning curve (I'm still on the very low end and I wrote a compiler in college). If you think compiler or parser design is interesting or may conceivably write a domain-specific language for your workplace, the Definitive Antlr Reference is not only a good place to start, but one of the only places to start short of signing up for a university course.

You can purchase The Definitive ANTLR Reference from amazon.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
This discussion has been archived. No new comments can be posted.

The Definitive ANTLR Reference

Comments Filter:
  • Re:LR versus LL (Score:3, Informative)

    by compro01 ( 777531 ) on Wednesday May 28, 2008 @02:53PM (#23574387)
    I believe the name means ANother Tool for Language Recognition. Nothing to do with LL vs. LR.
  • Re:Good stuff... (Score:2, Informative)

    by JeroenFM ( 1259708 ) on Wednesday May 28, 2008 @05:21PM (#23576711) Homepage
    As a person who owns the book and has tried working without it, I have to agree with grandparent here. The book is a must-have if you want to do serious work with version 3 of ANTLR - the v3 documentation or Wiki might contain some of the information you need for a serious grammar, but it's not presented in a consistent or useful manner. Sure, you can write a grammar without the book but unless you're intimately familiar with ANTLR, much of the online documentation just isn't all that helpful. The book on the other hand does a perfect job of explaining things.
  • Re:Good stuff... (Score:5, Informative)

    by parrt ( 157907 ) on Wednesday May 28, 2008 @06:08PM (#23577513) Homepage
    howdy. I never deleted anything from the documentation. v3 was completely new, I simply didn't provide as much documentation as some would like. I had a simple choice to make: (1) write some free documentation for which I would not be very motivated (after doing the 5 years of 7 day/week coding effort for v3) or (2) use cash to motivate myself to write decent documentation (side benefit is that I could use the book towards getting tenure at the University of San Francisco whereas documentation does not count as a publication). Obviously I chose (2), but I understand your frustration completely. It is only like 20 bucks at Amazon though ;)
  • Re:Good stuff... (Score:2, Informative)

    by ghettoimp ( 876408 ) on Wednesday May 28, 2008 @07:58PM (#23578983)
    After using ANTLR for a class long ago and being so impressed with it, I just returned to ANTLR today. I was shocked at the lack of documentation on the web site. I eventually typed "antlr reference" into google and found the following PDF: http://www.antlr.org/share/1084743321127/ANTLR_Reference_Manual.pdf [antlr.org] It's outdated and had many no-longer-supported constructs, but paired with the changes from 2.x to 3.0 it was adequate for what I needed to do. I can see nothing comparable linked from the ANTLR homepage. It seems like an obvious attempt to get you to buy the book. Oh well.

Solutions are obvious if one only has the optical power to observe them over the horizon. -- K.A. Arsdall

Working...