Take the 2-minute tour ×

I'm trying to parse a language in ANTLRWorks2:

grammar testLR;
pb: 'kind' '=' ID ';' pb
  | fd pb
fd: ( 'instance' '=' ID ';' )*   
ID: ('a'..'z'|'A'..'Z'|'_'|'$') ('a'..'z'|'A'..'Z'|'0'..'9'|'_'|'$')*

Then ANTLRWork tells me: "The following sets of rules are mutually left-recursive [pb]". I just can not figure out how to fix the problem. Any suggestions are welcome. Thanks!

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Since your fd rule has a * that means it can be empty (* = 0 or more times) - having an empty fd would mean your pb rule (second line) would be a pb : pb, which is not allowed since the parser would keep looping forever. You can fix this by not allowing the fd rule to be empty (change * to +), but I have no idea if that is desired in your grammar.

share|improve this answer
Thanks a lot! Now I know the reason! –  Lisa Aug 28 '13 at 22:10
If this answers your question please mark the answer as 'correct' - that way others will know your question does not need further attention. (and I do get some points ;-) –  Simon Groenewolt Aug 29 '13 at 9:15

Your Answer


