]> git.saurik.com Git - bison.git/blobdiff - data/glr.c
* data/glr.c (yyresolveValue): When merging semantic options, if at
[bison.git] / data / glr.c
index e1671325203d9d4af503067f9187bc8096e29f9d..975ec578cbe53a3094693cefdb2c3f4e22bc1f29 100644 (file)
@@ -1,7 +1,7 @@
 m4_divert(-1)                                                       -*- C -*-
 
 # GLR skeleton for Bison
-# Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+# Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -19,6 +19,8 @@ m4_divert(-1)                                                       -*- C -*-
 # 02110-1301  USA
 
 
+m4_include(b4_pkgdatadir/[c.m4])
+
 ## ---------------- ##
 ## Default values.  ##
 ## ---------------- ##
@@ -92,13 +94,6 @@ m4_define([b4_pure_formals],
 [b4_pure_if([b4_location_if([, YYLTYPE *yylocp])])[]b4_user_formals])
 
 
-# b4_lpure_formals
-# ----------------
-# Same as above, but on the look-ahead, hence yyllocp instead of yylocp.
-m4_define([b4_lpure_formals],
-[b4_pure_if([b4_location_if([YYLTYPE *yyllocp])])[]b4_user_formals])
-
-
 ## ----------------- ##
 ## Semantic Values.  ##
 ## ----------------- ##
