1
votes

i have this rule in antlr :

anREs : anRE 
      | ('(' anREs ')') =>  '(' anREs ')'
      | (anREs '|' anREs) =>  anREs '|' anREs   ;

where the anRE is a regular expression , when i want to compile the rules file i have this error message due to 3rd alternative in last rule :

error(210): The following sets of rules are mutually left-recursive [anREs]

how i can re write this rule ?

thanks

1
@ Bart Kiers thanks for your help , you are right i can solve this problem by delete this alternative but i need it , and i cant use PCRE because i need to implement special features in my rules . - Radi

1 Answers

2
votes

Here is your left recursion:

  ... | (anREs '|' anREs) =>  anREs '|' anREs   ;

Worse, its ambiguous. If you have anREs_1 | anREs_2 | anREs3 as input, it isn't clear what the subterms of the | operator are.

I'd expect this to solve the problem, and resolve the ambiguity, too:

  ... | (anRE '|' anREs) =>  anRE '|' anREs   ;