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

Re: "Left recursion detected" when translating from BNF

by Bertram :: Rate this Message:

Reply to Author | View in Thread

left associativity is what I need.

But:
Lets say: relExp can just be one of "ABC"
with the original expression I'm able to recognize:

A OR (B AND C)

I don't see how this works with <relExp() ( logOp() relExp() )* | "(" searchExp() ")"> ?

So I tried:

<relExp() (logOp() searchExp())* | "(" searchExp() ")">

But here I get "Warning: Choice conflict in (...)*". With the suggested solution (LOOKAHEAD(some_number)) I can't solve this.

Is the warning in this case to be ignored, or is there a different way ?
thanx

Artur Rataj wrote:
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@grillitsch.at> 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