[antlr-interest] for grammar tail recursion

John B. Brodie jbb at acm.org
Wed Apr 4 13:01:35 PDT 2007


>Hi all, I'm trying to migrate from antlr 2.7.6 to antlr 3 for XRuby project,
>I'm reading the antlr beta book and trying something from book
>'compiler construction principles and practice', that's  example 3.7:
>(rewritten using antlr's
>grammar and make it compact).
>slist:s';'slist | ;
>s:'s';
>//ignore WS rule
>but when I try it in antlrWorks, it would tell me the second
>alternative is unreachable, and it will misintepret 's;' to
>NoViableAltException, (which
>should be correct). generating the Lexer/Parser to test is also
>not correct. anyone has any ideas about this? Thanks.

Hello!

I tried your grammar under an old v3 - 3.b05 from November 2006 from
the command line, not from antlrWorks.

After adding a viable Start Rule - to satisfy Antlr's complaint, I got
no errors or warnings from the antlr.org.Tool

And the generated parser/lexer accepted 's;' and rejected 's;s' as
expected.

Hope this helps...
   -jbb


More information about the antlr-interest mailing list