[antlr-interest] Semantical disambiguation of rule conflicts
Rene Vestergaard
vester at jaist.ac.jp
Wed Aug 10 00:08:22 PDT 2011
I have a couple of rewrite rules on ASTs of the following kind, for use
as part of bottomup:
flattenOuter @init{boolean nestd=false;}
: ^(c=OUTER ( ^(OUTER ds+=.*) {nestd=true;}
| ds+=.
)+)
{nestd}?
-> ^(OUTER $ds+)
;
The effect is to flatten nested occurrences of the OUTER constructor.
The inner two rules are obviously conflicting but, as the top rule is
given preference, all is well. To suppress the resulting conflict
warnings, I used to write these type of rules with a gated semantic
predicate:
flattenOuter @init{boolean nestd=false;}
: ^(c=OUTER ( {true}?=> ^(OUTER ds+=.*) {nestd=true;}
| ds+=.
)+)
{nestd}?
-> ^(OUTER $ds+)
;
ANTLR 3.2 is happy with this. ANTLR 3.4 is not: the gated rules are
seemingly not invoked.
This doesn't quite make sense. Might this be a bug, or could someone
enlighten me about the rationale for the seemingly changed behaviour of
ANTLR 3.4?
More information about the antlr-interest
mailing list