[antlr-interest] Left recursive grammar

Bart Kiers bkiers at gmail.com
Thu Jul 21 06:30:29 PDT 2011


Hi Luigi,

I'm not sure if this is possible with ANTLR, or any other LL parser
generator.

See this for a work-around:
http://stackoverflow.com/questions/3799890/antlr-ast-generating-possible-madness

If it _is_ possible using some sort of fancy AST rewrite magic, I'm sure
someone will correct me.

Regards,

Bart.


On Thu, Jul 21, 2011 at 3:00 PM, Luigi Iannone
<iannone at cs.manchester.ac.uk>wrote:

> Hi all,
>
> I have this simple grammar
>
>
> grammar test;
> options {
>  language = Java;
>  output = AST;
> }
>
> a
>        :
>                a*B  ->^(B a*)
>                | A
>        ;
>
> B       :
>                '.B'
>        ;
>
> A       :
>                'A'
>        ;
>
>
>
>
> and I get the following output when I try to generate the parser in
> ANTRLWorks
>
> [13:48:53] error(210):  The following sets of rules are mutually
> left-recursive [a]
>
> I read on the Web that there are solutions to solve this, however they will
> mess up the associativity, which I need to keep instead.
> So, for instance, for the input
>
> A.B.B
>
> the AST tree should be
>
> ^(B ^(B A))
>
> Is there any way to change the grammar in order to eliminate the left
> recursion and obtain the above tree. I am afraid I do not get how to do it
> by just looking at what is there online about left recursive grammars.
>
> Thanks a lot for your help,
>
> Luigi
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>


More information about the antlr-interest mailing list