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: | Pete Jinks <pjj@cs.man.ac.uk> |
Newsgroups: | comp.compilers |
Date: | 9 Sep 2003 23:05:53 -0400 |
Organization: | Computer Science Dept, University of Manchester |
References: | 03-09-027 |
Keywords: | parse |
Posted-Date: | 09 Sep 2003 23:05:53 EDT |
Alfonso Urdaneta wrote:
>
> Basically I need to parse a line that may look like this.
>
> '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.
Agreed. (Formally, your grammar is LR(2) rather than LR(1), which is
all that yacc can cope with.)
Here is an equivalent LR(1) grammar, which works ok with yacc:
fred : fredhead fredtail
;
fredhead:
| MONTY_STORE MONTY_FD
;
fredtail: label_identifier MONTY_FD declare_length
| label_identifier MONTY_FD fredtail
;
declare_length and label_identifier as before
You may find the following link useful:
http://www.cs.man.ac.uk/~pjj/complang/grammar.html
--
Peter J. Jinks, Room 2.99, Department of Computer Science,
University of Manchester, Oxford Road, Manchester, M13 9PL, U.K.
(+44/0)161-275 6186 http://www.cs.man.ac.uk/~pjj
Return to the
comp.compilers page.
Search the
comp.compilers archives again.