Re: Left recursion error even when tokens are consumed



"dave" <groups@xxxxxxxxxxx> wrote in message
news:1135348347.197505.9520@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Hi All,
>
> I have a production as follows:
>
> Section Section() : {}
> {
> <SECTION_OPEN> <NAME>
> ( <CLOSE> )
> |
> (
> ( Section() )+
> <CLOSE>
> )
> }

I think you meant to have, something like:

Section Section() : {}
{
<SECTION_OPEN> <NAME>
( <CLOSE>
|
( Section() )+
<CLOSE>
)
}

Note, the different parenthesization. I'm not a JavaCC expert, but I
believe that | applies the the whole rule unless enclosed in
parenthesis--that's the way other tools work. I believe your way of
writing is was equivalent to:

Section Section() : {}
{
( <SECTION_OPEN> <NAME> <CLOSE> )
|
( Section() )+
<CLOSE>
)
}

which is the same as:

Section Section() : {}
{
( Section() )+
<CLOSE>
)
|
( <SECTION_OPEN> <NAME> <CLOSE> }
}

Does this make why JavaCC found a left-recursion problem....

Hope this helps,
-Chris

*****************************************************************************
Chris Clark Internet : compres@xxxxxxxxxxxxx
Compiler Resources, Inc. Web Site : http://world.std.com/~compres
23 Bailey Rd voice : (508) 435-5016
Berlin, MA 01503 USA fax : (978) 838-0263 (24 hours)
------------------------------------------------------------------------------
.