[antlr-interest] syntactic predicates vs. backtrack=true

Mark Volkmann r.mark.volkmann at gmail.com
Tue Feb 5 11:43:50 PST 2008


On Feb 5, 2008 10:53 AM, Jim Idle <jimi at temporal-wave.com> wrote:
> In my opinion you should never use backtracking unless performance is
> not a big deal for you. It is good for prototyping and as you say it can
> make the specification of your grammar easier/neater.

I snipped out a lot of your post which was excellent. However, I'm
still confused by this statement in the book.

"ANTLR also supports an auto-backtracking feature whereby ANTLR
inserts syntactic predicates on the left edge of every alternative."

To me this statement implies that the backtrack option is just a
shortcut for inserting syntactic predicates. Doesn't that mean that
these rules are equivalent in both behavior and
performance? If not, can someone explain how they differ at runtime?
Note that I'm specifying the backtrack option on a specific rule, not
on the entire grammar.

foo
options { backtrack = true; }
 : option1
 | option2
 | option3
 ;

foo
 : (option1)=> option1
 | (option2)=> option2
 | option3
 ;

-- 
R. Mark Volkmann
Object Computing, Inc.


More information about the antlr-interest mailing list