0

I'm trying to parse a language. The follow ANTLR4 parser rules are directly copied from the language specification :

physical_value 
 : raw_value DIV factor MUL factor PLUS offset 
 ;

raw_value
 : (physical_value MINUS offset) DIV factor  
 ;

but antlr reports an error:The following sets of rules are mutually left-recursive I don't know how to modify the grammar, Hope someone can help me. Thanks.

sara
  • 81
  • 1
  • 7

1 Answers1

1

You cannot eliminate the left recursion from the rules you posted, because the only string it matches is an infinite sequence.

  • physical_value always starts with a raw_value
  • raw_value always starts with a physical_value

...and repeat

Sam Harwell
  • 97,721
  • 20
  • 209
  • 280
  • Thanks for your answer, u mean there is no way to modify the rules? I cannot do anything? – sara Sep 10 '14 at 07:24
  • @sara: Could you post some sample input and what should be matched by the rules. Maybe there's a way to modify the rules. – Onur Sep 10 '14 at 16:03