Re: Avoiding right-recursion

mareb@lux.sait.edu.au (Buckley)
Tue, 29 Jan 91 17:19:41 BST

          From comp.compilers

Related articles
Avoiding right-recursion Mike.Spivey@prg.oxford.ac.uk (Mike Spivey) (1991-01-23)
Re: Avoiding right-recursion mareb@lux.sait.edu.au (1991-01-29)
| List of all articles for this month |

Newsgroups: comp.compilers
From: mareb@lux.sait.edu.au (Buckley)
Keywords: yacc, parse
Organization: Compilers Central
References: <MIKE.91Jan23103603@client25.prg.ox.ac.uk>
Date: Tue, 29 Jan 91 17:19:41 BST

>From: Mike.Spivey@prg.oxford.ac.uk (Mike Spivey)
>A better approach in some ways is to use left recursion but do extra
>work to build the list:


I like to use a cyclically linked list - the tail of the list points
back to the head. The list pointer points to the tail (or nil for
an empty list). It is very easy to append to this list and when you are
done it is very easy to convert it to a conventional list. And you still
only need one pointer.


I guess this would look something like this:


list : CLlist { $$ = tail($1); tail($1) = nil; } ;
CLlist : item { $$ = tail($1) = $1; }
| CLlist ',' item { tail($3) = tail($1); $$ = tail($1) = $3; }
;




b++
__
Bob Buckley Phone: (08) 343 3465
School of Mathematics & Computer Studies Fax: (08) 349 4367
University of South Australia
The Levels SA 5095 email: mareb@lux.sait.edu.au
Australia
--


Post a followup to this message

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