开发者

Antlr : mutually left-recursive rule

开发者 https://www.devze.com 2023-02-27 21:34 出处:网络
i have this rule in antlr : an开发者_如何转开发REs : anRE (\'(\' anREs \')\') =>\'(\' anREs \')\'

i have this rule in antlr :

an开发者_如何转开发REs : 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


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   ;
0

精彩评论

暂无评论...
验证码 换一张
取 消