[antlr-interest] Hoisting of a disambiguating semantic predicates
Paul Eames
peames at nexagent.com
Tue Oct 30 09:02:42 PDT 2007
Hi all,
I am using semantic predicates to disambiguate two syntactically
identical rules as follows:
foo :
(
{isFoo(input.LT(1))}?
x+=THING
)+ ;
bar :
(
{isBar(input.LT(1))}?
x+=THING
)+ ;
This is fine until I start using these rules in other rules like the
following:
a : foo bar | foo (bar foo)+;
The generated disabiguating check code in rule "a" hoists the semantic
predicate out of foo which is not sufficient to disambiguate and so this
rule will always take the first alternative.
Generated code snippet:
...
if ( (isFoo(input.LT(1)) ) {
alt5=1;
}
else if ( (isFoo(input.LT(1)) ) {
alt5=2;
}
else {
NoViableAltException nvae =
new NoViableAltException("203:1: a: ( ( foo bar ) | ( foo ( bar
foo ) )+ );", 5, 4, input);
throw nvae;
}
...
Is there a cunning grammar design decision that I can take to avoid this
problem?
Many thanks,
Paul.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20071030/3d95fe56/attachment.html
More information about the antlr-interest
mailing list