mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-10 12:53:03 +00:00
tests: check YYACCEPT and YYABORT
There are some tests that cover them, but nothing for all the skeletons. Let's do that in the calculator tests. * tests/calc.at: Check YYACCEPT and YYABORT.
This commit is contained in:
@@ -7,6 +7,8 @@ define a number of other macros to:
|
||||
- what skeleton is used
|
||||
|
||||
# Keywords
|
||||
The following keywords are used to label tests. Please follow them
|
||||
and avoid creating synonyms.
|
||||
- action
|
||||
- api.value.type
|
||||
- c++
|
||||
@@ -24,3 +26,9 @@ define a number of other macros to:
|
||||
- report
|
||||
- %union
|
||||
- variant
|
||||
|
||||
# Calculator
|
||||
The grammar features several special directives:
|
||||
- `!!` YYERROR
|
||||
- `!+` YYACCEPT
|
||||
- `!-` YYABORT
|
||||
|
||||
@@ -444,8 +444,10 @@ exp:
|
||||
| exp '^' exp { $$ = power ($1, $3); }
|
||||
| '(' exp ')' { $$ = $2; }
|
||||
| '(' error ')' { $$ = 1111; yyerrok; }
|
||||
| '!' { $$ = 0; YYERROR; }
|
||||
| '-' error { $$ = 0; YYERROR; }
|
||||
| '!' '!' { $$ = 0; YYERROR; }
|
||||
| '!' '+' { $$ = 0; YYACCEPT; }
|
||||
| '!' '-' { $$ = 0; YYABORT; }
|
||||
;
|
||||
%%
|
||||
|
||||
@@ -727,8 +729,10 @@ exp:
|
||||
| exp "^" exp { $$ = power ($1, $3); }
|
||||
| "(" exp ")" { $$ = $2; }
|
||||
| "(" error ")" { $$ = 1111; yyerrok(); }
|
||||
| "!" { $$ = 0; return YYERROR; }
|
||||
| "-" error { $$ = 0; return YYERROR; }
|
||||
| "!" "!" { $$ = 0; return YYERROR; }
|
||||
| "!" "+" { $$ = 0; return YYACCEPT; }
|
||||
| "!" "-" { $$ = 0; return YYABORT; }
|
||||
;
|
||||
%%
|
||||
|
||||
@@ -909,8 +913,10 @@ exp:
|
||||
| exp '^' exp { $$ = (int) Math.pow ($1, $3); }
|
||||
| '(' exp ')' { $$ = $2; }
|
||||
| '(' error ')' { $$ = 1111; }
|
||||
| '!' { $$ = 0; return YYERROR; }
|
||||
| '-' error { $$ = 0; return YYERROR; }
|
||||
| '!' '!' { $$ = 0; return YYERROR; }
|
||||
| '!' '+' { $$ = 0; return YYACCEPT; }
|
||||
| '!' '-' { $$ = 0; return YYABORT; }
|
||||
;
|
||||
]AT_CALC_YYLEX[
|
||||
]AT_LOCATION_IF([[
|
||||
@@ -953,6 +959,8 @@ m4_define([_AT_CHECK_CALC],
|
||||
[AT_DATA([[input]],
|
||||
[$2
|
||||
])
|
||||
echo "input:"
|
||||
sed -e 's/^/ | /' <input
|
||||
AT_JAVA_IF(
|
||||
[AT_JAVA_PARSER_CHECK([Calc $1 < input], 0, [m4_ifvaln(m4_quote($3), [$3])], [stderr])],
|
||||
[AT_PARSER_CHECK([calc $1 input], 0, [m4_ifvaln(m4_quote($3), [$3])], [stderr])])
|
||||
@@ -990,6 +998,8 @@ m4_define([_AT_CHECK_CALC_ERROR],
|
||||
[AT_DATA([[input]],
|
||||
[[$3
|
||||
]])
|
||||
echo "input:"
|
||||
sed -e 's/^/ | /' <input
|
||||
AT_JAVA_IF(
|
||||
[AT_JAVA_PARSER_CHECK([Calc $7 < input], $2, [m4_ifvaln(m4_quote($4), [$4])], [stderr])],
|
||||
[AT_PARSER_CHECK([calc $7 input], $2, [m4_ifvaln(m4_quote($4), [$4])], [stderr])])
|
||||
@@ -1020,8 +1030,7 @@ mv at-stderr stderr
|
||||
|
||||
# 2. Create the reference error message.
|
||||
AT_DATA([[expout]],
|
||||
[$6
|
||||
])
|
||||
[m4_n([$6])])
|
||||
|
||||
# 3. If locations are not used, remove them.
|
||||
AT_YYERROR_SEES_LOC_IF([],
|
||||
@@ -1190,11 +1199,11 @@ _AT_CHECK_CALC_ERROR([$1], [0],
|
||||
|
||||
# The same, but this time exercising explicitly triggered syntax errors.
|
||||
# POSIX says the lookahead causing the error should not be discarded.
|
||||
_AT_CHECK_CALC_ERROR([$1], [0], [(!) + (1 2) = 1],
|
||||
_AT_CHECK_CALC_ERROR([$1], [0], [(!!) + (1 2) = 1],
|
||||
[AT_PARAM_IF([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])[: error: 2222 != 1]])
|
||||
[AT_JAVA_IF([1.11-1.12], [1.11])[: syntax error on token [number] (expected: ['='] ['-'] ['+'] ['*'] ['/'] ['^'] [')'])
|
||||
]AT_JAVA_IF([1.1-1.17], [1.1-16])[: error: 2222 != 1]])
|
||||
|
||||
_AT_CHECK_CALC_ERROR([$1], [0], [(- *) + (1 2) = 1],
|
||||
[AT_PARAM_IF([final: 2222 0 3])],
|
||||
@@ -1213,6 +1222,24 @@ _AT_CHECK_CALC_ERROR([$1], [0], [(* *) + (*) + (*)],
|
||||
]AT_JAVA_IF([1.16-1.17], [1.16])[: syntax error on token ['*'] (expected: [number] ['-'] ['('] ['!'])]])
|
||||
|
||||
|
||||
# Special actions.
|
||||
# ----------------
|
||||
# !+ => YYACCEPT, !- => YYABORT, !! => YYERROR.
|
||||
|
||||
# YYACCEPT.
|
||||
# Java lacks the traces at the end for cleaning the stack
|
||||
# -Stack now 0 8 20
|
||||
# -Cleanup: popping token '+' (1.1: )
|
||||
# -Cleanup: popping nterm exp (1.1: 7)
|
||||
_AT_CHECK_CALC([], [1 + 2 * 3 + !+ ++],
|
||||
[AT_PARAM_IF([final: 0 0 0])],
|
||||
[AT_JAVA_IF([77], [80])])
|
||||
# YYABORT.
|
||||
_AT_CHECK_CALC_ERROR([$1], [1], [1 + 2 * 3 + !- ++],
|
||||
[AT_PARAM_IF([final: 0 0 0])],
|
||||
[102])
|
||||
|
||||
|
||||
# YYerror.
|
||||
# --------
|
||||
# Check that returning YYerror from the scanner properly enters
|
||||
|
||||
Reference in New Issue
Block a user