[antlr-interest] for grammar tail recursion

femto gary femtowin at gmail.com
Thu Apr 5 03:44:08 PDT 2007


Hi John, yes I also tried adding a start rule,
start:slist; to the grammar file,
and it's ok now (both in antlrWorks and outside it).

but it's weird, shouldn't antlr3 just recognize the grammar slist?
why doesn't it need a seperate start rule (maybe it's a bug?).
because I'm reading the antlr beta book now and didn't find
that it says special handling must be treated for start rule. weird.

On 4/5/07, John B. Brodie <jbb at acm.org> wrote:
> >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
>


-- 
Best Regards
XRuby http://xruby.com
femto http://hi.baidu.com/femto


More information about the antlr-interest mailing list