[antlr-interest] ANTLR version 2.X to ANTLR version 3.X (the horror, the horror)

Kay Röpke kroepke at classdump.org
Sat Aug 9 08:19:21 PDT 2008


Hi!

On Aug 9, 2008, at 1:07 PM, Raphael Reitzig wrote:

> I think the problem often lies with ANTLRs approachability. It is  
> very easy to write down a grammar in common EBNF, push some things  
> around ("Oww, if I write this rule name in capitals, it works!") and  
> get, for easy examples, what you want. Then, you think yourself a  
> rather experienced user and proceed to your real problem, that which  
> brought you to ANTLR. You fuck up. There is much to know about the  
> tool and about grammars in general (you have to know what ambiguity  
> _is_ before you can care about it) before you can be really  
> productive. But ANTLR itself, exspecially with great ANTLRWorks,  
> tends to suggest "Just do it!", what is not the case today.


I think the main problem is that when programmers realize they need to  
parse something, they often want to parse very ambiguous and ill- 
defined languages. Creating something that "just works" is hard for  
those types of languages, hence the fuck-up part.

However, if you turn on backtracking (and memoize) you generally will  
end up with a working solution, but the programmers (being  
professionals after all) don't like the incurred overhead. That's the  
point when people go "uhhh, what an ugly tool, it's so slow and hard  
to learn". Only that the tool is not that hard to learn (there are  
really only a couple of rules (no pun) you need to follow) but the  
problem domain can be a tough one. Throw in keywords-as-identifiers,  
case insensitivity (in many cases only partly case-insensitive), and  
bona fide ambiguous constructs it is a pain to write parsers.

Often I wonder if people new to ANTLR even bother to check out the  
"getting started" page on the wiki. It's quite disturbing to me to  
think they do not, because when I'm new to a tool I might start  
playing with it as well without reading anything about it, but once I  
don't understand something, I turn to articles or blogs. Looking at http://antlr.org/wiki/display/ANTLR3/FAQ+-+Getting+Started 
  and following one or two links to the excellent intro by Mark  
Volkmann (for example) you should be up and running within a day or  
two, provided you accept the fact that you have to learn new stuff.  
(The "you" is of course not meant to be "you", Raphael :))

Having said that, yeah sure there's room for improvement as with every  
tool out there.

I just realize that probably the biggest source of confusion are  
combined grammars. If a beginner does not grasp the important  
distinction between lexer and parser rules, it's probably best to  
start out with separate grammars for those. Then, all of a sudden,  
realization comes when you see that separation into two files. :)

cheers,
-k
-- 
Kay Röpke
http://classdump.org/








More information about the antlr-interest mailing list