Left Recursion in Yacc

Mike <student1330@my-deja.com>
24 Dec 2000 16:02:47 -0500

          From comp.compilers

Related articles
Left Recursion in Yacc student1330@my-deja.com (Mike) (2000-12-24)
Re: Left Recursion in Yacc chenxq@my-deja.com (2000-12-31)
Re: Left Recursion in Yacc loewis@informatik.hu-berlin.de (Martin von Loewis) (2000-12-31)
Re: Left Recursion in Yacc ralph@inputplus.demon.co.uk (2001-01-09)
| List of all articles for this month |

From: Mike <student1330@my-deja.com>
Newsgroups: comp.compilers
Date: 24 Dec 2000 16:02:47 -0500
Organization: Deja.com
Keywords: yacc, question, comment
Posted-Date: 24 Dec 2000 16:02:47 EST

Hi,
I have a question about left recursive rules in Yacc/Bison. Suppose I
have a left recursive rule


expression:expression ',' ITEM
:ITEM


Now I want to create a list of items separated by a ',' from my input.
Although it is clear that the grammar would allow me to have a list of
one or more items. What is confusing for me is the actions that would
be taken. More specifically, how exactly would the recursion be
handled. Would I get the list in reverse order? If yes, why is that.
Let's say that the input is:


one,two,three,four,five


How exactly would Yacc/Bison handle this list?


Thanks a lot in advance!
[You can make the list any way you want, although if you do the simplest
think and link $1 to $3 in your first rule, you'll end up with a backwards
list. It's easy enough to make one pass at the end and reverse the links.
-John]


Post a followup to this message

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