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>
> )
> }
>
> 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


.



Relevant Pages

  • Left recursion error even when tokens are consumed
    ... I have a production as follows: ... This causes a left recursion error: ... If I take out the conditionality, ...
    (comp.compilers.tools.javacc)
  • Re: CoBOL moved to OO
    ... that we shopuld be considering how to help COBOL people bridge the gap. ... > languages that descend from ALGOL is that COBOL resisted recursion until ... But it is notable that RECURSIVE program ID syntax enters COBOL ... Yet Class methods and data are part of object orientation. ...
    (comp.lang.cobol)
  • Re: Simple yet Profound Metatheorem
    ... > All you have to do is explain what your notation means. ... I'll have to break the bad news to Boolos, Kripke, Solovay et, al. ... There's nothing more trivial than a purported syntax error, ... I once surveyed about 20 proofs of the Recursion Theorem to determine ...
    (sci.logic)
  • Re: Recursive Call
    ... both direct and indirect recursion is prohibited. ... >> an extension and it does whatever the implementor says it does. ... > COBOL, but I did find it extremely useful in writing a parts explosion ... pitfalls were and what the appropriate syntax was. ...
    (comp.lang.cobol)