help-bison
[Top][All Lists]
Advanced

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

Re: Effect of Precedence while there is no S/R conflict


From: Hans Aberg
Subject: Re: Effect of Precedence while there is no S/R conflict
Date: Sat, 3 Apr 2004 20:53:47 +0200

At 14:22 +0530 2004/04/03, RAJASANKAR K wrote:
>      Hi All,   Please validate whether my understanding stated  below is
>right. If there is no shift/reduce conflict at  all, precedences assigned
>to productions and terminals have no effect on  the bison behavior (in
>generating the parse table). Putting it other way, unless there is a
>shift/reduce conflict, bison  doesn't ever check the precedence of the
>token and  the production.   I am solving some shift/reduce conflicts by
>assigning prcedence to the token and the production involved in the
>conflict.  Neither this production nor the token is involved in any other
>conflicts with  any other token or production. I am asking the above
>question to assert that  this doesn't cause any other problems.

Bison is using a token-based precedence system, which, if correctly
implemented, only affects certain states with shift/reduce conflicts, and
nothing else. It looks at the tokens immediately before (reduce item) and
after (shift item) the "." in the conflicting state, and based on their
precedences make a choice reduce/shift.

You can easily check what choice it should make: Take a rules
   E: E + E | E * E
The, when parsing a + b . * c, when reaching the dot, one should arrive at
a state with
    E -> E + E .
    E -> E . * E
Normally, the precedence of + is lower than * (in Bison: the precedence
declaration of + comes before *), so then it should shift, so that the
multiplication is computed first. Thus, the rule whose token has the higher
precedence, will be computed first.

  Hans Aberg






reply via email to

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