[antlr-interest] The power of backtracking in ANTLR

Terence Parr parrt at cs.usfca.edu
Mon Feb 15 10:38:57 PST 2010


On Feb 14, 2010, at 11:52 PM, Gavin Lambert wrote:

> At 14:54 15/02/2010, Michael Bedward wrote:
>> So, in this example you can't refactor the grammar to LL(k) but
>> you can have a simple, readable grammar for this part of the
>> language if you work with a back-tracking parser.
> 
> Or you put in the appropriate look-ahead predicates yourself.
> 
> Basically all ANTLR's backtracking mode does is to insert 
> lookahead predicates in every path and switch off ambiguity 
> warnings.  Consequently, while it's often useful while 
> experimenting, or with ridiculously ambiguous languages, it's 
> usually better to keep backtracking off, refactor, and add 
> predicates as needed.

ANTLR puts them in, but only uses them when necessary :)

Ter


More information about the antlr-interest mailing list