ANTLR is Ter-rific
June 6th, 2007Mark Proctor has posted an interview he did with Terence Parr of ANTLR fame. Ter is one of the nicest and smartest guys I know.
Back in the day, teaching myself how to program in C++, I decided to write my own scripting language. I’d tried (f)lex/yacc/bison, and they were either not friendly to C++, or not friendly to the way my brain works. Then I stumbled across PCCTS and recursive-descent LL(k) parsers. For once, the grammar productions seemed to make sense. The generated code seemed to be readable and make sense.
Praise be unto Terence Parr, creator of PCCTS.
Then he abandoned C++ for Java, and created ANTLR. Now it’s up to version 3.0. And has a book.
ANTLR is one of those libraries that you either love or have never heard about. You’ve probably enjoyed the benefits of ANTLR none-the-less.
Being able to create a parser for a new little language (or “DSL” to be hip and trendy) opens up a whole world when implementing new software. It makes it easy to think of formats beyond XML or CSV. Users get tired of being stabbed in the eye with XML’s pointy brackets.
June 6th, 2007 at 10:13 am
Antlr is a LL(k) parser generator and with these types of generators you always need to deal with syntactical ambiguity. LR parser generators have less trouble with syntactical ambiguity.
I have done a lot with ANTLR a few years ago, but I prefer using SableCC as parser generator. SableCC is a LALR parser generator and generates very useful structures (AST, Visitors etc). So if I have the chance I would certainly go for SableCC.
June 6th, 2007 at 10:26 am
With the semantic and syntactic predicates, along with the new predicate hoisting, I’ve yet to come across an insolvable ambiguity.
ANTLR also supports ASTs and allows writing of tree parsers in the same general language as you write character-based parsers. It’s quite nice.
June 6th, 2007 at 10:33 am
Hi Peter, Actually ANTLR v3 is LL(*) which handles many more grammars than LL(k). It uses a DFA to scan arbitrarily far ahead lookahead for a sequence to disambiguate decisions. Note that there are grammars that are LL(*) but NOT LR(k) for any k>1. SableCC is indeed a nice tool though. ANTLR v3 has plenty of advantages; check out the interview Bob points to above.
June 6th, 2007 at 11:13 am
There is a third way besides CSV and XML without getting into ANTLR’s territory - Lisp as data. Those parentheses are an illusion, just wait and see.
June 6th, 2007 at 3:35 pm
hi there,
“You’ve probably enjoyed the benefits of ANTLR none-the-less”
I first came to ANTLR while looking at a Weblogic(4.51 or 5.1) JSP stacktrace (not sure if weblogic still employs ANTLR).
I hope that the book can help non-CS Engg people who don’t have the benefit of some the courses CS guys take.
BR,
~A
June 12th, 2007 at 5:12 am
hello, is it possible to convert an expression(c=a+b) into xml document.
if so…can u give a brief example of the grammer file