[antlr-interest] guessing w/ predicates

Loring Craymer Loring.G.Craymer at jpl.nasa.gov
Fri Jan 28 12:21:40 PST 2005


Unless I am misreading what you wrote, this sounds like expected 
behavior.  The only difference between processing in guessing mode (within 
the scope of a synpred) and non-guessing mode is that exceptions cause 
failure of a synpred and back off a level of guessing when caught.


At 07:35 AM 1/28/2005, Bryan Ewbank wrote:
>This is exactly what I expected, but not what I'm seeing.  What I see
>is that during evalutation of once syntactic predicate (guessing==1)
>any syntactic predicate encountered is processed (with guessing==2),
>and if it is accepted then the guarded alternative is traversed (with
>guessing==1) to determine if it matches.
>Only if the alternative itself passes will guessing finally be exited
>and the input rewound.
>I think this is incorrect because the syntactic predicate should force
>evalaution into that branch (and throw an exception later w/
>I'm working on getting a testcase that demonstrates the problem I'm seeing.
>Nigel said:
> > When you add a syntactic predicate, the alternatives are still tested 
> in the
> > same order (so it only really makes sense to put the syntactic predicate on
> > the first one or two alternatives). However, the predicate simply tests
> > whether this alternative is suitable before continuing. The lexer/parser is
> > switched into "guessing" mode and the syntactic predicate tested. If the
> > predicate is found to be true, then "guessing" mode is turned off, the 
> input
> > stream is rewound to the beginning again, and the alternative with the
> > tested syntactic predicate is then followed to consume the input.

More information about the antlr-interest mailing list