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 authored and Akim Demaille committed 2020-09-02 07:38:42 +02:00
1 parent 325ec7d324
commit f3bcb3de0e
2 files changed
+11 -1

No files matched your search

+10
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
+1 -1
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; }
;