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) |
From: | blackmarlin@asean-mail.com (C) |
Newsgroups: | comp.compilers |
Date: | 9 Sep 2003 22:59:25 -0400 |
Organization: | http://groups.google.com/ |
References: | 03-09-027 |
Keywords: | parse, LALR |
Posted-Date: | 09 Sep 2003 22:59:25 EDT |
a7244270@yahoo.com (Alfonso Urdaneta) wrote
> I have trimmed my grammar down to as small as possible while still
> maintaining the error - I get shift/reduce conflicts that I can't get
> rid of no matter what I try. Basically I need to parse a line that
> may look like this. (a bunch of variable declarations).
>
> 'george', 'barney', 'wilma', 'pebbles', 25 CHAR
>
> what I _think_ is happening is that the last comma before the 25 is
> throwing it for a loop, as the parser doesn't know if another
> identifier is coming, or if the length is coming.
Quite correct. This is because the parser does not know if the comma
is the one in the label_identifier_seq or that in the declare_length
(as the parser cannot lookahead more than one token, an LALR(2) parser
would be happy with this), the simplist solution is to eliminate one
of these commas by merging the rules. Try this...
lines
: fred
{}
;
fred
: declaration
{}
;
declaration
: STORE FD label_identifier_seq
{}
| label_identifier_seq
{}
;
label_identifier_seq
: SINGLE_QUOTE IDENTIFIER SINGLE_QUOTE FD label_identifier_seq
{ printf( "\tidentifier %s\n", $<text>2 ); }
| UNSIGNED_INTEGER_NUMBER CHAR
{ printf("\tlength is %d\n", $<ival>1 ); }
;
MONTY_ removed to due to a typing aversion (lazyius fingerious).
I guess this is your language's name :-)
C
2003/9/5
Return to the
comp.compilers page.
Search the
comp.compilers archives again.