]> git.saurik.com Git - bison.git/blobdiff - data/lalr1.cc
yysyntax_error: more preparation for readability of next patch.
[bison.git] / data / lalr1.cc
index cd54b6c3e61c8335fe9ed0e4cb698b2b55876ba3..206aee99141e17d55f87890dab30789276dfd61f 100644 (file)
@@ -1,6 +1,7 @@
 # C++ skeleton for Bison
 
-# Copyright (C) 2002-2010 Free Software Foundation, Inc.
+# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
+# 2010 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
@@ -24,9 +25,10 @@ m4_define([b4_parser_class_name],
 b4_defines_if([],
               [b4_fatal([b4_skeleton[: using %%defines is mandatory]])])
 
-# Backward compatibility.
-m4_define([b4_location_constructors])
-m4_include(b4_pkgdatadir/[location.cc])
+b4_percent_define_ifdef([[location_type]], [],
+  [# Backward compatibility.
+  m4_define([b4_location_constructors])
+  m4_include(b4_pkgdatadir/[location.cc])])
 
 # We do want M4 expansion after # for CPP macros.
 m4_changecom()
@@ -34,7 +36,7 @@ m4_divert_push(0)dnl
 b4_defines_if(
 [@output(b4_spec_defines_file@)@
 b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++],
-             [2002-2010])
+             [2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010])
 dnl FIXME: This is wrong, we want computed header guards.
 [
 /* C++ LALR(1) parser skeleton written by Akim Demaille.  */
@@ -46,8 +48,9 @@ dnl FIXME: This is wrong, we want computed header guards.
 
 #include <string>
 #include <iostream>
-#include "location.hh"
 #include "stack.hh"
+]b4_percent_define_ifdef([[location_type]], [],
+                         [[#include "location.hh"]])[
 
 /* Enabling traces.  */
 #ifndef YYDEBUG
@@ -67,25 +70,6 @@ dnl FIXME: This is wrong, we want computed header guards.
 # define YYTOKEN_TABLE ]b4_token_table[
 #endif
 
-/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
-   If N is 0, then set CURRENT to the empty location which ends
-   the previous symbol: RHS[0] (always defined).  */
-
-#ifndef YYLLOC_DEFAULT
-# define YYLLOC_DEFAULT(Current, Rhs, N)               \
-do {                                                   \
-  if (N)                                               \
-    {                                                  \
-      (Current).begin = (Rhs)[1].begin;                        \
-      (Current).end   = (Rhs)[N].end;                  \
-    }                                                  \
-  else                                                 \
-    {                                                  \
-      (Current).begin = (Current).end = (Rhs)[0].end;  \
-    }                                                  \
-} while (false)
-#endif
-
 ]b4_namespace_open[
 
   /// A Bison parser.
@@ -106,7 +90,8 @@ b4_user_stype
     typedef YYSTYPE semantic_type;
 #endif
     /// Symbol locations.
-    typedef ]b4_percent_define_get([[location_type]])[ location_type;
+    typedef ]b4_percent_define_get([[location_type]],
+                                   [[location]])[ location_type;
     /// Tokens.
     struct token
     {
@@ -298,7 +283,7 @@ b4_percent_code_get([[provides]])[]dnl
 ])dnl
 @output(b4_parser_file_name@)@
 b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++],
-             [2002-2010])
+             [2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010])
 b4_percent_code_get([[top]])[]dnl
 m4_if(b4_prefix, [yy], [],
 [
@@ -327,6 +312,26 @@ b4_percent_code_get[]dnl
 # endif
 #endif
 
+/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
+   If N is 0, then set CURRENT to the empty location which ends
+   the previous symbol: RHS[0] (always defined).  */
+
+#define YYRHSLOC(Rhs, K) ((Rhs)[K])
+#ifndef YYLLOC_DEFAULT
+# define YYLLOC_DEFAULT(Current, Rhs, N)                               \
+ do                                                                    \
+   if (N)                                                              \
+     {                                                                 \
+       (Current).begin = YYRHSLOC (Rhs, 1).begin;                      \
+       (Current).end   = YYRHSLOC (Rhs, N).end;                        \
+     }                                                                 \
+   else                                                                \
+     {                                                                 \
+       (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end;        \
+     }                                                                 \
+ while (false)
+#endif
+
 /* Suppress unused-variable warnings by "using" E.  */
 #define YYUSE(e) ((void) (e))
 
@@ -841,70 +846,70 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
   ]b4_parser_class_name[::yysyntax_error_ (]dnl
 b4_error_verbose_if([int yystate, int yytoken],
                     [int, int])[)
-  {
-    std::string yyres;]b4_error_verbose_if([[
+  {]b4_error_verbose_if([[
+    std::string yyres;
     int yyn = yypact_[yystate];
     if (yypact_ninf_ < yyn && yyn <= yylast_)
       {
-       /* Start YYX at -YYN if negative to avoid negative indexes in
-          YYCHECK.  In other words, skip the first -YYN actions for this
-          state because they are default actions.  */
-       int yyxbegin = yyn < 0 ? -yyn : 0;
+            /* Start YYX at -YYN if negative to avoid negative indexes in
+               YYCHECK.  In other words, skip the first -YYN actions for
+               this state because they are default actions.  */
+            int yyxbegin = yyn < 0 ? -yyn : 0;
 
-       /* Stay within bounds of both yycheck and yytname.  */
-       int yychecklim = yylast_ - yyn + 1;
-       int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
+            /* Stay within bounds of both yycheck and yytname.  */
+            int yychecklim = yylast_ - yyn + 1;
+            int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
 
         // Number of reported tokens (one for the "unexpected", one per
         // "expected").
-       size_t yycount = 0;
+        size_t yycount = 0;
         // Its maximum.
         enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
         // Arguments of yyformat.
         char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
         yyarg[yycount++] = yytname_[yytoken];
-       for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
-         if (yycheck_[yyx + yyn] == yyx && yyx != yyterror_
-             && !yy_table_value_is_error_ (yytable_[yyx + yyn]))
-          {
-            if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
-            {
-              yycount = 1;
-              break;
-            }
-            else
-              yyarg[yycount++] = yytname_[yyx];
-          }
-
-        char const* yyformat = 0;
-        switch (yycount)
-        {
-#define YYCASE_(N, S)                           \
-          case N:                               \
-            yyformat = S;                       \
-          break
-          YYCASE_(1, YY_("syntax error, unexpected %s"));
-          YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
-          YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
-          YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
-          YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
+            for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
+              if (yycheck_[yyx + yyn] == yyx && yyx != yyterror_
+                  && !yy_table_value_is_error_ (yytable_[yyx + yyn]))
+                {
+                  if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
+                    {
+                      yycount = 1;
+                      break;
+                    }
+                  else
+                    yyarg[yycount++] = yytname_[yyx];
+                }
+
+    char const* yyformat = 0;
+    switch (yycount)
+      {
+#define YYCASE_(N, S)                         \
+        case N:                               \
+          yyformat = S;                       \
+        break
+        YYCASE_(1, YY_("syntax error, unexpected %s"));
+        YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
+        YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
+        YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
+        YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
 #undef YYCASE_
-        }
-        // Argument number.
-        size_t yyi = 0;
-        for (char const* yyp = yyformat; *yyp; ++yyp)
-          if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount)
-          {
-            yyres += yytnamerr_ (yyarg[yyi++]);
-            ++yyp;
-          }
-          else
-            yyres += *yyp;
       }
-    else
-  ]])dnl
-[    yyres = YY_("syntax error");
-    return yyres;
+    // Argument number.
+    size_t yyi = 0;
+    for (char const* yyp = yyformat; *yyp; ++yyp)
+      if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount)
+        {
+          yyres += yytnamerr_ (yyarg[yyi++]);
+          ++yyp;
+        }
+      else
+        yyres += *yyp;
+    }
+  else
+    yyres = YY_("syntax error");
+    return yyres;]], [[
+    return YY_("syntax error");]])[
   }
 
 
@@ -1085,7 +1090,7 @@ b4_error_verbose_if([int yystate, int yytoken],
 dnl
 @output(b4_dir_prefix[]stack.hh@)@
 b4_copyright([Stack handling for Bison parsers in C++],
-             [2002-2010])[
+             [2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010])[
 
 #ifndef BISON_STACK_HH
 # define BISON_STACK_HH