Re: shift/reduce conflict issues

rkrayhawk@aol.com (RKRayhawk)
9 Sep 2003 23:05:12 -0400

          From comp.compilers

Related articles
shift/reduce conflict issues a7244270@yahoo.com (2003-09-04)
Re: shift/reduce conflict issues chief@ockhamstyle.com (Mykola Rabchevskiy) (2003-09-09)
Re: shift/reduce conflict issues blackmarlin@asean-mail.com (2003-09-09)
Re: shift/reduce conflict issues rkrayhawk@aol.com (2003-09-09)
Re: shift/reduce conflict issues pjj@cs.man.ac.uk (Pete Jinks) (2003-09-09)
| List of all articles for this month |
From: rkrayhawk@aol.com (RKRayhawk)
Newsgroups: comp.compilers
Date: 9 Sep 2003 23:05:12 -0400
Organization: AOL http://www.aol.com
References: 03-09-027
Keywords: parse, yacc
Posted-Date: 09 Sep 2003 23:05:12 EDT

a7244270@yahoo.com (Alfonso Urdaneta)
Date: 9/4/03 9:48 PM EST


posted a bison grammar and commented in part ...


<snips>


<<
I followed the manuals suggestion and made the variable sequence left
recursive, but I have also been thinking that making it right
recursive (and making the fd right associative as well) might be the
answer.
>>


Perhaps you will wish to consider the advice to avoid right recursion
with a tool like bison.


Also, you may be allowing your notion of recursion to blur with
associativity (a bit hard to tell from your post)


Let me suggest a certain approach to one of the rules that is
problematic (this posted material here has not been tested, it is the
idea that counts not the exact code).




declaration: label_identifier_seq_top
| MONTY_STORE MONTY_FD label_identifier_seq_top
;


label_identifier_seq_top: label_identifier label_identifier_seq_deeper
;




label_identifier_seq_deeper: /* epsilon */
| MONTY_FD label_identifier
| label_identifier_seq_deeper MONTY_FD label_identifier
;






label_identifier: MONTY_SINGLE_QUOTE MONTY_IDENTIFIER
MONTY_SINGLE_QUOTE
        { printf("\tidentifier %s\n", $<text>2 ); }
;




So, the notion is that the original rule that you posted,
label_identifier_seq, is not really recursive. So do not make it left
recursive or right recursive. The possibilty of making it an extended,
comma delimitted, list is a recursive rule (which is optional all
together so you also need the epsilon in there, which is mildly
distracting). So make the extending of the list recursive (and with
bison do left recursion, lest you bust up your stack in a nasty way).


Hope that is useful,
Bob Rayhawk
RKRayhawk@aol.com



Post a followup to this message

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