examples: d: fix the handling of unary +

It was interpreting "+exp" as "-exp".

* examples/d/calc.y: Fix.
* examples/d/calc.test: Check it.
This commit is contained in:
Adela Vais
2020-09-01 21:54:34 +03:00
committed by Akim Demaille
parent 325ec7d324
commit f3bcb3de0e
2 changed files with 11 additions and 1 deletions

View File

@@ -20,6 +20,16 @@ cat >input <<EOF
EOF
run 0 7
cat >input <<EOF
+1 + +2 * +3
EOF
run 0 7
cat >input <<EOF
-1 + -2 * -3
EOF
run 0 5
cat >input <<EOF
1 + 2 * * 3
EOF

View File

@@ -61,7 +61,7 @@ exp:
| exp "-" exp { $$ = $1 - $3; }
| exp "*" exp { $$ = $1 * $3; }
| exp "/" exp { $$ = $1 / $3; }
| "+" exp %prec UNARY { $$ = -$2; }
| "+" exp %prec UNARY { $$ = $2; }
| "-" exp %prec UNARY { $$ = -$2; }
| "(" exp ")" { $$ = $2; }
;