From 1a05945136faf21ac5e3a07cfcdee8ee2e8ab6ae Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 19 Jul 2005 00:05:57 +0000 Subject: [PATCH] * NEWS: Document minor wording changes in diagnostics of Bison-generated parsers. * data/glr.c (yyMemoryExhausted): Renamed from yyStackOverflow. Remove unused formals. All uses changed. (yyreportAmbiguity): "ambiguity detected" -> "syntax is ambiguous". (yyparse): Rename yyoverflowlab to yyexhaustedlab. * data/yacc.c (yyparse): "parser stack overflow" -> "memory exhausted". Rename yyoverflowab to yyexhaustedlab. When memory exhaustion occurs during syntax-error reporting, report it separately rather than in a single diagnostic; this eases translation. * doc/bison.texinfo (Memory Management): Renamed from Stack Overflow. (Memory Exhausted): Renamed from Parser Stack Overflow. Revamp wording slightly to prefer "memory exhaustion". * tests/actions.at: "parser stack overflow" -> "memory exhausted". --- ChangeLog | 16 ++++++++++++ NEWS | 5 ++++ data/glr.c | 25 ++++++++++--------- data/yacc.c | 23 +++++++++-------- doc/bison.texinfo | 63 ++++++++++++++++++++++++----------------------- tests/actions.at | 2 +- 6 files changed, 81 insertions(+), 53 deletions(-) diff --git a/ChangeLog b/ChangeLog index 28dcb218..fca00022 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,21 @@ 2005-07-18 Paul Eggert + * NEWS: Document minor wording changes in diagnostics of + Bison-generated parsers. + * data/glr.c (yyMemoryExhausted): Renamed from yyStackOverflow. + Remove unused formals. All uses changed. + (yyreportAmbiguity): "ambiguity detected" -> "syntax is ambiguous". + (yyparse): Rename yyoverflowlab to yyexhaustedlab. + * data/yacc.c (yyparse): "parser stack overflow" -> "memory exhausted". + Rename yyoverflowab to yyexhaustedlab. + When memory exhaustion occurs during syntax-error reporting, + report it separately rather than in a single diagnostic; this + eases translation. + * doc/bison.texinfo (Memory Management): Renamed from Stack Overflow. + (Memory Exhausted): Renamed from Parser Stack Overflow. + Revamp wording slightly to prefer "memory exhaustion". + * tests/actions.at: "parser stack overflow" -> "memory exhausted". + * data/c.m4 (b4_yysymprint_generate): Use YYFPRINTF, not fprintf. Add i18n support to the GLR skeleton. Partially fix the C++ diff --git a/NEWS b/NEWS index 02b22d09..52064e7f 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,11 @@ Changes in the next version (not yet released): distributors should also see the new PACKAGING file. Thanks to Bruno Haible for this new feature. +* Wording in the Bison-generated parsers has been changed slightly to + simplify translation. In particular, the message "memory exhausted" + has replaced "parser stack overflow", as the old message was not + always accurate for modern Bison-generated parsers. + The following change was also in version 2.0a, 2005-05-22: * When generating verbose diagnostics, Bison-generated parsers no longer diff --git a/data/glr.c b/data/glr.c index c6fe4c3d..a137bbf7 100644 --- a/data/glr.c +++ b/data/glr.c @@ -698,7 +698,7 @@ yyFail (yyGLRStack* yystack]b4_pure_formals[, const char* yymsg) } static void -yyStackOverflow (yyGLRStack* yystack]b4_pure_formals[) +yyMemoryExhausted (yyGLRStack* yystack) { longjmp (yystack->yyexception_buffer, 2); } @@ -995,13 +995,13 @@ yyexpandGLRStack (yyGLRStack* yystack]b4_pure_formals[) size_t yyn; yysize = yystack->yynextFree - yystack->yyitems; if (YYMAXDEPTH <= yysize) - yyStackOverflow (yystack]b4_pure_args[); + yyMemoryExhausted (yystack); yynewSize = 2*yysize; if (YYMAXDEPTH < yynewSize) yynewSize = YYMAXDEPTH; yynewItems = (yyGLRStackItem*) YYMALLOC (yynewSize * sizeof yynewItems[0]); if (! yynewItems) - yyStackOverflow (yystack]b4_pure_args[); + yyMemoryExhausted (yystack); for (yyp0 = yystack->yyitems, yyp1 = yynewItems, yyn = yysize; 0 < yyn; yyn -= 1, yyp0 += 1, yyp1 += 1) @@ -1044,7 +1044,7 @@ yyexpandGLRStack (yyGLRStack* yystack]b4_pure_formals[) #else - yyStackOverflow (yystack]b4_pure_args[); + yyMemoryExhausted (yystack); #endif } @@ -1321,7 +1321,7 @@ yysplitStack (yyGLRStack* yystack, size_t yyk]b4_pure_formals[) (yyGLRState**) YYREALLOC (yystack->yytops.yystates, ((yystack->yytops.yycapacity *= 2) * sizeof yynewStates[0]))))) - yyStackOverflow (yystack]b4_pure_args[); + yyMemoryExhausted (yystack); yystack->yytops.yystates = yynewStates; } yystack->yytops.yystates[yystack->yytops.yysize] @@ -1536,7 +1536,7 @@ yyreportAmbiguity (yySemanticOption* yyx0, yySemanticOption* yyx1, yyreportTree (yyx1, 2); YYFPRINTF (stderr, "\n"); #endif - yyFail (yystack][]b4_pure_args[, YY_("ambiguity detected")); + yyFail (yystack][]b4_pure_args[, YY_("syntax is ambiguous")); } @@ -1815,7 +1815,10 @@ yyreportSyntaxError (yyGLRStack* yystack, YYFREE (yymsg); } else - yyerror (]b4_lyyerror_args[YY_("syntax error; also memory exhausted")); + { + yyerror (]b4_lyyerror_args[YY_("syntax error")); + yyMemoryExhausted (yystack); + } } else #endif /* YYERROR_VERBOSE */ @@ -1993,11 +1996,11 @@ m4_popdef([b4_at_dollar])dnl b4_syncline([@oline@], [@ofile@])])dnl [ if (! yyinitGLRStack (&yystack, YYINITDEPTH)) - goto yyoverflowlab; + goto yyexhaustedlab; switch (setjmp (yystack.yyexception_buffer)) { case 1: goto yyabortlab; - case 2: goto yyoverflowlab; + case 2: goto yyexhaustedlab; } yystack.yytokenp = &yytoken; yyglrShift (&yystack, 0, 0, 0, yylval, &yylloc]b4_user_args[); @@ -2109,8 +2112,8 @@ b4_syncline([@oline@], [@ofile@])])dnl yyresult = 1; goto yyreturn; - yyoverflowlab: - yyerror (]b4_lyyerror_args[YY_("parser stack overflow")); + yyexhaustedlab: + yyerror (]b4_lyyerror_args[YY_("memory exhausted")); yyresult = 2; /* Fall through. */ diff --git a/data/yacc.c b/data/yacc.c index 1d54e3b2..a9c3cf0e 100644 --- a/data/yacc.c +++ b/data/yacc.c @@ -911,7 +911,7 @@ m4_ifdef([b4_at_dollar_used], [[ yylsp[0] = yylloc; data in use in that stack, in bytes. This used to be a conditional around just the two extra args, but that might be undefined if yyoverflow is a macro. */ - yyoverflow (YY_("parser stack overflow"), + yyoverflow (YY_("memory exhausted"), &yyss1, yysize * sizeof (*yyssp), &yyvs1, yysize * sizeof (*yyvsp), ]b4_location_if([ &yyls1, yysize * sizeof (*yylsp),])[ @@ -922,11 +922,11 @@ m4_ifdef([b4_at_dollar_used], [[ yylsp[0] = yylloc; } #else /* no yyoverflow */ # ifndef YYSTACK_RELOCATE - goto yyoverflowlab; + goto yyexhaustedlab; # else /* Extend the stack our own way. */ if (YYMAXDEPTH <= yystacksize) - goto yyoverflowlab; + goto yyexhaustedlab; yystacksize *= 2; if (YYMAXDEPTH < yystacksize) yystacksize = YYMAXDEPTH; @@ -936,7 +936,7 @@ m4_ifdef([b4_at_dollar_used], [[ yylsp[0] = yylloc; union yyalloc *yyptr = (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); if (! yyptr) - goto yyoverflowlab; + goto yyexhaustedlab; YYSTACK_RELOCATE (yyss); YYSTACK_RELOCATE (yyvs); ]b4_location_if([ YYSTACK_RELOCATE (yyls);])[ @@ -1201,7 +1201,10 @@ yyerrlab: YYSTACK_FREE (yymsg); } else - yyerror (]b4_yyerror_args[YY_("syntax error; also memory exhausted")); + { + yyerror (]b4_yyerror_args[YY_("syntax error")); + goto yyexhaustedlab; + } } else #endif /* YYERROR_VERBOSE */ @@ -1317,11 +1320,11 @@ yyabortlab: goto yyreturn; #ifndef yyoverflow -/*----------------------------------------------. -| yyoverflowlab -- parser overflow comes here. | -`----------------------------------------------*/ -yyoverflowlab: - yyerror (]b4_yyerror_args[YY_("parser stack overflow")); +/*-------------------------------------------------. +| yyexhaustedlab -- memory exhaustion comes here. | +`-------------------------------------------------*/ +yyexhaustedlab: + yyerror (]b4_yyerror_args[YY_("memory exhausted")); yyresult = 2; /* Fall through. */ #endif diff --git a/doc/bison.texinfo b/doc/bison.texinfo index 1d4097e3..5f6f597a 100644 --- a/doc/bison.texinfo +++ b/doc/bison.texinfo @@ -267,7 +267,7 @@ The Bison Parser Algorithm * Reduce/Reduce:: When two rules are applicable in the same situation. * Mystery Conflicts:: Reduce/reduce conflicts that look unjustified. * Generalized LR Parsing:: Parsing arbitrary context-free grammars. -* Stack Overflow:: What happens when stack gets full. How to avoid it. +* Memory Management:: What happens when memory is exhausted. How to avoid it. Operator Precedence @@ -318,7 +318,7 @@ A Complete C++ Example Frequently Asked Questions -* Parser Stack Overflow:: Breaking the Stack Limits +* Memory Exhausted:: Breaking the Stack Limits * How Can I Reset the Parser:: @code{yyparse} Keeps some State * Strings are Destroyed:: @code{yylval} Loses Track of Strings * Implementing Gotos/Loops:: Control Flow in the Calculator @@ -4592,13 +4592,16 @@ declarations section (@pxref{Bison Declarations, ,The Bison Declarations Section}), then Bison provides a more verbose and specific error message string instead of just plain @w{@code{"syntax error"}}. -The parser can detect one other kind of error: stack overflow. This -happens when the input contains constructions that are very deeply +The parser can detect one other kind of error: memory exhaustion. This +can happen when the input contains constructions that are very deeply nested. It isn't likely you will encounter this, since the Bison -parser extends its stack automatically up to a very large limit. But -if overflow happens, @code{yyparse} calls @code{yyerror} in the usual -fashion, except that the argument string is @w{@code{"parser stack -overflow"}}. +parser normally extends its stack automatically up to a very large limit. But +if memory is exhausted, @code{yyparse} calls @code{yyerror} in the usual +fashion, except that the argument string is @w{@code{"memory exhausted"}}. + +In some cases diagnostics like @w{@code{"syntax error"}} are +translated automatically from English to some other language before +they are passed to @code{yyerror}. @xref{Internationalization}. The following definition suffices in simple programs: @@ -4961,7 +4964,7 @@ This kind of parser is known in the literature as a bottom-up parser. * Reduce/Reduce:: When two rules are applicable in the same situation. * Mystery Conflicts:: Reduce/reduce conflicts that look unjustified. * Generalized LR Parsing:: Parsing arbitrary context-free grammars. -* Stack Overflow:: What happens when stack gets full. How to avoid it. +* Memory Management:: What happens when memory is exhausted. How to avoid it. @end menu @node Look-Ahead @@ -5672,16 +5675,17 @@ London, Department of Computer Science, TR-00-12, @uref{http://www.cs.rhul.ac.uk/research/languages/publications/tomita_style_1.ps}, (2000-12-24). -@node Stack Overflow -@section Stack Overflow, and How to Avoid It +@node Memory Management +@section Memory Management, and How to Avoid Memory Exhaustion +@cindex memory exhaustion +@cindex memory management @cindex stack overflow @cindex parser stack overflow @cindex overflow of parser stack -The Bison parser stack can overflow if too many tokens are shifted and +The Bison parser stack can run out of memory if too many tokens are shifted and not reduced. When this happens, the parser function @code{yyparse} -returns a nonzero value, pausing only to call @code{yyerror} to report -the overflow. +calls @code{yyerror} and then returns 2. Because Bison parsers have growing stacks, hitting the upper limit usually results from using a right recursion instead of a left @@ -5689,12 +5693,12 @@ recursion, @xref{Recursion, ,Recursive Rules}. @vindex YYMAXDEPTH By defining the macro @code{YYMAXDEPTH}, you can control how deep the -parser stack can become before a stack overflow occurs. Define the +parser stack can become before memory is exhausted. Define the macro with a value that is an integer. This value is the maximum number of tokens that can be shifted (and not reduced) before overflow. The stack space allowed is not necessarily allocated. If you specify a -large value for @code{YYMAXDEPTH}, the parser actually allocates a small +large value for @code{YYMAXDEPTH}, the parser normally allocates a small stack at first, and then makes it bigger by stages as needed. This increasing allocation happens automatically and silently. Therefore, you do not need to make @code{YYMAXDEPTH} painfully small merely to save @@ -5716,17 +5720,14 @@ macro @code{YYINITDEPTH} to a positive integer. For the C unless you are assuming C99 or some other target language or compiler that allows variable-length arrays. The default is 200. -Do not allow @code{YYINITDEPTH} to be a value so large that arithmetic -overflow would occur when calculating the size of the stack space. -Also, do not allow @code{YYINITDEPTH} to be greater than -@code{YYMAXDEPTH}. +Do not allow @code{YYINITDEPTH} to be greater than @code{YYMAXDEPTH}. @c FIXME: C++ output. Because of semantical differences between C and C++, the -@acronym{LALR}(1) parsers in C produced by Bison by compiled as C++ -cannot grow. In this precise case (compiling a C parser as C++) you are -suggested to grow @code{YYINITDEPTH}. In the near future, a C++ output -output will be provided which addresses this issue. +@acronym{LALR}(1) parsers in C produced by Bison cannot grow when compiled +by C++ compilers. In this precise case (compiling a C parser as C++) you are +suggested to grow @code{YYINITDEPTH}. The Bison maintainers hope to fix +this deficiency in a future release. @node Error Recovery @chapter Error Recovery @@ -7539,17 +7540,17 @@ Several questions about Bison come up occasionally. Here some of them are addressed. @menu -* Parser Stack Overflow:: Breaking the Stack Limits +* Memory Exhausted:: Breaking the Stack Limits * How Can I Reset the Parser:: @code{yyparse} Keeps some State * Strings are Destroyed:: @code{yylval} Loses Track of Strings * Implementing Gotos/Loops:: Control Flow in the Calculator @end menu -@node Parser Stack Overflow -@section Parser Stack Overflow +@node Memory Exhausted +@section Memory Exhausted @display -My parser returns with error with a @samp{parser stack overflow} +My parser returns with error with a @samp{memory exhausted} message. What can I do? @end display @@ -8031,7 +8032,7 @@ use for @code{YYERROR_VERBOSE}, just whether you define it. Using @deffn {Macro} YYINITDEPTH Macro for specifying the initial size of the parser stack. -@xref{Stack Overflow}. +@xref{Memory Management}. @end deffn @deffn {Function} yylex @@ -8069,8 +8070,8 @@ variable within @code{yyparse}, and its address is passed to @end deffn @deffn {Macro} YYMAXDEPTH -Macro for specifying the maximum size of the parser stack. @xref{Stack -Overflow}. +Macro for specifying the maximum size of the parser stack. @xref{Memory +Management}. @end deffn @deffn {Variable} yynerrs diff --git a/tests/actions.at b/tests/actions.at index 55e51c6f..8ca79669 100644 --- a/tests/actions.at +++ b/tests/actions.at @@ -487,7 +487,7 @@ sending: '(' (18@180-189) sending: 'x' (19@190-199) thing (19@190-199): 'x' (19@190-199) sending: ')' (20@200-209) -200-209: parser stack overflow +200-209: memory exhausted Freeing nterm thing (19@190-199) Freeing nterm line (15@150-179) Freeing nterm line (12@120-149) -- 2.47.2