@@ -149,7 +144,7 @@ m4_changecom()
 m4_divert(0)dnl
 @output @output_parser_name@
 b4_copyright([Skeleton parser for GLR parsing with Bison],
-  [2002, 2003, 2004, 2005])
+  [2002, 2003, 2004, 2005, 2006])
 [
 /* This is the parser code for GLR (Generalized LR) parser.  */
 
@@ -178,10 +173,11 @@ m4_define([b4_shared_declarations],
 
 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
 ]m4_ifdef([b4_stype],
-[b4_syncline([b4_stype_line], [b4_file_name])
-typedef union m4_bregexp(b4_stype, [^{], [YYSTYPE ])b4_stype YYSTYPE;
+[typedef union m4_bregexp(b4_stype, [^{], [YYSTYPE ])
+b4_stype
 /* Line __line__ of glr.c.  */
-b4_syncline([@oline@], [@ofile@])],
+b4_syncline([@oline@], [@ofile@])
+       YYSTYPE;],
 [typedef int YYSTYPE;])[
 # define YYSTYPE_IS_DECLARED 1
 # define YYSTYPE_IS_TRIVIAL 1
@@ -495,7 +491,7 @@ static const ]b4_int_type_for([b4_stos])[ yystos[] =
 #ifndef YYLLOC_DEFAULT
 # define YYLLOC_DEFAULT(Current, Rhs, N)                               \
     do                                                                 \
-      if (YYID (N))                                                    \
+      if (YYID (N))                                                    \
        {                                                               \
          (Current).first_line   = YYRHSLOC (Rhs, 1).first_line;        \
          (Current).first_column = YYRHSLOC (Rhs, 1).first_column;      \
@@ -577,15 +573,15 @@ do {                                              \
     YYFPRINTF Args;                            \
 } while (YYID (0))
 
-]b4_yysymprint_generate([b4_c_ansi_function_def])[
+]b4_yy_symbol_print_generate([b4_c_ansi_function_def])[
 
 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)                     \
 do {                                                                       \
   if (yydebug)                                                             \
     {                                                                      \
       YYFPRINTF (stderr, "%s ", Title);                                            \
-      yysymprint (stderr,                                                  \
-                 Type, Value]b4_location_if([, Location])[]b4_user_args[); \
+      yy_symbol_print (stderr, Type,                                       \
+                      Value]b4_location_if([, Location])[]b4_user_args[);  \
       YYFPRINTF (stderr, "\n");                                                    \
     }                                                                      \
 } while (YYID (0))
@@ -976,8 +972,8 @@ yydestroyGLRState (char const *yymsg, yyGLRState *yys]b4_user_formals[)
       if (yydebug)
        {
          YYFPRINTF (stderr, "%s unresolved ", yymsg);
-         yysymprint (stderr, yystos[yys->yylrState],
-                     &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[]b4_user_args[);
+         yy_symbol_print (stderr, yystos[yys->yylrState],
+                          &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[]b4_user_args[);
          YYFPRINTF (stderr, "\n");
        }
 #endif
@@ -1407,10 +1403,10 @@ yy_reduce_print (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
   for (yyi = 0; yyi < yynrhs; yyi++)
     {
       fprintf (stderr, "   $%d = ", yyi + 1);
-      yysymprint (stderr, yyrhs[yyprhs[yyrule] + yyi],
-                 &]b4_rhs_value(yynrhs, yyi + 1)[
-                 ]b4_location_if([, &]b4_rhs_location(yynrhs, yyi + 1))[]dnl
-                 b4_user_args[);
+      yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
+                      &]b4_rhs_value(yynrhs, yyi + 1)[
+                      ]b4_location_if([, &]b4_rhs_location(yynrhs, yyi + 1))[]dnl
+                      b4_user_args[);
       fprintf (stderr, "\n");
     }
 }
@@ -1616,7 +1612,7 @@ yypreference (yySemanticOption* y0, yySemanticOption* y1)
   return 0;
 }
 
-static YYRESULTTAG yyresolveValue (yySemanticOption* yyoptionList,
+static YYRESULTTAG yyresolveValue (yyGLRState* yys,
                                   yyGLRStack* yystackp, YYSTYPE* yyvalp,
                                   YYLTYPE* yylocp]b4_user_formals[);
 
@@ -1624,20 +1620,21 @@ static YYRESULTTAG
 yyresolveStates (yyGLRState* yys, int yyn,
                 yyGLRStack* yystackp]b4_user_formals[)
 {
-  YYRESULTTAG yyflag;
   if (0 < yyn)
     {
       YYASSERT (yys->yypred);
-      yyflag = yyresolveStates (yys->yypred, yyn-1, yystackp]b4_user_args[);
-      if (yyflag != yyok)
-       return yyflag;
+      YYCHK (yyresolveStates (yys->yypred, yyn-1, yystackp]b4_user_args[));
       if (! yys->yyresolved)
        {
-         yyflag = yyresolveValue (yys->yysemantics.yyfirstVal, yystackp,
-                                  &yys->yysemantics.yysval, &yys->yyloc
-                                 ]b4_user_args[);
+         YYSTYPE yysval;
+         YYRESULTTAG yyflag = yyresolveValue (yys, yystackp, &yysval,
+                                              &yys->yyloc]b4_user_args[);
          if (yyflag != yyok)
-           return yyflag;
+           {
+             yys->yysemantics.yyfirstVal = NULL;
+             return yyflag;
+           }
+         yys->yysemantics.yysval = yysval;
          yys->yyresolved = yytrue;
        }
     }
@@ -1732,12 +1729,13 @@ yyreportAmbiguity (yySemanticOption* yyx0, yySemanticOption* yyx1,
 }
 
 
-/** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
+/** Resolve the ambiguity represented in state S, perform the indicated
  *  actions, and return the result.  */
 static YYRESULTTAG
-yyresolveValue (yySemanticOption* yyoptionList, yyGLRStack* yystackp,
-               YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[)
+yyresolveValue (yyGLRState* yys, yyGLRStack* yystackp, YYSTYPE* yyvalp,
+               YYLTYPE* yylocp]b4_user_formals[)
 {
+  yySemanticOption* yyoptionList = yys->yysemantics.yyfirstVal;
   yySemanticOption* yybest;
   yySemanticOption** yypp;
   yybool yymerge;
@@ -1790,8 +1788,15 @@ yyresolveValue (yySemanticOption* yyoptionList, yyGLRStack* yystackp,
            {
              YYSTYPE yyval1;
              YYLTYPE yydummy;
-             YYCHK (yyresolveAction (yyp, yystackp, &yyval1,
-                                     &yydummy]b4_user_args[));
+             YYRESULTTAG yyflag = yyresolveAction (yyp, yystackp, &yyval1,
+                                                   &yydummy]b4_user_args[);
+             if (yyflag != yyok)
+               {
+                 yydestruct ("Cleanup: discarding merged value",
+                             yystos[yys->yylrState],
+                             yyvalp]b4_location_if([, yylocp])[]b4_user_args[);
+                 return yyflag;
+               }
              yyuserMerge (yymerger[yyp->yyrule], yyvalp, &yyval1);
            }
        }
@@ -1851,7 +1856,7 @@ yycompressStack (yyGLRStack* yystackp)
 
 static YYRESULTTAG
 yyprocessOneStack (yyGLRStack* yystackp, size_t yyk,
-                  size_t yyposn]b4_pure_formals[)
+                  size_t yyposn]b4_pure_formals[)
 {
   int yyaction;
   const short int* yyconflicts;
@@ -1885,7 +1890,7 @@ yyprocessOneStack (yyGLRStack* yystackp, size_t yyk,
              YYDPRINTF ((stderr, "Reading a token: "));
              yychar = YYLEX;
              *yytokenp = YYTRANSLATE (yychar);
-             YY_SYMBOL_PRINT ("Next token is", *yytokenp, &yylval, &yylloc);
+             YY_SYMBOL_PRINT ("Next token is", *yytokenp, &yylval, &yylloc);
            }
          yygetLRActions (yystate, *yytokenp, &yyaction, &yyconflicts);
 
@@ -1897,8 +1902,8 @@ yyprocessOneStack (yyGLRStack* yystackp, size_t yyk,
                          (unsigned long int) yyk));
              YYCHK (yyglrReduce (yystackp, yynewStack,
                                  *yyconflicts, yyfalse]b4_user_args[));
-             YYCHK (yyprocessOneStack (yystackp, yynewStack,
-                                       yyposn]b4_pure_args[));
+             YYCHK (yyprocessOneStack (yystackp, yynewStack,
+                                       yyposn]b4_pure_args[));
              yyconflicts += 1;
            }
 
@@ -1912,8 +1917,8 @@ yyprocessOneStack (yyGLRStack* yystackp, size_t yyk,
              break;
            }
          else
-           YYCHK (yyglrReduce (yystackp, yyk, -yyaction,
-                               yyfalse]b4_user_args[));
+           YYCHK (yyglrReduce (yystackp, yyk, -yyaction,
+                               yyfalse]b4_user_args[));
        }
     }
   return yyok;
@@ -2044,15 +2049,15 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
            yyGLRState *yys = yystackp->yytops.yystates[0];
            yyGLRStackItem yyerror_range[3];
            yyerror_range[1].yystate.yyloc = yys->yyloc;
-           yyerror_range[2].yystate.yyloc = yylloc;
+           yyerror_range[2].yystate.yyloc = yylloc;
            YYLLOC_DEFAULT (yys->yyloc, yyerror_range, 2);]])[
            yydestruct ("Error: discarding",
-                       *yytokenp, &yylval]b4_location_if([, &yylloc])[]b4_user_args[);
+                       *yytokenp, &yylval]b4_location_if([, &yylloc])[]b4_user_args[);
          }
        YYDPRINTF ((stderr, "Reading a token: "));
        yychar = YYLEX;
        *yytokenp = YYTRANSLATE (yychar);
