[antlr-interest] Mutual left recursive problem

Bart Kiers bkiers at gmail.com
Thu Mar 25 02:27:20 PDT 2010


On Thu, Mar 25, 2010 at 9:56 AM, foxterri foxterri <foxterri2 at hotmail.com>wrote:

>
> The complete grammer is attached, it is not completely done, but should
> give a good overview of it.
>
> debugging it in eclipse gives the following error:
>
> error(210): The following sets of rules are mutually left-recursive
> [primaryNoNewArray, arrayAccess, methodInvocation, primary, fieldAccess]
>

That grammar still contains errors, but after commenting them out, I can
spot the left recursive rules.
I presume you know what left recursive rules are? If not, here's one in your
grammar: an 'arrayAccess' first part can be a 'primaryNoNewArray' whose
first part can be a 'methodInvocation' whose first part can be a 'primary'
whose first part can be a 'primaryNoNewArray'. The 'primaryNoNewArray' makes
it left recursive. Note that by "first part", I mean the left-most part of a
rule.

arrayAccess
 primaryNoNewArray <-----------------------+
  methodInvocation                         |
   primary                                 | left recursive
    primaryNoNewArray <--------------------+

Checkout ANTLR's wiki about this in more detail and how to remove them:
http://www.antlr.org/wiki/display/ANTLR3/Left-Recursion+Removal

Regards,

Bart.


More information about the antlr-interest mailing list