summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdela Vais <adela.vais99@gmail.com>2020-09-01 21:54:34 +0300
committerAkim Demaille <akim.demaille@gmail.com>2020-09-02 07:38:42 +0200
commitf3bcb3de0e4bf9eb3e771857917e19aa271b4c30 (patch)
tree680be8113c4b03544c377e3eb9ff332b3caa21d1
parent325ec7d32414d3b732d22387bb54da6918ec2ffc (diff)
downloadbison-f3bcb3de0e4bf9eb3e771857917e19aa271b4c30.tar.gz
examples: d: fix the handling of unary +
It was interpreting "+exp" as "-exp". * examples/d/calc.y: Fix. * examples/d/calc.test: Check it.
-rw-r--r--examples/d/calc.test10
-rw-r--r--examples/d/calc.y2
2 files changed, 11 insertions, 1 deletions
diff --git a/examples/d/calc.test b/examples/d/calc.test
index cf4f80a8..6b237592 100644
--- a/examples/d/calc.test
+++ b/examples/d/calc.test
@@ -21,6 +21,16 @@ 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
run 1 "err: syntax error, unexpected *, expecting + or - or ( or number"
diff --git a/examples/d/calc.y b/examples/d/calc.y
index b0dee929..15b4f7c7 100644
--- a/examples/d/calc.y
+++ b/examples/d/calc.y
@@ -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; }
;