Re: Left recursion error even when tokens are consumed
- From: "Oliver Wong" <owong@xxxxxxxxxxxxxx>
- Date: Fri, 23 Dec 2005 16:57:03 GMT
"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>
> )
> }
>
> This causes a left recursion error:
>
>> Left recursion detected: "Section... --> Section..."
My JavaCC is a bit rusty, but why is the first occurence of <CLOSE>
enclosed in parenthesis?
>
> If I take out the conditionality, it has no problem:
> Section Section() : {}
> {
> <SECTION_OPEN> <NAME>
> (
> ( Section() )+
> <CLOSE>
> )
> }
Yes, that is because there is no longer any left recursion. That is, the
first thin Section() matches is no longer another instance of Section(); now
it's <SECTION_OPEN>.
>
> Also, if I reorder the condition there is no error
>
> Section Section() : {}
> {
> <SECTION_OPEN> <NAME>
> (
> ( Section() )+
> <CLOSE>
> )
> |
> ( <CLOSE> )
>
> }
Again, there is no left recursion. The first thing Section() matches is
either <SECTION_OPEN> or <CLOSE>, as opposed to another instance of
Section().
>
> So I am confused, on two counts:
>
> - how is it possibly left recursive if it *definitely* consumes tokens
> before recursing?
> - how does adding the conditional section affect this?
Sounds like you are misunderstanding the syntax. I'm not sure what you
are trying to match though, so I can't give you hints towards the "correct"
syntax.
- Oliver
.
- Follow-Ups:
- Re: Left recursion error even when tokens are consumed
- From: Chris F Clark
- Re: Left recursion error even when tokens are consumed
- References:
- Prev by Date: Left recursion error even when tokens are consumed
- Next by Date: Re: Left recursion error even when tokens are consumed
- Previous by thread: Left recursion error even when tokens are consumed
- Next by thread: Re: Left recursion error even when tokens are consumed
- Index(es):
Relevant Pages
|
|