objc-parse.y
Ashish Gupta
ashishg@niksun.com
Tue Mar 12 14:05:00 GMT 2002
Cj B wrote:
> While trying to do a "make" on a DEC 3000 OSF1 V4.0 I get the following
> error:
>
> cd ./objc; bison -o objc-parse.c objc-parse.y
> objc-parse.y contains 72 shift/reduce conflicts
> expected 66 shift/reduce conflicts
>
> Any one know how to fix this or what it means?
>
> Thanks in advance
>
> Cj B
> black@krellinst.org
bison is a LALR(1) parser. What objc-parse.y contains ( I persume ) is a
Context Free Grammar represented in BNF (Backus Naur Form) this type of
representation allows .. Bison basically is used to generate a C program
which will parse the semantics of the BNF. here I am quoting what is
present in the bison maual. hope it makes things clearer :-
Suppose we are parsing a language which has if-then and if-then-else
statements, with a pair of rules like this:
if_stmt:
IF expr THEN stmt
| IF expr THEN stmt ELSE stmt
;
Here we assume that `IF', `THEN' and `ELSE' are terminal symbols for
specific keyword tokens.
When the `ELSE' token is read and becomes the look-ahead token, the
contents of the stack (assuming the input is valid) are just right for
reduction by the first rule. But it is also legitimate to shift the
`ELSE', because that would lead to eventual reduction by the second
rule.
This situation, where either a shift or a reduction would be valid,
is called a "shift/reduce conflict". Bison is designed to resolve
these conflicts by choosing to shift, unless otherwise directed by
operator precedence declarations.
** Back to earth here ***
So if there are 2 rules which are both doing the same thing ( or at least
bison is not able to differentiate between the rules. It raises a conflict
If there are 2 possible shifts ( stack push ) for a particular rule it is
a shift conflict similarly if there are 2 reduces ( stack pop ) this is a
reduce conflict. Use Bison with the --verbose option it may help to locate
the conflicting rules The only way i know is to see the conflicts and fix
the grammar rules in the input file to bison.
Hope this helps
Regards,
Ashish Gupta
More information about the Gcc-help
mailing list