[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/5] tests: check YYACCEPT and YYABORT
From: |
Akim Demaille |
Subject: |
[PATCH 1/5] tests: check YYACCEPT and YYABORT |
Date: |
Sat, 16 Jan 2021 12:59:01 +0100 |
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.
---
tests/README.md | 8 ++++++++
tests/calc.at | 43 +++++++++++++++++++++++++++++++++++--------
2 files changed, 43 insertions(+), 8 deletions(-)
diff --git a/tests/README.md b/tests/README.md
index 314dc606..76990a04 100644
--- a/tests/README.md
+++ b/tests/README.md
@@ -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
diff --git a/tests/calc.at b/tests/calc.at
index 005e6bee..2643d570 100644
--- a/tests/calc.at
+++ b/tests/calc.at
@@ -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
--
2.30.0
- [PATCH 0/5] Introduce YYNOMEM in C skeletons, Akim Demaille, 2021/01/16
- [PATCH 1/5] tests: check YYACCEPT and YYABORT,
Akim Demaille <=
- [PATCH 2/5] glr.c: style: formatting changes, Akim Demaille, 2021/01/16
- [PATCH 3/5] yacc.c, glr.c: style: rename yyreturn and yyreturnlab, Akim Demaille, 2021/01/16
- [PATCH 4/5] doc: spell check, Akim Demaille, 2021/01/16
- [PATCH 5/5] c: add support for YYNOMEM, Akim Demaille, 2021/01/16