[antlr-interest] syntactic predicates vs. backtrack=true
Jim Idle
jimi at temporal-wave.com
Tue Feb 5 12:23:22 PST 2008
> -----Original Message-----
> From: Mark Volkmann [mailto:r.mark.volkmann at gmail.com]
> Sent: Tuesday, February 05, 2008 11:44 AM
> To: Jim Idle
> Cc: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] syntactic predicates vs. backtrack=true
>
> 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.
Backtrack on a rule can be good too. It is inserting automatic
predicates but if you use the memoizing option, then it will shortcut
predicates that it has tried before, so sometimes it is better than
syntactic predicates. Using it on a whole grammar is expensive of
course.
Jim
More information about the antlr-interest
mailing list