-       YY_SYMBOL_PRINT ("Next token is", *yytokenp, &yylval, &yylloc);
+       YY_SYMBOL_PRINT ("Next token is", *yytokenp, &yylval, &yylloc);
        yyj = yypact[yystackp->yytops.yystates[0]->yylrState];
        if (yyis_pact_ninf (yyj))
          return;
@@ -2091,12 +2096,12 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
            {
              /* Shift the error token having adjusted its location.  */
              YYLTYPE yyerrloc;]b4_location_if([[
-             yystackp->yyerror_range[2].yystate.yyloc = yylloc;
+             yystackp->yyerror_range[2].yystate.yyloc = yylloc;
              YYLLOC_DEFAULT (yyerrloc, yystackp->yyerror_range, 2);]])[
              YY_SYMBOL_PRINT ("Shifting", yystos[yytable[yyj]],
-                              &yylval, &yyerrloc);
+                              &yylval, &yyerrloc);
              yyglrShift (yystackp, 0, yytable[yyj],
-                         yys->yyposn, &yylval, &yyerrloc);
+                         yys->yyposn, &yylval, &yyerrloc);
              yys = yystackp->yytops.yystates[0];
              break;
            }
@@ -2194,8 +2199,8 @@ b4_syncline([@oline@], [@ofile@])])dnl
              yyrule = yydefaultAction (yystate);
              if (yyrule == 0)
                {
-]b4_location_if([[               yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[
-                 yyreportSyntaxError (&yystack]b4_user_args[);
+]b4_location_if([[               yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[
+                 yyreportSyntaxError (&yystack]b4_user_args[);
                  goto yyuser_error;
                }
              YYCHK1 (yyglrReduce (&yystack, 0, yyrule, yytrue]b4_user_args[));
@@ -2207,25 +2212,25 @@ b4_syncline([@oline@], [@ofile@])])dnl
                  YYDPRINTF ((stderr, "Reading a token: "));
                  yychar = YYLEX;
                  yytoken = YYTRANSLATE (yychar);
-                 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
+                 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
                }
              yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
              if (*yyconflicts != 0)
                break;
              if (yyisShiftAction (yyaction))
                {
-                 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
+                 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
                  if (yytoken != YYEOF)
                    yytoken = YYEMPTY;
                  yyposn += 1;
-                 yyglrShift (&yystack, 0, yyaction, yyposn, &yylval, &yylloc);
+                 yyglrShift (&yystack, 0, yyaction, yyposn, &yylval, &yylloc);
                  if (0 < yystack.yyerrState)
                    yystack.yyerrState -= 1;
                }
              else if (yyisErrorAction (yyaction))
                {
-]b4_location_if([[               yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[
-                 yyreportSyntaxError (&yystack]b4_user_args[);
+]b4_location_if([[               yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[
+                 yyreportSyntaxError (&yystack]b4_user_args[);
                  goto yyuser_error;
                }
              else
@@ -2259,7 +2264,7 @@ b4_syncline([@oline@], [@ofile@])])dnl
             on yylval in the event of memory exhaustion.  */
 
          for (yys = 0; yys < yyn; yys += 1)
-           YYCHK1 (yyprocessOneStack (&yystack, yys, yyposn]b4_lpure_args[));
+           YYCHK1 (yyprocessOneStack (&yystack, yys, yyposn]b4_lpure_args[));
          yyremoveDeletes (&yystack);
          yyn = yystack.yytops.yysize;
 
@@ -2280,9 +2285,9 @@ b4_syncline([@oline@], [@ofile@])])dnl
                              &yyconflicts);
              /* Note that yyconflicts were handled by yyprocessOneStack.  */
              YYDPRINTF ((stderr, "On stack %lu, ", (unsigned long int) yys));
-             YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, &yylval, &yylloc);
+             YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, &yylval, &yylloc);
              yyglrShift (&yystack, yys, yyaction, yyposn,
-                         &yylval, &yylloc);
+                         &yylval, &yylloc);
              YYDPRINTF ((stderr, "Stack %lu now in state #%d\n",
                          (unsigned long int) yys,
                          yystack.yytops.yystates[yys]->yylrState));
@@ -2294,8 +2299,8 @@ b4_syncline([@oline@], [@ofile@])])dnl
                yyFail (&yystack][]b4_lpure_args[, YY_("syntax error"));
              YYCHK1 (yyresolveStack (&yystack]b4_user_args[));
              YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
