Re: Problem solving shift/reduce conflict (Lars Duening)
7 Jan 2003 23:25:17 -0500

          From comp.compilers

Related articles
Problem solving shift/reduce conflict (Ashwin) (2003-01-04)
Re: Problem solving shift/reduce conflict (Chris Dodd) (2003-01-07)
Re: Problem solving shift/reduce conflict (2003-01-07)
| List of all articles for this month |

From: (Lars Duening)
Newsgroups: comp.compilers
Date: 7 Jan 2003 23:25:17 -0500
Organization: Compilers Central
References: 03-01-011
Keywords: yacc, comment
Posted-Date: 07 Jan 2003 23:25:17 EST

Ashwin <> wrote:

> The following is my (simplified) grammar. The starting point is ArrayType.
> ArrayType: ReferenceType RankSpecifiers ;
> ReferenceType: ClassType | ArrayType ;
> ClassType: OBJECT | STRING ;
> RankSpecifiers: RankSpecifier
> | RankSpecifiers RankSpecifier
> ;

The problem is I see it is that you implement the repetition of array
indices twice: once in the ArrayType/ReferenceType rule combination,
and a second time in RankSpecifiers. The shift/reduce conflict comes to
pass when the parser encounters a LEFTBRACKET after having parsed a
LEFTBRACKET RIGHTBRACKET: at that point the parser has to choose between
shifting and continue parsing RankSpecifiers, or reducing the text so
far as ArrayType.

One solution is to drop the ReferenceType rule altogether and write
ArrayType as

ArrayType: ClassType RankSpecifiers;
[Several other people sent in similar analyses. Thanks to all. -John]

Post a followup to this message

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