* 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".
This commit is contained in:
Paul Eggert
2005-07-19 00:05:57 +00:00
parent a778f668a1
commit 1a05945136
6 changed files with 81 additions and 53 deletions

View File

@@ -1,5 +1,21 @@
2005-07-18 Paul Eggert <eggert@cs.ucla.edu> 2005-07-18 Paul Eggert <eggert@cs.ucla.edu>
* 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. * data/c.m4 (b4_yysymprint_generate): Use YYFPRINTF, not fprintf.
Add i18n support to the GLR skeleton. Partially fix the C++ Add i18n support to the GLR skeleton. Partially fix the C++

5
NEWS
View File

@@ -10,6 +10,11 @@ Changes in the next version (not yet released):
distributors should also see the new PACKAGING file. Thanks to distributors should also see the new PACKAGING file. Thanks to
Bruno Haible for this new feature. 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: The following change was also in version 2.0a, 2005-05-22:
* When generating verbose diagnostics, Bison-generated parsers no longer * When generating verbose diagnostics, Bison-generated parsers no longer

View File

@@ -698,7 +698,7 @@ yyFail (yyGLRStack* yystack]b4_pure_formals[, const char* yymsg)
} }
static void static void
yyStackOverflow (yyGLRStack* yystack]b4_pure_formals[) yyMemoryExhausted (yyGLRStack* yystack)
{ {
longjmp (yystack->yyexception_buffer, 2); longjmp (yystack->yyexception_buffer, 2);
} }
@@ -995,13 +995,13 @@ yyexpandGLRStack (yyGLRStack* yystack]b4_pure_formals[)
size_t yyn; size_t yyn;
yysize = yystack->yynextFree - yystack->yyitems; yysize = yystack->yynextFree - yystack->yyitems;
if (YYMAXDEPTH <= yysize) if (YYMAXDEPTH <= yysize)
yyStackOverflow (yystack]b4_pure_args[); yyMemoryExhausted (yystack);
yynewSize = 2*yysize; yynewSize = 2*yysize;
if (YYMAXDEPTH < yynewSize) if (YYMAXDEPTH < yynewSize)
yynewSize = YYMAXDEPTH; yynewSize = YYMAXDEPTH;
yynewItems = (yyGLRStackItem*) YYMALLOC (yynewSize * sizeof yynewItems[0]); yynewItems = (yyGLRStackItem*) YYMALLOC (yynewSize * sizeof yynewItems[0]);
if (! yynewItems) if (! yynewItems)
yyStackOverflow (yystack]b4_pure_args[); yyMemoryExhausted (yystack);
for (yyp0 = yystack->yyitems, yyp1 = yynewItems, yyn = yysize; for (yyp0 = yystack->yyitems, yyp1 = yynewItems, yyn = yysize;
0 < yyn; 0 < yyn;
yyn -= 1, yyp0 += 1, yyp1 += 1) yyn -= 1, yyp0 += 1, yyp1 += 1)
@@ -1044,7 +1044,7 @@ yyexpandGLRStack (yyGLRStack* yystack]b4_pure_formals[)
#else #else
yyStackOverflow (yystack]b4_pure_args[); yyMemoryExhausted (yystack);
#endif #endif
} }
@@ -1321,7 +1321,7 @@ yysplitStack (yyGLRStack* yystack, size_t yyk]b4_pure_formals[)
(yyGLRState**) YYREALLOC (yystack->yytops.yystates, (yyGLRState**) YYREALLOC (yystack->yytops.yystates,
((yystack->yytops.yycapacity *= 2) ((yystack->yytops.yycapacity *= 2)
* sizeof yynewStates[0]))))) * sizeof yynewStates[0])))))
yyStackOverflow (yystack]b4_pure_args[); yyMemoryExhausted (yystack);
yystack->yytops.yystates = yynewStates; yystack->yytops.yystates = yynewStates;
} }
yystack->yytops.yystates[yystack->yytops.yysize] yystack->yytops.yystates[yystack->yytops.yysize]
@@ -1536,7 +1536,7 @@ yyreportAmbiguity (yySemanticOption* yyx0, yySemanticOption* yyx1,
yyreportTree (yyx1, 2); yyreportTree (yyx1, 2);
YYFPRINTF (stderr, "\n"); YYFPRINTF (stderr, "\n");
#endif #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); YYFREE (yymsg);
} }
else else
yyerror (]b4_lyyerror_args[YY_("syntax error; also memory exhausted")); {
yyerror (]b4_lyyerror_args[YY_("syntax error"));
yyMemoryExhausted (yystack);
}
} }
else else
#endif /* YYERROR_VERBOSE */ #endif /* YYERROR_VERBOSE */
@@ -1993,11 +1996,11 @@ m4_popdef([b4_at_dollar])dnl
b4_syncline([@oline@], [@ofile@])])dnl b4_syncline([@oline@], [@ofile@])])dnl
[ [
if (! yyinitGLRStack (&yystack, YYINITDEPTH)) if (! yyinitGLRStack (&yystack, YYINITDEPTH))
goto yyoverflowlab; goto yyexhaustedlab;
switch (setjmp (yystack.yyexception_buffer)) switch (setjmp (yystack.yyexception_buffer))
{ {
case 1: goto yyabortlab; case 1: goto yyabortlab;
case 2: goto yyoverflowlab; case 2: goto yyexhaustedlab;
} }
yystack.yytokenp = &yytoken; yystack.yytokenp = &yytoken;
yyglrShift (&yystack, 0, 0, 0, yylval, &yylloc]b4_user_args[); yyglrShift (&yystack, 0, 0, 0, yylval, &yylloc]b4_user_args[);
@@ -2109,8 +2112,8 @@ b4_syncline([@oline@], [@ofile@])])dnl
yyresult = 1; yyresult = 1;
goto yyreturn; goto yyreturn;
yyoverflowlab: yyexhaustedlab:
yyerror (]b4_lyyerror_args[YY_("parser stack overflow")); yyerror (]b4_lyyerror_args[YY_("memory exhausted"));
yyresult = 2; yyresult = 2;
/* Fall through. */ /* Fall through. */

