Re: eliminating left-recursion

Russell Shaw <rjshaw@netspace.net.au>
8 Jan 2006 11:38:19 -0500

          From comp.compilers

Related articles
eliminating left-recursion aegis@mad.scientist.com (aegis) (2006-01-07)
Re: eliminating left-recursion rjshaw@netspace.net.au (Russell Shaw) (2006-01-08)
Re: eliminating left-recursion cdodd@acm.org (Chris Dodd) (2006-01-08)
Re: eliminating left-recursion DrDiettrich@compuserve.de (Hans-Peter Diettrich) (2006-01-09)
Re: eliminating left-recursion lojiancn@hotmail.com (jackycn) (2006-01-09)
| List of all articles for this month |
From: Russell Shaw <rjshaw@netspace.net.au>
Newsgroups: comp.compilers
Date: 8 Jan 2006 11:38:19 -0500
Organization: Compilers Central
References: 06-01-013
Keywords: parse, LL(1)
Posted-Date: 08 Jan 2006 11:38:19 EST

aegis wrote:
> Given the following production:
>
> d-declarator: ID | d-declarator '[' constant ']' | '(' d-declarator ')'
> ;
>
> How can I eliminate left-recursion here? The method sketched
> out in 'Compilers, Principles, Techniques and Tools' only
> presents a very simple case where the non-terminal
> that introduces left-recursion in the production, isn't restricted
> to being on the left-hand side of the rule. In the above production,
> the second rule allows me to construct an array of arrays ... ad
> infinitum. i.e., foo[10][10][10][10][10][10][10]; etc
>
> Is it even possible to express the second rule of the above production
> without relying on left-recursion?


d-declarator:
      d-declarator '[' constant ']' |
      '(' d-declarator ')' |
      ID




How about:


d-declarator:
      x '[' constant ']'


x:
      '(' d-declarator ')' x |
      ID x |
      e


(e is null)



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.