Improve tests for stack overflow in GLR parser.

Problem reported by twlevo@xs4all.nl.
* data/glr.c (struct yyGLRStack): Remove yyerrflag member.
All uses removed.
(yyStackOverflow): Just longjmp, but with value 2 so that caller
can handle the problem.
(YYCHK1): Use goto (a la yacc.c) rather than setting a flag.
(yyparse): New local variable yyresult to record the result.
Use result of setjmp to set it, rather than storing itinto
struct.
(yyDone): Remove label.
(yyacceptlab, yyabortlab, yyoverflowlab, yyreturn): New labels,
to mimic yacc.c.  Do not discard lookahead if it's EOF (possible
if YYABORT is used).
* tests/actions.at (_AT_CHECK_PRINTER_AND_DESTRUCTOR): Exit with
yyparse status; put status > 1 into diagnostic.
Check that status==2 works.
* tests/calc.at, tests/cxx-type.at, tests/glr-regression.at:
Use exit status 3 for failure to open (which shouldn't happen).
This commit is contained in:
Paul Eggert
2005-07-18 18:09:40 +00:00
parent 67fd79c427
commit 6100a9aa2e
6 changed files with 65 additions and 29 deletions

View File

@@ -337,16 +337,18 @@ yyerror (const char *msg)
int
main (int argc, const char *argv[])
{
int status;
yydebug = !!getenv ("YYDEBUG");
assert (argc == 2);
yysource = argv[1];
if (yyparse ())
status = yyparse ();
switch (status)
{
printf ("Parsing FAILED.\n");
exit (1);
case 0: printf ("Successful parse.\n"); break;
case 1: printf ("Parsing FAILED.\n"); break;
default: printf ("Parsing FAILED (status %d).\n", status); break;
}
printf ("Successful parse.\n");
return 0;
return status;
}
]])
@@ -450,7 +452,7 @@ Parsing FAILED.
# Upon stack overflow, all symbols on the stack should be destroyed.
# Only check for yacc.c.
AT_YACC_IF([
AT_PARSER_CHECK([./input '(x)(x)(x)(x)(x)(x)(x)'], 1,
AT_PARSER_CHECK([./input '(x)(x)(x)(x)(x)(x)(x)'], 2,
[[sending: '(' (0@0-9)
sending: 'x' (1@10-19)
thing (1@10-19): 'x' (1@10-19)
@@ -493,7 +495,7 @@ Freeing nterm line (9@90-119)
Freeing nterm line (6@60-89)
Freeing nterm line (3@30-59)
Freeing nterm line (0@0-29)
Parsing FAILED.
Parsing FAILED (status 2).
]])
])

View File

@@ -288,7 +288,7 @@ power (int base, int exponent)
{
int res = 1;
if (exponent < 0)
exit (1);
exit (3);
for (/* Niente */; exponent; --exponent)
res *= base;
return res;
@@ -315,7 +315,7 @@ main (int argc, const char **argv)
if (!yyin)
{
perror (argv[1]);
exit (1);
return 3;
}
]AT_LALR1_CC_IF([], [m4_bmatch([$4], [%debug],

View File

@@ -115,8 +115,8 @@ main (int argc, char **argv)
if (argc != 2)
abort ();
if (!freopen (argv[1], "r", stdin))
abort ();
exit (yyparse ());
return 3;
return yyparse ();
}
int

View File

@@ -202,7 +202,7 @@ int
main (int argc, char **argv)
{
yyin = stdin;
if (argc == 2 && !(yyin = fopen (argv[1], "r"))) return 1;
if (argc == 2 && !(yyin = fopen (argv[1], "r"))) return 3;
return yyparse ();
}
]])
@@ -312,7 +312,7 @@ int yylex (void)
int main(int argc, char* argv[]) {
yyin = stdin;
if (argc == 2 && !(yyin = fopen (argv[1], "r"))) return 1;
if (argc == 2 && !(yyin = fopen (argv[1], "r"))) return 3;
return yyparse ();
}
]])