[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Use of %prec breaks associativity
From: |
Akim Demaille |
Subject: |
Re: Use of %prec breaks associativity |
Date: |
Sat, 15 Nov 2008 10:06:39 +0100 |
Le 14 nov. 08 à 11:04, Jeroen Ketema a écrit :
%nonassoc '+'
%nonassoc PLUS_PREC
proc '+' proc %prec PLUS_PREC
This grammar states that when there are s/r conflicts between the rule
"proc + proc" and the token "+" then Bison should use their own
precedences to resolve the conflict. The precedence of the rule is
the one of PLUS_PREC, just as you stated via %prec, and that of "+" is
that of "+".
Therefore, since PLUS_PREC has higher precedence, the rule wins, which
in the end makes "+" behave left-associatively.
Now, in the case of "%nonassoc '+' PLUS_PREC" both the rule and the
token have the precedence, so we use their associativity to decide.
Here, it is non-assoc, so this token is not allowed to "follow this
rule", so indeed + is non assoc.
%nonassoc, %left etc. express nothing about associativity, they are
understood as hints to favor either the rule, the token or neither in
s/r conflicts.
If you want to express associativities, stick to the book, and write
%nonassoc '+';
foo: foo '+' foo;
It suffices. By default, the precedence/associativity of a rule is
that of its last token.