[antlr-interest] How to remove mutual left recursion from this grammar?

Seref Arikan serefarikan at kurumsalteknoloji.com
Wed Jan 4 14:25:33 PST 2012


Jim, thanks a lot. Learning Antlr is quite easy, but learning LL way of
thinking is proving to be real challenge!


On Wed, Jan 4, 2012 at 6:24 PM, Jim Idle <jimi at temporal-wave.com> wrote:

> rul    :  contains_expr    ;
>
> contains_expr: 'CONTAINS' contains_expression
>                  //'CONTAINS' contains_or
>        ;
>
> contains_expression : primary (('OR'|'AND'|'XOR') primary)*
>        ;
>
> primary
>  : '(' contains_expression ')'
>  | class_expression
>  ;
>
>
> Jim
>
> > -----Original Message-----
> > From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> > bounces at antlr.org] On Behalf Of Seref Arikan
> > Sent: Wednesday, January 04, 2012 9:35 AM
> > To: antlr-interest at antlr.org
> > Subject: [antlr-interest] How to remove mutual left recursion from this
> > grammar?
> >
> > Greetings,
> > This simple grammar represents a setup  I could not fix. Obviously the
> > target is to create nested boolean statements, but I could not fix the
> > recursion. This pattern repeats in a larger grammar, so solving this
> > will help me fix more problems. Any clues that you can think of?
> >
> > //---------------------------------------------------------------------
> > -----------
> > grammar testg;
> >
> > rul    :  contains_expr    ;
> >
> > contains_expr: 'CONTAINS' contains_expression
> >                   //'CONTAINS' contains_or
> >         ;
> >
> > contains_expression : class_expression
> >                         | contains_expression_boolean
> >                         |'(' contains_expression_boolean ')'
> >         ;
> >
> > contains_expression_boolean : contains_expression 'OR'
> > contains_expression
> >                               | contains_expression 'AND'
> > contains_expression
> >                               | contains_expression 'XOR'
> > contains_expression
> >         ;
> >
> >
> >
> >
> > class_expression
> >     : ID
> >     ;
> >
> >
> >
> > ID  :    ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
> >     ;
> >
> >
> >
> > Best regards
> > Seref
> >
> > List: http://www.antlr.org/mailman/listinfo/antlr-interest
> > Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> > email-address
>
> 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