[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to change default outcome of shift/reduce conflict?

From: Hans Aberg
Subject: Re: How to change default outcome of shift/reduce conflict?
Date: Sat, 12 Jan 2002 10:42:45 +0100

At 03:53 -0500 2002/01/12, Anthony DeRobertis wrote:
>Now, expr contains, among many other lines,
>expr: ...
>   | expr OR expr      { ... }
>     ...
>   ;
>The problem is a line which looks like this
>ANSWER expr WITH expr OR expr
>                     ^^
>Bison chooses the resolve the ambiguous grammar by shifting at the

There are different styles of handling this problem. One is trying to alter
the shift to reduce somehow; I think that the Bison manual say something
about that (in the section about IF ... THEN ... ELSE).

The other, which I prefer myself, is to rewrite the grammar so that it is
not ambiguous anymore:

The problem Bison has is that when "ANSWER expr WITH expr OR expr" is on
top of the stack, it does not know if it should apply the rule that this
line belongs to, or the expr -> expr OR expr rule. You could specify this
grammar even further, by say
expr: ...

    expr               {}
  | or_expr OR or_expr {}

 ANSWER expr WITH or_expr

if the idea is that OR should not appear between ANSWER and WITH. Or if OR
can appear there, the grammar might look like
expr: ...
   | expr OR expr       {}

...  ANSWER expr WITH expr {}

You should see the problem here, though: You have thrown in a redundant
"expr OR expr" in the grammar, which somehow should be removed.

  Hans Aberg

reply via email to

[Prev in Thread] Current Thread [Next in Thread]