Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!lll-winken!sol.ctr.columbia.edu!emory!att!att!ima!iecc!compilers-sender From: mareb@lux.sait.edu.au (Buckley) Newsgroups: comp.compilers Subject: Re: Avoiding right-recursion Keywords: yacc, parse Message-ID: <9101290649.AA11150@lux.sait.edu.au> Date: 29 Jan 91 16:19:41 GMT References: Sender: compilers-sender@iecc.cambridge.ma.us Reply-To: mareb@lux.sait.edu.au (Buckley) Organization: Compilers Central Lines: 28 Approved: compilers@iecc.cambridge.ma.us >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 -- Send compilers articles to compilers@iecc.cambridge.ma.us or {ima | spdcc | world}!iecc!compilers. Meta-mail to compilers-request.