-]b4_location_if([[           yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[
-             yyreportSyntaxError (&yystack]b4_user_args[);
+]b4_location_if([[           yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[
+             yyreportSyntaxError (&yystack]b4_user_args[);
              goto yyuser_error;
            }
          else if (yystack.yytops.yysize == 1)
@@ -2332,7 +2337,7 @@ b4_syncline([@oline@], [@ofile@])])dnl
  yyreturn:
   if (yytoken != YYEOF && yytoken != YYEMPTY)
     yydestruct ("Cleanup: discarding lookahead",
-               yytoken, &yylval]b4_location_if([, &yylloc])[]b4_user_args[);
+               yytoken, &yylval]b4_location_if([, &yylloc])[]b4_user_args[);
 
   /* If the stack is well-formed, pop the stack until it is empty,
      destroying its entries as we go.  But free the stack regardless
@@ -2442,12 +2447,7 @@ b4_epilogue
 m4_if(b4_defines_flag, 0, [],
 [@output @output_header_name@
 b4_copyright([Skeleton parser for GLR parsing with Bison],
-            [2002, 2003, 2004, 2005])[
-
-/* As a special exception, when this parser skeleton is copied by
-   Bison into a Bison output file, you may use that output file
-   without restriction.  This special exception was added by the Free
-   Software Foundation for C GLR parsers in version 2.2 of Bison.  */
+            [2002, 2003, 2004, 2005, 2006])[
 
 /* C GLR parser skeleton written by Paul Hilfinger.  */
 ]