bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

revamped skeletons to simplify Bison messages needing translation


From: Paul Eggert
Subject: revamped skeletons to simplify Bison messages needing translation
Date: Mon, 18 Jul 2005 17:10:22 -0700
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

I installed the following patch in order to regularize the
bison-runtime messages needing translation.  We want this set to be
small and stable, since it will be used by all Bison-generated parsers.

I'd like to generate a new Bison test version in the next day or so,
so that we can give these messages to the translation teams.  We can
then follow up with Bison 2.1 after they've had a bit of time to
translate.  Any comments or objections?

After this patch is installed, only the following strings require
translation in Bison-generated parsers:

memory exhausted
syntax error
syntax error, unexpected %s
syntax error, unexpected %s, expecting %s
syntax error, unexpected %s, expecting %s or %s
syntax error, unexpected %s, expecting %s or %s or %s
syntax error, unexpected %s, expecting %s or %s or %s or %s
syntax error: cannot back up
syntax is ambiguous

The last message is new: it's used only by GLR parsers.  The other
messages are shared among all the skeletons.

2005-07-18  Paul Eggert  <address@hidden>

        * 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".

Index: NEWS
===================================================================
RCS file: /cvsroot/bison/bison/NEWS,v
retrieving revision 1.118
diff -p -u -r1.118 NEWS
--- NEWS        13 Jul 2005 18:16:30 -0000      1.118
+++ NEWS        18 Jul 2005 23:59:06 -0000
@@ -10,6 +10,11 @@ Changes in the next version (not yet rel
   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
Index: data/glr.c
===================================================================
RCS file: /cvsroot/bison/bison/data/glr.c,v
retrieving revision 1.102
diff -p -u -r1.102 glr.c
--- data/glr.c  18 Jul 2005 22:10:15 -0000      1.102
+++ data/glr.c  18 Jul 2005 23:59:07 -0000
@@ -698,7 +698,7 @@ yyFail (yyGLRStack* yystack]b4_pure_form
 }
 
 static void
-yyStackOverflow (yyGLRStack* yystack]b4_pure_formals[)
+yyMemoryExhausted (yyGLRStack* yystack)
 {
   longjmp (yystack->yyexception_buffer, 2);
 }
@@ -995,13 +995,13 @@ yyexpandGLRStack (yyGLRStack* yystack]b4
   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
 
 #else
 
-  yyStackOverflow (yystack]b4_pure_args[);
+  yyMemoryExhausted (yystack);
 #endif
 }
 
@@ -1321,7 +1321,7 @@ yysplitStack (yyGLRStack* yystack, size_
                 (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* yyx
   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(address@hidden@], address@hidden@])])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(address@hidden@], address@hidden@])])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.  */
 
Index: data/yacc.c
===================================================================
RCS file: /cvsroot/bison/bison/data/yacc.c,v
retrieving revision 1.96
diff -p -u -r1.96 yacc.c
--- data/yacc.c 18 Jul 2005 22:10:15 -0000      1.96
+++ data/yacc.c 18 Jul 2005 23:59:07 -0000
@@ -911,7 +911,7 @@ m4_ifdef([b4_at_dollar_used], [[  yylsp[
           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[
       }
 #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[
        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
Index: doc/bison.texinfo
===================================================================
RCS file: /cvsroot/bison/bison/doc/bison.texinfo,v
retrieving revision 1.151
diff -p -u -r1.151 bison.texinfo
--- doc/bison.texinfo   18 Jul 2005 22:10:15 -0000      1.151
+++ doc/bison.texinfo   18 Jul 2005 23:59:07 -0000
@@ -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 Decla
 Section}), then Bison provides a more verbose and specific error message
 string instead of just plain @address@hidden"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 @address@hidden"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 @address@hidden"memory 
exhausted"}}.
+
+In some cases diagnostics like @address@hidden"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 lite
 * 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, 
 
@uref{http://www.cs.rhul.ac.uk/research/languages/publications/tomita_style_1.ps},
 (2000-12-24).
 
address@hidden Stack Overflow
address@hidden Stack Overflow, and How to Avoid It
address@hidden Memory Management
address@hidden Memory Management, and How to Avoid Memory Exhaustion
address@hidden memory exhaustion
address@hidden 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 R
 
 @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 i
 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
address@hidden
+Do not allow @code{YYINITDEPTH} to be greater than @code{YYMAXDEPTH}.
 
 @c FIXME: C++ output.
 Because of semantical differences between C and C++, the
address@hidden(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.
address@hidden(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 oc
 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
 
address@hidden Parser Stack Overflow
address@hidden Parser Stack Overflow
address@hidden Memory Exhausted
address@hidden 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 whe
 
 @deffn {Macro} YYINITDEPTH
 Macro for specifying the initial size of the parser stack.
address@hidden Overflow}.
address@hidden Management}.
 @end deffn
 
 @deffn {Function} yylex
@@ -8069,8 +8070,8 @@ variable within @code{yyparse}, and its 
 @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
Index: tests/actions.at
===================================================================
RCS file: /cvsroot/bison/bison/tests/actions.at,v
retrieving revision 1.50
diff -p -u -r1.50 actions.at
--- tests/actions.at    18 Jul 2005 18:09:40 -0000      1.50
+++ tests/actions.at    18 Jul 2005 23:59:07 -0000
@@ -487,7 +487,7 @@ sending: '(' (address@hidden)
 sending: 'x' (address@hidden)
 thing (address@hidden): 'x' (address@hidden)
 sending: ')' (address@hidden)
-200-209: parser stack overflow
+200-209: memory exhausted
 Freeing nterm thing (address@hidden)
 Freeing nterm line (address@hidden)
 Freeing nterm line (address@hidden)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]