[antlr-interest] Ambiguity warning (ANTLR 2.7.5, 2.7.6)

Bryan Ewbank ewbank at gmail.com
Fri Feb 24 02:14:18 PST 2006


I finally figured out why I was getting an TreeGrammar ambiguity
warning in places where others were saying that I should not - it's
because I have an action.

If you have a rule of the form, no warning is issued.
    a:  ( #(B ...)
        | .
        );

If; however, you add an action to the "." alternative, am ambiguity
warning is issued:
    a:  ( #(B ...)
        | e:. { error(#e); }
        );

The warning again disappears if you make the last alternative a #(...) tree:
    a:  ( #(B ...)
        | #( e:. { error(#e); } )
        );

It looks like it is supposed to be suppressed in LLkAnalyzer.java, by
altUsesWildcardDefault(), but I don't know the data shapes well enough
to propose a solution.

At the very least, turns out I'll been able to remove quite a few
predicates by using the last form.

Hope this helps someone,
- Bryan Ewbank


More information about the antlr-interest mailing list