]> git.saurik.com Git - bison.git/blobdiff - data/glr.c
In verbose parse error message, don't report `error' as an
[bison.git] / data / glr.c
index bcd4e615ac89dd3aca403a8f4abb84bb588ff590..c2fab0b8d3e71e3628d9b1e763eee419c9bc8d44 100644 (file)
@@ -197,23 +197,39 @@ static YYLTYPE yyloc_default;
 #  define yyfalse 0
 #endif
 
-#if ! defined (yy__GNUC__)
-#  define inline
+/*-----------------.
+| GCC extensions.  |
+`-----------------*/
+
+#ifndef __attribute__
+/* This feature is available in gcc versions 2.5 and later.  */
+# if !defined (__GNUC__) || __GNUC__ < 2 || \
+(__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
+#  define __attribute__(Spec) /* empty */
+# endif
+#endif
+
+#ifndef ATTRIBUTE_UNUSED
+# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
+#endif
+
+#if ! defined (__GNUC__)
+# define inline
 #endif
 
 /* YYFINAL -- State number of the termination state. */
-#define YYFINAL  ]b4_final[
+#define YYFINAL  ]b4_final_state_number[
 #define YYFLAG  ]b4_flag[
 #define YYLAST   ]b4_last[
 
 /* YYNTOKENS -- Number of terminals. */
-#define YYNTOKENS  ]b4_ntokens[
+#define YYNTOKENS  ]b4_tokens_number[
 /* YYNNTS -- Number of nonterminals. */
-#define YYNNTS  ]b4_nnts[
+#define YYNNTS  ]b4_nterms_number[
 /* YYNRULES -- Number of rules. */
-#define YYNRULES  ]b4_nrules[
+#define YYNRULES  ]b4_rules_number[
 /* YYNRULES -- Number of states. */
-#define YYNSTATES  ]b4_nstates[
+#define YYNSTATES  ]b4_states_number[
 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
 #define YYMAXRHS ]b4_r2_max[
 
@@ -225,7 +241,7 @@ static YYLTYPE yyloc_default;
   ((unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
 
 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
-static const ]b4_uint_type(b4_translate_max)[ yytranslate[] =
+static const ]b4_int_type_for([b4_translate])[ yytranslate[] =
 {
   ]b4_translate[
 };
@@ -233,19 +249,19 @@ static const ]b4_uint_type(b4_translate_max)[ yytranslate[] =
 #if YYDEBUG
 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
    YYRHS.  */
-static const ]b4_uint_type(b4_prhs_max)[ yyprhs[] =
+static const ]b4_int_type_for([b4_prhs])[ yyprhs[] =
 {
   ]b4_prhs[
 };
 
 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
-static const ]b4_sint_type(b4_rhs_max)[ yyrhs[] =
+static const ]b4_int_type_for([b4_rhs])[ yyrhs[] =
 {
   ]b4_rhs[
 };
 
 /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
-static const ]b4_uint_type(b4_rline_max)[ yyrline[] =
+static const ]b4_int_type_for([b4_rline])[ yyrline[] =
 {
   ]b4_rline[
 };
@@ -259,29 +275,29 @@ static const char *const yytname[] =
   ]b4_tname[
 };
 
-#define yytname_size (sizeof (yytname) / sizeof (yytname[0]))
+#define yytname_size ((int) (sizeof (yytname) / sizeof (yytname[0])))
 #endif
 
 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
-static const ]b4_uint_type(b4_r1_max)[ yyr1[] =
+static const ]b4_int_type_for([b4_r1])[ yyr1[] =
 {
   ]b4_r1[
 };
 
 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
-static const ]b4_uint_type(b4_r2_max)[ yyr2[] =
+static const ]b4_int_type_for([b4_r2])[ yyr2[] =
 {
   ]b4_r2[
 };
 
 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
-static const short yydprec[] =
+static const ]b4_int_type_for([b4_dprec])[ yydprec[] =
 {
   ]b4_dprec[
 };
 
 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
-static const short yymerger[] =
+static const ]b4_int_type_for([b4_merger])[ yymerger[] =
 {
   ]b4_merger[
 };
@@ -289,26 +305,27 @@ static const short yymerger[] =
 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
    doesn't specify something else to do.  Zero means the default is an
    error.  */
-static const short yydefact[] =
+static const ]b4_int_type_for([b4_defact])[ yydefact[] =
 {
   ]b4_defact[
 };
 
-/* YYPGOTO[NTERM-NUM]. */
-static const short yydefgoto[] =
+/* YYPDEFGOTO[NTERM-NUM]. */
+static const ]b4_int_type_for([b4_defgoto])[ yydefgoto[] =
 {
   ]b4_defgoto[
 };
 
 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
    STATE-NUM.  */
-static const short yypact[] =
+#define YYPACT_NINF ]b4_pact_ninf[
+static const ]b4_int_type_for([b4_pact])[ yypact[] =
 {
   ]b4_pact[
 };
 
 /* YYPGOTO[NTERM-NUM].  */
-static const short yypgoto[] =
+static const ]b4_int_type_for([b4_pgoto])[ yypgoto[] =
 {
   ]b4_pgoto[
 };
@@ -316,7 +333,8 @@ static const short yypgoto[] =
 /* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
    positive, shift that token.  If negative, reduce the rule which
    number is the opposite.  If zero, do what YYDEFACT says.  */
-static const short yytable[] =
+#define YYTABLE_NINF ]b4_table_ninf[
+static const ]b4_int_type_for([b4_table])[ yytable[] =
 {
   ]b4_table[
 };
@@ -325,19 +343,22 @@ static const short yytable[] =
    of conflicting reductions corresponding to action entry for state
    STATE-NUM in yytable.  0 means no conflicts.  The list in yyconfl
    is terminated by a rule number of 0. */
-static const short yyconflp[] =
+static const ]b4_int_type_for([b4_conflict_list_heads])[ yyconflp[] =
 {
   ]b4_conflict_list_heads[
 };
 
 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated
    by 0, pointed into by YYCONFLP. */
-static const short yyconfl[] =
+]dnl Do not use b4_int_type_for here, since there are places where
+dnl pointers onto yyconfl are taken, which type is "short *".
+dnl We probably ought to introduce a type for confl.
+[static const short yyconfl[] =
 {
   ]b4_conflicting_rules[
 };
 
-static const short yycheck[] =
+static const ]b4_int_type_for([b4_check])[ yycheck[] =
 {
   ]b4_check[
 };
@@ -373,10 +394,10 @@ int yyparse (void);
 #define YYRHSLOC(yyRhs,YYK) (yyRhs[YYK].yystate.yyloc)
 
 #ifndef YYLLOC_DEFAULT
-# define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN)           \
-  yyCurrent.yyfirst_line   = YYRHSLOC(yyRhs,1).yyfirst_line;      \
-  yyCurrent.yyfirst_column = YYRHSLOC(yyRhs,1).yyfirst_column;    \
-  yyCurrent.yylast_line    = YYRHSLOC(yyRhs,YYN).yylast_line;       \
+# define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN)                 \
+  yyCurrent.yyfirst_line   = YYRHSLOC(yyRhs,1).yyfirst_line;   \
+  yyCurrent.yyfirst_column = YYRHSLOC(yyRhs,1).yyfirst_column; \
+  yyCurrent.yylast_line    = YYRHSLOC(yyRhs,YYN).yylast_line;  \
   yyCurrent.yylast_column  = YYRHSLOC(yyRhs,YYN).yylast_column;
 #endif
 
@@ -428,7 +449,8 @@ do {                                                \
    multiple parsers can coexist.  */
 int yydebug;
 #else /* !YYDEBUG */
-# define YYDPRINTF(Args)
+  /* Avoid empty `if' bodies.  */
+# define YYDPRINTF(Args)  {}
 #endif /* !YYDEBUG */
 
 /* YYINITDEPTH -- initial size of the parser's stacks.  */
@@ -569,6 +591,9 @@ static YYRESULTTAG
 yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,
              YYSTYPE* yyvalp, YYLTYPE* yylocp, yyGLRStack* yystack)
 {
+  /* Avoid `unused' warnings in there are no $n. */
+  (void) yystack;
+
   if (yyrhslen == 0)
     {
       *yyvalp = yyval_default;
@@ -624,6 +649,10 @@ static YYSTYPE
 yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1)
 {
   YYSTYPE yyval = *yy0;
+  /* `Use' the arguments. */
+  (void) yy0;
+  (void) yy1;
+
   switch (yyn)
     {
       b4_mergers
@@ -652,7 +681,7 @@ yylhsNonterm (yyRuleNum yyrule)
 static inline bool
 yyisDefaultedState (yyStateNum yystate)
 {
-  return yypact[yystate] == YYFLAG;
+  return yypact[yystate] == YYPACT_NINF;
 }
 
 /** The default reduction for STATE, assuming it has one. */
@@ -707,7 +736,7 @@ yyisShiftAction (int yyaction)
 static inline bool
 yyisErrorAction (int yyaction)
 {
-  return yyaction == 0 || yyaction == YYFLAG;
+  return yyaction == 0 || yyaction == YYPACT_NINF;
 }
 
                                /* GLRStates */
@@ -720,8 +749,9 @@ yyhasResolvedValue (yyGLRState* yystate)
   return yystate->yyresolved;
 }
 
-void yyaddDeferredAction (yyGLRStack* yystack, yyGLRState* yystate,
-                         yyGLRState* yyrhs, yyRuleNum yyrule)
+static void
+yyaddDeferredAction (yyGLRStack* yystack, yyGLRState* yystate,
+                    yyGLRState* yyrhs, yyRuleNum yyrule)
 {
   yySemanticOption* yynewItem;
   yynewItem = &yystack->yynextFree->yyoption;
@@ -882,13 +912,13 @@ yyundeleteLastStack (yyGLRStack* yystack)
 static inline void
 yyremoveDeletes (yyGLRStack* yystack)
 {
-  int yyi, yyj;
+  size_t yyi, yyj;
   yyi = yyj = 0;
   while (yyj < yystack->yytops.yysize)
     {
       if (yystack->yytops.yystates[yyi] == NULL)
        {
-         if (YYDEBUG && yyi == yyj)
+         if (yyi == yyj)
            YYDPRINTF ((stderr, "Removing dead stacks.\n"));
          yystack->yytops.yysize -= 1;
        }
@@ -1022,9 +1052,10 @@ yydoAction (yyGLRStack* yystack, int yyk, yyRuleNum yyrule,
  *  added to the options for the existing state's semantic value.
  */
 static inline YYRESULTTAG
-yyglrReduce (yyGLRStack* yystack, int yyk, yyRuleNum yyrule, bool yyforceEval)
+yyglrReduce (yyGLRStack* yystack, size_t yyk, yyRuleNum yyrule,
+             bool yyforceEval)
 {
-  int yyposn = yystack->yytops.yystates[yyk]->yyposn;
+  size_t yyposn = yystack->yytops.yystates[yyk]->yyposn;
 
   if (yyforceEval || yystack->yysplitPoint == NULL)
     {
@@ -1041,7 +1072,8 @@ yyglrReduce (yyGLRStack* yystack, int yyk, yyRuleNum yyrule, bool yyforceEval)
     }
   else
     {
-      int yyi, yyn;
+      size_t yyi;
+      int yyn;
       yyGLRState* yys, *yys0 = yystack->yytops.yystates[yyk];
       yyStateNum yynewLRState;
 
@@ -1153,23 +1185,23 @@ yymergeOptionSets (yySemanticOption* yyy0, yySemanticOption* yyy1)
  *  parsing state; return 0 if no combination is possible,
  *  1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
 static int
-yypreference (yySemanticOption* yyy0, yySemanticOption* yyy1)
+yypreference (yySemanticOption* y0, yySemanticOption* y1)
 {
-  yyRuleNum yyr0 = yyy0->yyrule, yyr1 = yyy1->yyrule;
-  int yyp0 = yydprec[yyr0], yyp1 = yydprec[yyr1];
+  yyRuleNum r0 = y0->yyrule, r1 = y1->yyrule;
+  int p0 = yydprec[r0], p1 = yydprec[r1];
 
-  if (yyp0 == yyp1)
+  if (p0 == p1)
     {
-      if (yymerger[yyr0] == 0 || yymerger[yyr0] != yymerger[yyr1])
+      if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1])
        return 0;
       else
        return 1;
     }
-  if (yyp0 == 0 || yyp1 == 0)
+  if (p0 == 0 || p1 == 0)
     return 0;
-  if (yyp0 < yyp1)
+  if (p0 < p1)
     return 3;
-  if (yyp0 > yyp1)
+  if (p0 > p1)
     return 2;
   return 0;
 }
@@ -1269,6 +1301,10 @@ static void
 yyreportAmbiguity (yySemanticOption* yyx0, yySemanticOption* yyx1,
                   yyGLRStack* yystack)
 {
+  /* `Unused' warnings.  */
+  (void) yyx0;
+  (void) yyx1;
+
 #if YYDEBUG
   YYFPRINTF (stderr, "Ambiguity detected.\n");
   YYFPRINTF (stderr, "Option 1,\n");
@@ -1453,17 +1489,20 @@ yyprocessOneStack (yyGLRStack* yystack, int yyk,
 static void
 yyreportParseError (yyGLRStack* yystack, YYSTYPE* yylvalp, YYLTYPE* yyllocp)
 {
-  yySymbol* const yytokenp = yystack->yytokenp;
+  /* `Unused' warnings. */
+  (void) yylvalp;
+  (void) yyllocp;
 
   if (yystack->yyerrState == 0)
     {
 #if YYERROR_VERBOSE
+      yySymbol* const yytokenp = yystack->yytokenp;
       int yyn, yyx, yycount, yysize;
-      char* yyprefix;
+      const char* yyprefix;
       char* yyp;
       char* yymsg;
       yyn = yypact[yystack->yytops.yystates[0]->yylrState];
-      if (yyn > YYFLAG && yyn < YYLAST)
+      if (YYPACT_NINF < yyn && yyn < YYLAST)
        {
          yycount = 0;
          /* Start YYX at -YYN if negative to avoid negative indexes in
@@ -1473,7 +1512,7 @@ yyreportParseError (yyGLRStack* yystack, YYSTYPE* yylvalp, YYLTYPE* yyllocp)
          yyprefix = ", expecting ";
          for (yyx = yyn < 0 ? -yyn : 0; yyx < yytname_size && yycount <= 5;
               yyx += 1)
-           if (yycheck[yyx + yyn] == yyx)
+           if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
              yysize += strlen (yytokenName (yyx)) + strlen (yyprefix),
                yycount += 1, yyprefix = " or ";
          yymsg = yyp = (char*) malloc (yysize);
@@ -1510,7 +1549,8 @@ static void
 yyrecoverParseError (yyGLRStack* yystack, YYSTYPE* yylvalp, YYLTYPE* yyllocp)
 {
   yySymbol* const yytokenp = yystack->yytokenp;
-  int yyk, yyj;
+  size_t yyk;
+  int yyj;
 
   if (yystack->yyerrState == 0)
     yystack->yyerrState = 3;
@@ -1528,7 +1568,7 @@ yyrecoverParseError (yyGLRStack* yystack, YYSTYPE* yylvalp, YYLTYPE* yyllocp)
        *yytokenp = YYTRANSLATE (yychar);
        YYDPRINTF ((stderr, "Read token %s\n", yytokenName (*yytokenp)));
        yyj = yypact[yystack->yytops.yystates[0]->yylrState];
-       if (yyj == YYFLAG)
+       if (yyj == YYPACT_NINF)
          /* Something's not right; we shouldn't be here */
          yyFail (yystack, NULL);
        yyj += *yytokenp;
@@ -1537,7 +1577,7 @@ yyrecoverParseError (yyGLRStack* yystack, YYSTYPE* yylvalp, YYLTYPE* yyllocp)
            if (yydefact[yystack->yytops.yystates[0]->yylrState] != 0)
              return;
          }
-       else if (yytable[yyj] != 0 && yytable[yyj] != YYFLAG)
+       else if (yytable[yyj] != 0 && yytable[yyj] != YYTABLE_NINF)
          return;
       } while (yytrue);
     }
@@ -1557,7 +1597,7 @@ yyrecoverParseError (yyGLRStack* yystack, YYSTYPE* yylvalp, YYLTYPE* yyllocp)
   while (yystack->yytops.yystates[0] != NULL)
     {
       yyj = yypact[yystack->yytops.yystates[0]->yylrState] + YYTERROR;
-      if (yyj != YYFLAG + YYTERROR && yyj >= 0 && yyj <= YYLAST &&
+      if (yyj != YYPACT_NINF + YYTERROR && yyj >= 0 && yyj <= YYLAST &&
          yycheck[yyj] == YYTERROR && yyisShiftAction (yytable[yyj]))
        {
          yyglrShift (yystack, 0, yytable[yyj],
@@ -1717,11 +1757,14 @@ yyparse (YYPARSE_PARAM_ARG)
 }
 
 /* DEBUGGING ONLY */
+static void yypstack (yyGLRStack* yystack, int yyk) ATTRIBUTE_UNUSED;
+static void yypdumpstack (yyGLRStack* yystack) ATTRIBUTE_UNUSED;
 
-void
+static void
 yypstates (yyGLRState* yyst)
 {
-  void yy_yypstack (yyGLRState* yys)
+  static void
+  yy_yypstack (yyGLRState* yys)
     {
       if (yys->yypred == NULL)
        fprintf (stderr, "%d@%d", yys->yylrState, yys->yyposn);
@@ -1739,7 +1782,7 @@ yypstates (yyGLRState* yyst)
   fprintf (stderr, "\n");
 }
 
-void
+static void
 yypstack (yyGLRStack* yystack, int yyk)
 {
   yypstates (yystack->yytops.yystates[yyk]);
@@ -1749,11 +1792,11 @@ yypstack (yyGLRStack* yystack, int yyk)
     ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
 
 
-void
+static void
 yypdumpstack (yyGLRStack* yystack)
 {
   yyGLRStackItem* yyp;
-  int yyi;
+  size_t yyi;
   for (yyp = yystack->yyitems; yyp < yystack->yynextFree; yyp += 1)
     {
       fprintf (stderr, "%3d. ", yyp - yystack->yyitems);