summaryrefslogtreecommitdiff
path: root/tests/calc.at
diff options
context:
space:
mode:
authorAkim Demaille <akim.demaille@gmail.com>2020-09-20 17:06:04 +0200
committerAkim Demaille <akim.demaille@gmail.com>2020-09-20 17:24:06 +0200
commitf8cd049ecc493067720ab873747391795ce59c64 (patch)
tree4ebcc9f769799990102e9d0273435f57f03a2479 /tests/calc.at
parent72946549ed8e363035ada65bbbf03e4b0216e47a (diff)
downloadbison-f8cd049ecc493067720ab873747391795ce59c64.tar.gz
tests: check the location of the right-hand side symbols
The D skeleton was not properly supporting @1 etc. Reported by Adela Vais. https://lists.gnu.org/r/bison-patches/2020-09/msg00049.html * data/skeletons/d.m4 (b4_rhs_location): Fix it. * tests/calc.at: Check the support of @n for all the skeletons.
Diffstat (limited to 'tests/calc.at')
-rw-r--r--tests/calc.at51
1 files changed, 41 insertions, 10 deletions
diff --git a/tests/calc.at b/tests/calc.at
index c3557aa6..7da61af4 100644
--- a/tests/calc.at
+++ b/tests/calc.at
@@ -577,7 +577,7 @@ exp:
[c], [[
{
char buf[1024];
- snprintf (buf, sizeof buf, "calc: error: %d != %d", $1, $3);]AT_YYERROR_ARG_LOC_IF([[
+ snprintf (buf, sizeof buf, "error: %d != %d", $1, $3);]AT_YYERROR_ARG_LOC_IF([[
yyerror (&@$, ]AT_PARAM_IF([result, count, nerrs, ])[buf);]], [[
{
YYLTYPE old_yylloc = yylloc;
@@ -590,17 +590,39 @@ exp:
[c++], [[
{
char buf[1024];
- snprintf (buf, sizeof buf, "calc: error: %d != %d", $1, $3);
+ snprintf (buf, sizeof buf, "error: %d != %d", $1, $3);
]AT_GLR_IF([[yyparser.]])[error (]AT_LOCATION_IF([[@$, ]])[buf);
}]],
[d], [[
- yyerror (]AT_LOCATION_IF([[@$, ]])[format ("calc: error: %d != %d", $1, $3));]])[
+ yyerror (]AT_LOCATION_IF([[@$, ]])[format ("error: %d != %d", $1, $3));]])[
$$ = $1;
}
| exp '+' exp { $$ = $1 + $3; }
| exp '-' exp { $$ = $1 - $3; }
| exp '*' exp { $$ = $1 * $3; }
-| exp '/' exp { $$ = $1 / $3; }
+| exp '/' exp
+ {
+ if ($3 == 0)]AT_LANG_CASE(
+ [c], [[
+ {]AT_YYERROR_ARG_LOC_IF([[
+ yyerror (&@3, ]AT_PARAM_IF([result, count, nerrs, ])["error: null divisor");]], [[
+ {
+ YYLTYPE old_yylloc = yylloc;
+ yylloc = @3;
+ yyerror (]AT_PARAM_IF([result, count, nerrs, ])["error: null divisor");
+ yylloc = old_yylloc;
+ }
+ ]])[
+ }]],
+ [c++], [[
+ {
+ ]AT_GLR_IF([[yyparser.]])[error (]AT_LOCATION_IF([[@3, ]])["error: null divisor");
+ }]],
+ [d], [[
+ yyerror (]AT_LOCATION_IF([[@3, ]])["error: null divisor");]])[
+ else
+ $$ = $1 / $3;
+ }
| '-' exp %prec NEG { $$ = -$2; }
| exp '^' exp { $$ = power ($1, $3); }
| '(' exp ')' { $$ = $2; }
@@ -728,12 +750,18 @@ exp:
| exp '=' exp
{
if ($1.intValue () != $3.intValue ())
- yyerror (]AT_LOCATION_IF([[@$, ]])["calc: error: " + $1 + " != " + $3);
+ yyerror (]AT_LOCATION_IF([[@$, ]])["error: " + $1 + " != " + $3);
}
| exp '+' exp { $$ = $1 + $3; }
| exp '-' exp { $$ = $1 - $3; }
| exp '*' exp { $$ = $1 * $3; }
-| exp '/' exp { $$ = $1 / $3; }
+| exp '/' exp
+ {
+ if ($3.intValue () == 0)
+ yyerror (]AT_LOCATION_IF([[@3, ]])["error: null divisor");
+ else
+ $$ = $1 / $3;
+ }
| '-' exp %prec NEG { $$ = -$2; }
| exp '^' exp { $$ = (int) Math.pow ($1, $3); }
| '(' exp ')' { $$ = $2; }
@@ -1003,7 +1031,7 @@ _AT_CHECK_CALC_ERROR([$1], [0],
]AT_JAVA_IF([1.18-1.19], [1.18])[: syntax error on token [')'] (expected: [number] ['-'] ['('] ['!'])
]AT_JAVA_IF([1.23-1.24], [1.23])[: syntax error on token ['*'] (expected: [number] ['-'] ['('] ['!'])
]AT_JAVA_IF([1.41-1.42], [1.41])[: syntax error on token ['*'] (expected: [number] ['-'] ['('] ['!'])
-]AT_JAVA_IF([1.1-1.47], [1.1-46])[: calc: error: 4444 != 1]])
+]AT_JAVA_IF([1.1-1.47], [1.1-46])[: error: 4444 != 1]])
# The same, but this time exercising explicitly triggered syntax errors.
# POSIX says the lookahead causing the error should not be discarded.
@@ -1011,14 +1039,14 @@ _AT_CHECK_CALC_ERROR([$1], [0], [(!) + (1 2) = 1],
[[final: 2222 0 2]],
[102],
[AT_JAVA_IF([1.10-1.11], [1.10])[: syntax error on token [number] (expected: ['='] ['-'] ['+'] ['*'] ['/'] ['^'] [')'])
-]AT_JAVA_IF([1.1-1.16], [1.1-15])[: calc: error: 2222 != 1]])
+]AT_JAVA_IF([1.1-1.16], [1.1-15])[: error: 2222 != 1]])
_AT_CHECK_CALC_ERROR([$1], [0], [(- *) + (1 2) = 1],
[[final: 2222 0 3]],
[113],
[AT_JAVA_IF([1.4-1.5], [1.4])[: syntax error on token ['*'] (expected: [number] ['-'] ['('] ['!'])
]AT_JAVA_IF([1.12-1.13], [1.12])[: syntax error on token [number] (expected: ['='] ['-'] ['+'] ['*'] ['/'] ['^'] [')'])
-]AT_JAVA_IF([1.1-1.18], [1.1-17])[: calc: error: 2222 != 1]])
+]AT_JAVA_IF([1.1-1.18], [1.1-17])[: error: 2222 != 1]])
# Check that yyerrok works properly: second error is not reported,
# third and fourth are. Parse status is successful.
@@ -1056,7 +1084,10 @@ _AT_CHECK_CALC_ERROR([$1], [0], [(1 + # + 1) = 1111],
[102],
[[1.6: syntax error: invalid character: '#']])
-
+_AT_CHECK_CALC_ERROR([$1], [0], [(1 + 1) / (1 - 1)],
+ [[final: 2 0 1]],
+ [102],
+[AT_JAVA_IF([1.11-1.18], [1.11-17])[: error: null divisor]])
AT_BISON_OPTION_POPDEFS