summaryrefslogtreecommitdiff
path: root/parse/gram.y
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-02-13 20:33:11 -0800
committerOri Bernstein <ori@eigenstate.org>2017-02-13 21:13:04 -0800
commit8cc25499958961ae0a2afbe142b929f01cf34cbe (patch)
tree518547ac0bfa0510c0e85c46be8cf3b9644f1d40 /parse/gram.y
parent0139ee45f197942d81737539f64d9723968181ba (diff)
downloadmc-8cc25499958961ae0a2afbe142b929f01cf34cbe.tar.gz
Clean up warnings about ambiguous grammar.
Diffstat (limited to 'parse/gram.y')
-rw-r--r--parse/gram.y38
1 files changed, 29 insertions, 9 deletions
diff --git a/parse/gram.y b/parse/gram.y
index 67edb24..e687fef 100644
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -159,6 +159,26 @@ static void setupinit(Node *n);
%type <uconlist> unionbody
+/*
+We want to bind more tightly to `Foo unaryexpr
+than to binary operators around it. Eg:
+
+ `Foo +bar
+
+should be interpreted as
+
+ (`Foo (+bar))
+
+and not
+
+ (`Foo) + (bar)
+
+The default action of shifting does the right thing,
+but warnings suck.
+*/
+%left Ttick
+%left Tplus Tminus Tband
+
%union {
struct {
Srcloc loc;
@@ -683,15 +703,15 @@ shiftexpr
shiftop : Tbsl | Tbsr;
prefixexpr
- : Tinc prefixexpr {$$ = mkexpr($1->loc, Opreinc, $2, NULL);}
- | Tdec prefixexpr {$$ = mkexpr($1->loc, Opredec, $2, NULL);}
- | Tband prefixexpr {$$ = mkexpr($1->loc, Oaddr, $2, NULL);}
- | Tlnot prefixexpr {$$ = mkexpr($1->loc, Olnot, $2, NULL);}
- | Tbnot prefixexpr {$$ = mkexpr($1->loc, Obnot, $2, NULL);}
- | Tminus prefixexpr {$$ = mkexpr($1->loc, Oneg, $2, NULL);}
- | Tplus prefixexpr {$$ = $2;} /* positive is a nop */
- | Ttick name prefixexpr {$$ = mkexpr($1->loc, Oucon, $2, $3, NULL);}
- | Ttick name {$$ = mkexpr($1->loc, Oucon, $2, NULL);}
+ : Tinc prefixexpr {$$ = mkexpr($1->loc, Opreinc, $2, NULL);}
+ | Tdec prefixexpr {$$ = mkexpr($1->loc, Opredec, $2, NULL);}
+ | Tband prefixexpr {$$ = mkexpr($1->loc, Oaddr, $2, NULL);}
+ | Tlnot prefixexpr {$$ = mkexpr($1->loc, Olnot, $2, NULL);}
+ | Tbnot prefixexpr {$$ = mkexpr($1->loc, Obnot, $2, NULL);}
+ | Tminus prefixexpr {$$ = mkexpr($1->loc, Oneg, $2, NULL);}
+ | Tplus prefixexpr {$$ = $2;} /* positive is a nop */
+ | Ttick name prefixexpr {$$ = mkexpr($1->loc, Oucon, $2, $3, NULL);}
+ | Ttick name {$$ = mkexpr($1->loc, Oucon, $2, NULL);}
| postfixexpr
;