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

Mark Volkmann r.mark.volkmann at gmail.com
Tue Feb 5 05:51:00 PST 2008


On Feb 5, 2008 6:58 AM, Johannes Luber <jaluber at gmx.de> wrote:
> Mark Volkmann schrieb:
> > Can someone describe a case where it's better to use syntactic
> > predicates on rule alternatives than just specifying backtrack=true as
> > a rule option? It certainly introduces less clutter in the grammar to
> > use backtrack and of course there is less to type and less opportunity
> > for error. Is it significantly more efficient to use syntactic
> > predicates?
> >
>
> Maybe
> <http://www.antlr.org/wiki/display/ANTLR3/How+to+remove+global+backtracking+from+your+grammar>
> includes the required information. It collects my (limited?) knowledge
> on this matter.

Thanks! I learned some new things by reading that. I'm still a little
confused though. In section 12.2 of the book (page 300 in my copy) it
says:

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

So it seems to me that these rules are equivalent in both behavior and
performance.

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

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

If this is true then I think I prefer using backtrack because it adds
less clutter to the rule.

-- 
R. Mark Volkmann
Object Computing, Inc.


More information about the antlr-interest mailing list