[antlr-interest] guessing w/ predicates

Bryan Ewbank ewbank at gmail.com
Fri Jan 28 07:35:44 PST 2005

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