Happy: Order of Productions Removes R / R Conflicts

I have a grammar which, depending on the order of setting, 3 happy reports reduce / decrease conflicts or not. The minimum example I can find is:

%tokentype {Token} %token int { Int } '-' { Neg } both { Both } %nonassoc both %left '-' %nonassoc NEG %% E : int {IntE} | both EE {BothE $2 $3} | '-' E %prec NEG {NegE $2} | E '-' E {SubE $1 $3} { data Token = Int | Neg | Both deriving Show data Expr = BothE Expr Expr | IntE | SubE Expr Expr | NegE Expr deriving Show } 

It has 3 contraction reduction conflicts based on the inability to distinguish between " both 7 -3 " and " both 7-3 2 ". Fair enough!

However, if you replace the last two pieces for E ( '-' E %prec NEG and E '-' E ), the decrease / decrease conflicts will disappear. More mysteriously, if you then remove the %prec NEG directive, they will return. I am completely confused by what is happening here: why the question of order?

+7
haskell happy lr
source share

No one has answered this question yet.

See related questions:

3
happy: reduce / reduce conflict
3
How to rewrite grammar to eliminate shift-reduction conflict (in Haskell Happy parser)
2
Shift / decrease conflict in Happy grammar
2
Specify the order of alternatives in the happy parser
2
Shift / Decrease Conflicts in a Propositional Logic Parser in Happy
2
Happy Conflict Reduction Shift
2
Happy conflict offset / reduction
one
Solving this Shift / Reduce conflict in Happy / Bison
one
Parser Rules Compliance Procedure
0
Conflicts at ocamlyacc

All Articles