Related articles |
---|
HELP needed with this s/r error chseet@iti.gov.sg (Seet Chern Hway) (1997-02-16) |
Re: HELP needed with this s/r error clark@quarry.zk3.dec.com (1997-02-27) |
From: | Seet Chern Hway <chseet@iti.gov.sg> |
Newsgroups: | comp.compilers |
Date: | 16 Feb 1997 23:15:57 -0500 |
Organization: | Information Technology Institute |
Keywords: | yacc, parse, question, comment |
I hope somebody can help me overcome an s/r error in the grammar I have
constructed to parse a language. The language has the following
fragment:
INDEX name [segment]
[ , INDEX name [segment] ]...
where segment refers to the fragment
SEGMENT item [ , item ]...
The s/r error can be reproduced by the simplified YACC productions shown
below. The problem is caused by the occurrence of the ',' separator
used in both the list_index and list_item productions.
Could somebody help me rewrite the grammar to avoid the s/r error
please?
Seet Chern Hway
Information Technology Institute
email: chseet@iti.gov.sg
------------- start of grammar ------------
%token INDEX name SEGMENT item ','
%start fragment
%%
fragment
: list_index
;
list_index
: index
| list_index ',' index
;
index
: INDEX name SEGMENT list_item
| INDEX name
;
list_item
: item
| list_item ',' item
;
-------------- end of grammar -------------
[Looks to me like this is LR(2) -- when it sees a comma it has to reduce one
rule or the other but it can't because it needs to look ahead and see if
there is an INDEX following. -John]
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.