« Return to Thread: "Left recursion detected" when translating from BNF

Re: "Left recursion detected" when translating from BNF

by Artur Rataj :: Rate this Message:

Reply to Author | View in Thread

Decide on the associativity of the operator. If you want the operator to have a left associativity:

void searchExp():
{}
{
  
     relExp() ( logOp() relExp() )*
   | "(" searchExp() ")"

}

If you'd like to search more for this, the problem is generally called resolving left recursion.



On Tue, Mar 24, 2009 at 10:03 AM, Bertram <bertram@...> wrote:


Hello,

I am new to Javacc, so there might be a very obvious solution to this.
This is a left recursion problem (Left recursion detected:).

Here the 1:1 translation of the related BNF description:

void searchExp():
{}
{
   relExp()
   |  searchExp() logOp() searchExp()  // this line is the problem
   | "(" searchExp() ")"

}

void logOp():
{}
{
        <T_OR>
        | <T_AND>
}


 « Return to Thread: "Left recursion detected" when translating from BNF