* tests/glr-regression.at (Leaked semantic values when reporting

ambiguity): Remove unnecessary union and type declarations.
(Leaked lookahead after nondeterministic parse syntax error): New test
case.
* data/glr.c (yyparse): Check for zero stacks remaining before
attempting to shift the lookahead so that you don't lose it.
This commit is contained in:
Joel E. Denny
2006-03-04 03:29:03 +00:00
parent 35ee866a32
commit ae952af227
3 changed files with 93 additions and 21 deletions

View File

@@ -1431,8 +1431,6 @@ AT_SETUP([Leaked semantic values when reporting ambiguity])
AT_DATA_GRAMMAR([glr-regr15.y],
[[
%glr-parser
%union { int dummy; }
%type <dummy> parent_rhs_before
%destructor { parent_rhs_before_value = 0; } parent_rhs_before
%{
@@ -1512,3 +1510,69 @@ AT_CHECK([[./glr-regr15]], 0, [],
])
AT_CLEANUP
## ------------------------------------------------------------------------- ##
## Leaked lookahead after nondeterministic parse syntax error. ##
## ------------------------------------------------------------------------- ##
AT_SETUP([Leaked lookahead after nondeterministic parse syntax error])
AT_DATA_GRAMMAR([glr-regr16.y],
[[
%glr-parser
%destructor { lookahead_value = 0; } 'b'
%{
# include <stdlib.h>
static void yyerror (char const *);
static int yylex (void);
static int lookahead_value = 0;
# define USE(val)
%}
%%
start: alt1 'a' | alt2 'a' ;
alt1: ;
alt2: ;
%%
static void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}
static int
yylex (void)
{
static const char *input = "ab";
if (*input == 'b')
lookahead_value = 1;
return *input++;
}
int
main (void)
{
int exit_status = yyparse () != 1;
if (lookahead_value)
{
fprintf (stderr, "Lookahead destructor not called.\n");
exit_status = 1;
}
return exit_status;
}
]])
AT_CHECK([[bison -o glr-regr16.c glr-regr16.y]], 0, [],
[glr-regr16.y: conflicts: 1 reduce/reduce
])
AT_COMPILE([glr-regr16])
AT_CHECK([[./glr-regr16]], 0, [],
[syntax error
])
AT_CLEANUP