yacc: fix YYBACKUP.

Reported by David Kastrup:
https://lists.gnu.org/archive/html/bug-bison/2011-10/msg00002.html.

	* data/yacc.c (YYBACKUP): Accept rhs size.
	Restore the proper state value.
	* TODO (YYBACKUP): Make it...
	* tests/actions.at: a new test case.
	* NEWS, THANKS: Update.
(cherry picked from commit d115aad911)

Conflicts:

	TODO
	data/yacc.c
This commit is contained in:
Akim Demaille
2012-01-25 16:57:58 +01:00
parent 7aadf26359
commit 94556574b5
4 changed files with 81 additions and 12 deletions

View File

@@ -1525,3 +1525,68 @@ AT_PARSER_CHECK([[./input]], [[0]], [],
]])
AT_CLEANUP
## ---------- ##
## YYBACKUP. ##
## ---------- ##
AT_SETUP([[YYBACKUP]])
AT_DATA_GRAMMAR([input.y],
[[
%error-verbose
%debug
%pure-parser
%code {
# include <stdio.h>
# include <stdlib.h>
# include <assert.h>
static void yyerror (const char *msg);
static int yylex (YYSTYPE *yylval);
}
%%
input:
exp exp {}
;
exp:
'a' { printf ("a: %d\n", $1); }
| 'b' { YYBACKUP('a', 123); }
| 'c' 'd' { YYBACKUP('a', 456); }
;
%%
static int
yylex (YYSTYPE *yylval)
{
static char const input[] = "bcd";
static size_t toknum;
assert (toknum < sizeof input);
*yylval = (toknum + 1) * 10;
return input[toknum++];
}
static void
yyerror (const char *msg)
{
fprintf (stderr, "%s\n", msg);
}
int
main (void)
{
yydebug = !!getenv("YYDEBUG");
return yyparse ();
}
]])
AT_BISON_CHECK([[-o input.c input.y]])
AT_COMPILE([[input]])
AT_PARSER_CHECK([[./input]], [[0]],
[[a: 123
a: 456
a: 789
]])
AT_CLEANUP