[antlr-interest] How to remove mutual left recursion from this grammar?
Jim Idle
jimi at temporal-wave.com
Wed Jan 4 10:24:36 PST 2012
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
More information about the antlr-interest
mailing list