Thanks for the patch, but I suspect the code patch isn't quite general enough, since a similar problem occurs if the user invokes YYACCEPT or YYABORT. How about this patch instead?
2005-05-01 Paul Eggert <[EMAIL PROTECTED]> * data/yacc.c (yyerrlab): Move the code that destroys the stack from here.... (yyreturn): to here. That way, destructors are called properly even if the stack overflows, or the user calls YYACCEPT or YYABORT. Stack-overflow problem reported by Marcus Holland-Moritz. (yyoverflowlab): Destroy the lookahead. --- yacc.c.~1.86.~ 2005-04-24 20:13:06 -0700 +++ yacc.c 2005-05-01 06:12:32 -0700 @@ -1203,15 +1203,7 @@ yyerrlab: /* If at end of input, pop the error token, then the rest of the stack, then return failure. */ if (yychar == YYEOF) - for (;;) - { -]b4_location_if([[ yyerror_range[0] = *yylsp;]])[ - YYPOPSTACK; - if (yyssp == yyss) - YYABORT; - yydestruct (_("Error: popping"), - yystos[*yyssp], yyvsp]b4_location_if([, yylsp])[); - } + YYABORT; } else { @@ -1316,11 +1308,23 @@ yyabortlab: `----------------------------------------------*/ yyoverflowlab: yyerror (]b4_yyerror_args[_("parser stack overflow")); + yydestruct (_("Error: discarding lookahead"), + yytoken, &yylval]b4_location_if([, &yylloc])[); yyresult = 2; /* Fall through. */ #endif yyreturn: + if (yyssp != yyss) + for (;;) + { +]b4_location_if([[ yyerror_range[0] = *yylsp;]])[ + YYPOPSTACK; + if (yyssp == yyss) + break; + yydestruct (_("Error: popping"), + yystos[*yyssp], yyvsp]b4_location_if([, yylsp])[); + } #ifndef yyoverflow if (yyss != yyssa) YYSTACK_FREE (yyss);