c: add support for YYNOMEM

Suggested by Joe Nelson <joe@begriffs.com>.
https://lists.gnu.org/r/help-bison/2020-12/msg00020.html

* data/skeletons/glr.c, data/skeletons/yacc.c (YYNOMEM): New.
Use it.
(yyexhaustedlab): Rename as...
(yynomemlab): this.
* tests/calc.at: Check it.
* doc/bison.texi: Document it.
Fix incorrect statements about non-existing constants for YYERROR etc.
This commit is contained in:
Akim Demaille
2021-01-16 09:17:07 +01:00
parent a9f9f317b5
commit 17fb1d0377
6 changed files with 67 additions and 35 deletions

View File

@@ -32,3 +32,4 @@ The grammar features several special directives:
- `!!` YYERROR
- `!+` YYACCEPT
- `!-` YYABORT
- `!*` YYNOMEM

View File

@@ -447,7 +447,8 @@ exp:
| '-' error { $$ = 0; YYERROR; }
| '!' '!' { $$ = 0; YYERROR; }
| '!' '+' { $$ = 0; YYACCEPT; }
| '!' '-' { $$ = 0; YYABORT; }
| '!' '-' { $$ = 0; YYABORT; }]AT_C_IF([[
| '!' '*' { $$ = 0; YYNOMEM; }]])[
;
%%
@@ -1224,7 +1225,7 @@ _AT_CHECK_CALC_ERROR([$1], [0], [(* *) + (*) + (*)],
# Special actions.
# ----------------
# !+ => YYACCEPT, !- => YYABORT, !! => YYERROR.
# !+ => YYACCEPT, !- => YYABORT, !! => YYERROR, !* => YYNOMEM.
# YYACCEPT.
# Java lacks the traces at the end for cleaning the stack
@@ -1238,6 +1239,12 @@ _AT_CHECK_CALC([], [1 + 2 * 3 + !+ ++],
_AT_CHECK_CALC_ERROR([$1], [1], [1 + 2 * 3 + !- ++],
[AT_PARAM_IF([final: 0 0 0])],
[102])
AT_C_IF(
[# YYNOMEM.
_AT_CHECK_CALC_ERROR([$1], [2], [1 + 2 * 3 + !* ++],
[AT_PARAM_IF([final: 0 0 1])],
[102],
[1.14: memory exhausted])])
# YYerror.