View File

@@ -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 data in use in that stack, in bytes. This used to be a
conditional around just the two extra args, but that might conditional around just the two extra args, but that might
be undefined if yyoverflow is a macro. */ be undefined if yyoverflow is a macro. */
yyoverflow (YY_("parser stack overflow"), yyoverflow (YY_("memory exhausted"),
&yyss1, yysize * sizeof (*yyssp), &yyss1, yysize * sizeof (*yyssp),
&yyvs1, yysize * sizeof (*yyvsp), &yyvs1, yysize * sizeof (*yyvsp),
]b4_location_if([ &yyls1, yysize * sizeof (*yylsp),])[ ]b4_location_if([ &yyls1, yysize * sizeof (*yylsp),])[
@@ -922,11 +922,11 @@ m4_ifdef([b4_at_dollar_used], [[ yylsp[0] = yylloc;
} }
#else /* no yyoverflow */ #else /* no yyoverflow */
# ifndef YYSTACK_RELOCATE # ifndef YYSTACK_RELOCATE
goto yyoverflowlab; goto yyexhaustedlab;
# else # else
/* Extend the stack our own way. */ /* Extend the stack our own way. */
if (YYMAXDEPTH <= yystacksize) if (YYMAXDEPTH <= yystacksize)
goto yyoverflowlab; goto yyexhaustedlab;
yystacksize *= 2; yystacksize *= 2;
if (YYMAXDEPTH < yystacksize) if (YYMAXDEPTH < yystacksize)
yystacksize = YYMAXDEPTH; yystacksize = YYMAXDEPTH;
@@ -936,7 +936,7 @@ m4_ifdef([b4_at_dollar_used], [[ yylsp[0] = yylloc;
union yyalloc *yyptr = union yyalloc *yyptr =
(union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
if (! yyptr) if (! yyptr)
goto yyoverflowlab; goto yyexhaustedlab;
YYSTACK_RELOCATE (yyss); YYSTACK_RELOCATE (yyss);
YYSTACK_RELOCATE (yyvs); YYSTACK_RELOCATE (yyvs);
]b4_location_if([ YYSTACK_RELOCATE (yyls);])[ ]b4_location_if([ YYSTACK_RELOCATE (yyls);])[
@@ -1201,7 +1201,10 @@ yyerrlab:
YYSTACK_FREE (yymsg); YYSTACK_FREE (yymsg);
} }
else else
yyerror (]b4_yyerror_args[YY_("syntax error; also memory exhausted")); {
yyerror (]b4_yyerror_args[YY_("syntax error"));
goto yyexhaustedlab;
}
} }
else else
#endif /* YYERROR_VERBOSE */ #endif /* YYERROR_VERBOSE */
@@ -1317,11 +1320,11 @@ yyabortlab:
goto yyreturn; goto yyreturn;
#ifndef yyoverflow #ifndef yyoverflow
/*----------------------------------------------. /*-------------------------------------------------.
| yyoverflowlab -- parser overflow comes here. | | yyexhaustedlab -- memory exhaustion comes here. |
`----------------------------------------------*/ `-------------------------------------------------*/
yyoverflowlab: yyexhaustedlab:
yyerror (]b4_yyerror_args[YY_("parser stack overflow")); yyerror (]b4_yyerror_args[YY_("memory exhausted"));
yyresult = 2; yyresult = 2;
/* Fall through. */ /* Fall through. */
#endif #endif

View File

@@ -267,7 +267,7 @@ The Bison Parser Algorithm
* Reduce/Reduce:: When two rules are applicable in the same situation. * Reduce/Reduce:: When two rules are applicable in the same situation.
* Mystery Conflicts:: Reduce/reduce conflicts that look unjustified. * Mystery Conflicts:: Reduce/reduce conflicts that look unjustified.
* Generalized LR Parsing:: Parsing arbitrary context-free grammars. * 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 Operator Precedence
@@ -318,7 +318,7 @@ A Complete C++ Example
Frequently Asked Questions 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 * How Can I Reset the Parser:: @code{yyparse} Keeps some State
* Strings are Destroyed:: @code{yylval} Loses Track of Strings * Strings are Destroyed:: @code{yylval} Loses Track of Strings
* Implementing Gotos/Loops:: Control Flow in the Calculator * 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 Section}), then Bison provides a more verbose and specific error message
string instead of just plain @w{@code{"syntax error"}}. string instead of just plain @w{@code{"syntax error"}}.
The parser can detect one other kind of error: stack overflow. This The parser can detect one other kind of error: memory exhaustion. This
happens when the input contains constructions that are very deeply can happen when the input contains constructions that are very deeply
nested. It isn't likely you will encounter this, since the Bison nested. It isn't likely you will encounter this, since the Bison
parser extends its stack automatically up to a very large limit. But parser normally extends its stack automatically up to a very large limit. But
if overflow happens, @code{yyparse} calls @code{yyerror} in the usual if memory is exhausted, @code{yyparse} calls @code{yyerror} in the usual
fashion, except that the argument string is @w{@code{"parser stack fashion, except that the argument string is @w{@code{"memory exhausted"}}.
overflow"}}.
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: 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. * Reduce/Reduce:: When two rules are applicable in the same situation.
* Mystery Conflicts:: Reduce/reduce conflicts that look unjustified. * Mystery Conflicts:: Reduce/reduce conflicts that look unjustified.
* Generalized LR Parsing:: Parsing arbitrary context-free grammars. * 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 @end menu
@node Look-Ahead @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}, @uref{http://www.cs.rhul.ac.uk/research/languages/publications/tomita_style_1.ps},
(2000-12-24). (2000-12-24).
@node Stack Overflow @node Memory Management
@section Stack Overflow, and How to Avoid It @section Memory Management, and How to Avoid Memory Exhaustion
@cindex memory exhaustion
@cindex memory management
@cindex stack overflow @cindex stack overflow
@cindex parser stack overflow @cindex parser stack overflow
@cindex overflow of parser stack @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} not reduced. When this happens, the parser function @code{yyparse}
returns a nonzero value, pausing only to call @code{yyerror} to report calls @code{yyerror} and then returns 2.
the overflow.
Because Bison parsers have growing stacks, hitting the upper limit Because Bison parsers have growing stacks, hitting the upper limit
usually results from using a right recursion instead of a left usually results from using a right recursion instead of a left
@@ -5689,12 +5693,12 @@ recursion, @xref{Recursion, ,Recursive Rules}.
@vindex YYMAXDEPTH @vindex YYMAXDEPTH
By defining the macro @code{YYMAXDEPTH}, you can control how deep the 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 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. of tokens that can be shifted (and not reduced) before overflow.
The stack space allowed is not necessarily allocated. If you specify a 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 stack at first, and then makes it bigger by stages as needed. This
increasing allocation happens automatically and silently. Therefore, increasing allocation happens automatically and silently. Therefore,
you do not need to make @code{YYMAXDEPTH} painfully small merely to save 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 unless you are assuming C99 or some other target language or compiler
that allows variable-length arrays. The default is 200. that allows variable-length arrays. The default is 200.
Do not allow @code{YYINITDEPTH} to be a value so large that arithmetic Do not allow @code{YYINITDEPTH} to be greater than @code{YYMAXDEPTH}.
overflow would occur when calculating the size of the stack space.
Also, do not allow @code{YYINITDEPTH} to be greater than
@code{YYMAXDEPTH}.
@c FIXME: C++ output. @c FIXME: C++ output.
Because of semantical differences between C and C++, the Because of semantical differences between C and C++, the
@acronym{LALR}(1) parsers in C produced by Bison by compiled as C++ @acronym{LALR}(1) parsers in C produced by Bison cannot grow when compiled
cannot grow. In this precise case (compiling a C parser as C++) you are by C++ compilers. In this precise case (compiling a C parser as C++) you are
suggested to grow @code{YYINITDEPTH}. In the near future, a C++ output suggested to grow @code{YYINITDEPTH}. The Bison maintainers hope to fix
output will be provided which addresses this issue. this deficiency in a future release.
@node Error Recovery @node Error Recovery
@chapter Error Recovery @chapter Error Recovery
@@ -7539,17 +7540,17 @@ Several questions about Bison come up occasionally. Here some of them
are addressed. are addressed.
@menu @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 * How Can I Reset the Parser:: @code{yyparse} Keeps some State
* Strings are Destroyed:: @code{yylval} Loses Track of Strings * Strings are Destroyed:: @code{yylval} Loses Track of Strings
* Implementing Gotos/Loops:: Control Flow in the Calculator * Implementing Gotos/Loops:: Control Flow in the Calculator
@end menu @end menu
@node Parser Stack Overflow @node Memory Exhausted
@section Parser Stack Overflow @section Memory Exhausted
@display @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? message. What can I do?
@end display @end display
@@ -8031,7 +8032,7 @@ use for @code{YYERROR_VERBOSE}, just whether you define it. Using
@deffn {Macro} YYINITDEPTH @deffn {Macro} YYINITDEPTH
Macro for specifying the initial size of the parser stack. Macro for specifying the initial size of the parser stack.
@xref{Stack Overflow}. @xref{Memory Management}.
@end deffn @end deffn
@deffn {Function} yylex @deffn {Function} yylex
@@ -8069,8 +8070,8 @@ variable within @code{yyparse}, and its address is passed to
@end deffn @end deffn
@deffn {Macro} YYMAXDEPTH @deffn {Macro} YYMAXDEPTH
Macro for specifying the maximum size of the parser stack. @xref{Stack Macro for specifying the maximum size of the parser stack. @xref{Memory
Overflow}. Management}.
@end deffn @end deffn
@deffn {Variable} yynerrs @deffn {Variable} yynerrs

View File

@@ -487,7 +487,7 @@ sending: '(' (18@180-189)
sending: 'x' (19@190-199) sending: 'x' (19@190-199)
thing (19@190-199): 'x' (19@190-199) thing (19@190-199): 'x' (19@190-199)
sending: ')' (20@200-209) sending: ')' (20@200-209)
200-209: parser stack overflow 200-209: memory exhausted
Freeing nterm thing (19@190-199) Freeing nterm thing (19@190-199)
Freeing nterm line (15@150-179) Freeing nterm line (15@150-179)
Freeing nterm line (12@120-149) Freeing nterm line (12@120-149)