[antlr-interest] guessing w/ predicates

Bryan Ewbank ewbank at gmail.com
Thu Jan 27 08:31:24 PST 2005

Hi Folks,

I'm seeing something during the guessing phase of tree walkers that
has me puzzled.

If I write a rule that has syntactic predicates for *every*
alternative, it seems that guessing would pass if one of the
predicates matched - there's no need for further exploration.

For example:

  : (b) => b
  | c

  : (X) => #(X ( a )* )
  | (Y) => #(Y ( a )* )
  | (Z) => #(Z ( a )* )

  : bad:. { err << "illegal node: " << bad; }

I would expect that guessing from production "a", when drilling into "b", would
just check the syntactic predicates for "b" - that is, X|Y|Z, and then succeed.

What I'm seeing is that it checks X, then drills down into the
production to see if "a" matches recursively -- this seems
counterintuitive (to me, anyway) because "b" requires going into the
production when the predicate matches.  If guessing goes into the
production after the predicate, and the production fails, then
guessing will reject that path incorrectly.

I rewrote "a" to be what I expected to happen:

   : ( X | Y | Z ) => b
   | c

but this is a maintenance problem because now X, Y, and Z occur in two

Do I misunderstand the purpose of syntactic predicates?

More information about the antlr-interest mailing list