Implement %locations (inserts code that ensures YYLTYPE_IS_DECLARED is defined)
authorNick Downing <downing.nick@gmail.com>
Sun, 29 Jul 2018 09:04:40 +0000 (19:04 +1000)
committerNick Downing <downing.nick@gmail.com>
Sun, 29 Jul 2018 09:07:23 +0000 (19:07 +1000)
ast.py
bison_lr1dfa.py
skel/y.tab.c.patch

diff --git a/ast.py b/ast.py
index b4303ce..c2498fa 100644 (file)
--- a/ast.py
+++ b/ast.py
@@ -2325,8 +2325,8 @@ class PYACC(element.Element):
         sys.stderr.write('warning: ignoring %define api.prefix\n')
       #if self.api_pure != 0:
       #  sys.stderr.write('warning: ignoring %define api.pure\n')
-      if self.locations:
-        sys.stderr.write('warning: ignoring %define locations\n')
+      #if self.locations:
+      #  sys.stderr.write('warning: ignoring %define locations\n')
       if len(self.parse_error):
         sys.stderr.write('warning: ignoring %define parse.error\n')
       if len(self.parse_lac):
index 6cc4712..1f1f118 100644 (file)
@@ -424,6 +424,28 @@ typedef union YYSTYPE YYSTYPE;
 '''
               )
             )
+          elif line == '/* GENERATE YYLTYPE */\n':
+            fout.write(
+              '''/* GENERATE YYLTYPE BEGIN */
+{0:s}/* GENERATE YYLTYPE END */
+'''.format(
+                  '''#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
+typedef struct YYLTYPE YYLTYPE;
+struct YYLTYPE
+{
+  int first_line;
+  int first_column;
+  int last_line;
+  int last_column;
+};
+# define YYLTYPE_IS_DECLARED 1
+# define YYLTYPE_IS_TRIVIAL 1
+#endif
+'''
+                if pyacc[0].locations else
+                  ''
+              )
+            )
           elif line == '/* GENERATE SECTION1AFTERUNION */\n':
             fout.write(
               '''/* GENERATE SECTION1AFTERUNION BEGIN */
index ecdf758..86c6702 100644 (file)
@@ -1,5 +1,5 @@
---- y.tab.c.orig       2018-07-29 17:10:01.955483927 +1000
-+++ y.tab.c    2018-07-29 17:15:22.683492391 +1000
+--- y.tab.c.orig       2018-07-29 18:45:32.543635165 +1000
++++ y.tab.c    2018-07-29 19:01:47.335660891 +1000
 @@ -50,7 +50,7 @@
  #define YYSKELETON_NAME "yacc.c"
  
@@ -23,7 +23,7 @@
  
  # ifndef YY_NULLPTR
  #  if defined __cplusplus && 201103L <= __cplusplus
-@@ -97,28 +97,20 @@
+@@ -97,28 +97,26 @@
  # define YYTOKENTYPE
    enum yytokentype
    {
  #endif
  /* Tokens.  */
 -#define TOKEN 258
-+/* GENERATE TOKENS */
+-
 -/* Value type.  */
 -#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
--
++/* GENERATE TOKENS */
 -union YYSTYPE
 -{
 - /* something */ 
 -
 -};
--
++/* GENERATE SECTION1REQUIRES */
 -typedef union YYSTYPE YYSTYPE;
 -# define YYSTYPE_IS_TRIVIAL 1
 -# define YYSTYPE_IS_DECLARED 1
 -#endif
-+/* GENERATE SECTION1REQUIRES */
 +/* Value type.  */
 +/* GENERATE YYSTYPE */
  
++/* Location type.  */
++/* GENERATE YYLTYPE */
 +#if !YYPURE
  extern YYSTYPE yylval;
++# ifdef YYLTYPE_IS_DECLARED
++extern YYLTYPE yylloc;
++# endif
 +#endif
  
  int yyparse (void);
  
-@@ -126,6 +118,7 @@
+@@ -126,6 +124,7 @@
  
  /* Copy the second part of user declarations.  */
  
  
  #ifdef short
  # undef short
-@@ -364,155 +357,7 @@
+@@ -306,13 +305,20 @@
+ #if (! defined yyoverflow \
+      && (! defined __cplusplus \
+-         || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
++         || (!defined YYLTYPE_IS_DECLARED \
++             && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL) \
++         || (defined YYLTYPE_IS_DECLARED \
++             && defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
++             && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
+ /* A type that is properly aligned for any stack member.  */
+ union yyalloc
+ {
+   yytype_int16 yyss_alloc;
+   YYSTYPE yyvs_alloc;
++# ifdef YYLTYPE_IS_DECLARED
++  YYLTYPE yyls_alloc;
++# endif
+ };
+ /* The size of the maximum gap between one aligned stack and the next.  */
+@@ -320,9 +326,15 @@
+ /* The size of an array large to enough to hold all stacks, each with
+    N elements.  */
+-# define YYSTACK_BYTES(N) \
++# ifdef YYLTYPE_IS_DECLARED
++#  define YYSTACK_BYTES(N) \
++     ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
++      + 2 * YYSTACK_GAP_MAXIMUM)
++# else
++#  define YYSTACK_BYTES(N) \
+      ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
+       + YYSTACK_GAP_MAXIMUM)
++#endif
+ # define YYCOPY_NEEDED 1
+@@ -364,155 +376,7 @@
  # endif
  #endif /* !YYCOPY_NEEDED */
  
  
  #define yyerrok         (yyerrstatus = 0)
  #define yyclearin       (yychar = YYEMPTY)
-@@ -936,9 +781,7 @@
+@@ -526,7 +390,25 @@
+ #define YYRECOVERING()  (!!yyerrstatus)
+-#define YYBACKUP(Token, Value)                                  \
++#if YYPURE >= 2 && defined YYLTYPE_IS_DECLARED
++# define YYBACKUP(Token, Value)                                 \
++do                                                              \
++  if (yychar == YYEMPTY)                                        \
++    {                                                           \
++      yychar = (Token);                                         \
++      yylval = (Value);                                         \
++      YYPOPSTACK (yylen);                                       \
++      yystate = *yyssp;                                         \
++      goto yybackup;                                            \
++    }                                                           \
++  else                                                          \
++    {                                                           \
++      yyerror (&yylloc, YY_("syntax error: cannot back up")); \
++      YYERROR;                                                  \
++    }                                                           \
++while (0)
++#else
++# define YYBACKUP(Token, Value)                                 \
+ do                                                              \
+   if (yychar == YYEMPTY)                                        \
+     {                                                           \
+@@ -542,12 +424,39 @@
+       YYERROR;                                                  \
+     }                                                           \
+ while (0)
++#endif
+ /* Error token number */
+ #define YYTERROR        1
+ #define YYERRCODE       256
++#ifdef YYLTYPE_IS_DECLARED
++/* 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).first_line   = YYRHSLOC (Rhs, 1).first_line;        \
++          (Current).first_column = YYRHSLOC (Rhs, 1).first_column;      \
++          (Current).last_line    = YYRHSLOC (Rhs, N).last_line;         \
++          (Current).last_column  = YYRHSLOC (Rhs, N).last_column;       \
++        }                                                               \
++      else                                                              \
++        {                                                               \
++          (Current).first_line   = (Current).last_line   =              \
++            YYRHSLOC (Rhs, 0).last_line;                                \
++          (Current).first_column = (Current).last_column =              \
++            YYRHSLOC (Rhs, 0).last_column;                              \
++        }                                                               \
++    while (0)
++# endif
++# define YYRHSLOC(Rhs, K) ((Rhs)[K])
++#endif
+ /* Enable debugging if requested.  */
+ #if YYDEBUG
+@@ -563,13 +472,64 @@
+     YYFPRINTF Args;                             \
+ } while (0)
+-/* This macro is provided for backward compatibility. */
++/* YY_LOCATION_PRINT -- Print the location on the stream.
++   This macro was not mandated originally: define only if we know
++   we won't break user code: when these are the locations we know.  */
++
+ #ifndef YY_LOCATION_PRINT
+-# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
+-#endif
++# if defined YYLTYPE_IS_DECLARED \
++     && defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
++
++/* Print *YYLOCP on YYO.  Private, do not rely on its existence. */
++
++YY_ATTRIBUTE_UNUSED
++static unsigned
++yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp)
++{
++  unsigned res = 0;
++  int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
++  if (0 <= yylocp->first_line)
++    {
++      res += YYFPRINTF (yyo, "%d", yylocp->first_line);
++      if (0 <= yylocp->first_column)
++        res += YYFPRINTF (yyo, ".%d", yylocp->first_column);
++    }
++  if (0 <= yylocp->last_line)
++    {
++      if (yylocp->first_line < yylocp->last_line)
++        {
++          res += YYFPRINTF (yyo, "-%d", yylocp->last_line);
++          if (0 <= end_col)
++            res += YYFPRINTF (yyo, ".%d", end_col);
++        }
++      else if (0 <= end_col && yylocp->first_column < end_col)
++        res += YYFPRINTF (yyo, "-%d", end_col);
++    }
++  return res;
++ }
++#  define YY_LOCATION_PRINT(File, Loc)          \
++  yy_location_print_ (File, &(Loc))
+-# define YY_SYMBOL_PRINT(Title, Type, Value, Location)                    \
++# else
++#  define YY_LOCATION_PRINT(File, Loc) ((void) 0)
++# endif
++#endif
++
++# ifdef YYLTYPE_IS_DECLARED
++#  define YY_SYMBOL_PRINT(Title, Type, Value, Location)                   \
++do {                                                                      \
++  if (yydebug)                                                            \
++    {                                                                     \
++      YYFPRINTF (stderr, "%s ", Title);                                   \
++      yy_symbol_print (stderr,                                            \
++                  Type, Value, Location); \
++      YYFPRINTF (stderr, "\n");                                           \
++    }                                                                     \
++} while (0)
++#
++# else
++#  define YY_SYMBOL_PRINT(Title, Type, Value, Location)                   \
+ do {                                                                      \
+   if (yydebug)                                                            \
+     {                                                                     \
+@@ -579,12 +539,29 @@
+       YYFPRINTF (stderr, "\n");                                           \
+     }                                                                     \
+ } while (0)
++# endif
+ /*----------------------------------------.
+ | Print this symbol's value on YYOUTPUT.  |
+ `----------------------------------------*/
++# ifdef YYLTYPE_IS_DECLARED
++static void
++yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
++{
++  FILE *yyo = yyoutput;
++  YYUSE (yyo);
++  YYUSE (yylocationp);
++  if (!yyvaluep)
++    return;
++#  ifdef YYPRINT
++  if (yytype < YYNTOKENS)
++    YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
++#  endif
++  YYUSE (yytype);
++}
++# else
+ static void
+ yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
+ {
+@@ -592,18 +569,32 @@
+   YYUSE (yyo);
+   if (!yyvaluep)
+     return;
+-# ifdef YYPRINT
++#  ifdef YYPRINT
+   if (yytype < YYNTOKENS)
+     YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
+-# endif
++#  endif
+   YYUSE (yytype);
+ }
++# endif
+ /*--------------------------------.
+ | Print this symbol on YYOUTPUT.  |
+ `--------------------------------*/
++# ifdef YYLTYPE_IS_DECLARED
++static void
++yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
++{
++  YYFPRINTF (yyoutput, "%s %s (",
++             yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
++
++  YY_LOCATION_PRINT (yyoutput, *yylocationp);
++  YYFPRINTF (yyoutput, ": ");
++  yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp);
++  YYFPRINTF (yyoutput, ")");
++}
++# else
+ static void
+ yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
+ {
+@@ -613,6 +604,7 @@
+   yy_symbol_value_print (yyoutput, yytype, yyvaluep);
+   YYFPRINTF (yyoutput, ")");
+ }
++# endif
+ /*------------------------------------------------------------------.
+ | yy_stack_print -- Print the state stack from its BOTTOM up to its |
+@@ -642,6 +634,33 @@
+ | Report that the YYRULE is going to be reduced.  |
+ `------------------------------------------------*/
++# ifdef YYLTYPE_IS_DECLARED
++static void
++yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule)
++{
++  unsigned long int yylno = yyrline[yyrule];
++  int yynrhs = yyr2[yyrule];
++  int yyi;
++  YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
++             yyrule - 1, yylno);
++  /* The symbols being reduced.  */
++  for (yyi = 0; yyi < yynrhs; yyi++)
++    {
++      YYFPRINTF (stderr, "   $%d = ", yyi + 1);
++      yy_symbol_print (stderr,
++                       yystos[yyssp[yyi + 1 - yynrhs]],
++                       &(yyvsp[(yyi + 1) - (yynrhs)])
++                       , &(yylsp[(yyi + 1) - (yynrhs)])                       );
++      YYFPRINTF (stderr, "\n");
++    }
++}
++
++#  define YY_REDUCE_PRINT(Rule)         \
++do {                                    \
++  if (yydebug)                          \
++    yy_reduce_print (yyssp, yyvsp, yylsp, Rule); \
++} while (0)
++# else
+ static void
+ yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule)
+ {
+@@ -662,11 +681,12 @@
+     }
+ }
+-# define YY_REDUCE_PRINT(Rule)          \
++#  define YY_REDUCE_PRINT(Rule)         \
+ do {                                    \
+   if (yydebug)                          \
+     yy_reduce_print (yyssp, yyvsp, Rule); \
+ } while (0)
++# endif
+ /* Nonzero means print parse trace.  It is left uninitialized so that
+    multiple parsers can coexist.  */
+@@ -923,10 +943,12 @@
+ | Release the memory associated to this symbol.  |
+ `-----------------------------------------------*/
++#ifdef YYLTYPE_IS_DECLARED
+ static void
+-yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
++yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp)
+ {
+   YYUSE (yyvaluep);
++  YYUSE (yylocationp);
+   if (!yymsg)
+     yymsg = "Deleting";
+   YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
+@@ -935,18 +957,38 @@
+   YYUSE (yytype);
    YY_IGNORE_MAYBE_UNINITIALIZED_END
  }
++#else
++static void
++yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
++{
++  YYUSE (yyvaluep);
++  if (!yymsg)
++    yymsg = "Deleting";
++  YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
++  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
++  YYUSE (yytype);
++  YY_IGNORE_MAYBE_UNINITIALIZED_END
++}
++#endif
  
--
 -
 -
 +#if !YYPURE
  /* The lookahead symbol.  */
  int yychar;
  
-@@ -946,7 +789,7 @@
+ /* The semantic value of the lookahead symbol.  */
  YYSTYPE yylval;
++# ifdef YYLTYPE_IS_DECLARED
++/* Location data for the lookahead symbol.  */
++YYLTYPE yylloc
++#  if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
++  = { 1, 1, 1, 1 }
++#  endif
++;
++# endif
  /* Number of syntax errors so far.  */
  int yynerrs;
 -
  
  /*----------.
  | yyparse.  |
-@@ -955,6 +798,20 @@
+@@ -955,6 +997,27 @@
  int
  yyparse (void)
  {
 +       or non-GCC compilers.  */
 +    YY_INITIAL_VALUE (static YYSTYPE yyval_default;)
 +    YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);
-+
++# ifdef YYLTYPE_IS_DECLARED
++    /* Location data for the lookahead symbol.  */
++    YYLTYPE yylloc
++#  if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
++      = { 1, 1, 1, 1 }
++#  endif
++    ;
++# endif
 +    /* Number of syntax errors so far.  */
 +    int yynerrs;
 +#endif
      int yystate;
      /* Number of tokens to shift before error messages enabled.  */
      int yyerrstatus;
-@@ -1109,7 +966,11 @@
+@@ -962,6 +1025,7 @@
+     /* The stacks and their tools:
+        'yyss': related to states.
+        'yyvs': related to semantic values.
++       'yyls': related to locations.
+        Refer to the stacks through separate pointers, to allow yyoverflow
+        to reallocate them elsewhere.  */
+@@ -976,6 +1040,16 @@
+     YYSTYPE *yyvs;
+     YYSTYPE *yyvsp;
++#ifdef YYLTYPE_IS_DECLARED
++    /* The location stack.  */
++    YYLTYPE yylsa[YYINITDEPTH];
++    YYLTYPE *yyls;
++    YYLTYPE *yylsp;
++
++    /* The locations where the error started and ended.  */
++    YYLTYPE yyerror_range[3];
++#endif
++ 
+     YYSIZE_T yystacksize;
+   int yyn;
+@@ -985,6 +1059,9 @@
+   /* The variables used to return semantic value and location from the
+      action routines.  */
+   YYSTYPE yyval;
++#ifdef YYLTYPE_IS_DECLARED
++  YYLTYPE yyloc;
++#endif
+ #if YYERROR_VERBOSE
+   /* Buffer for error messages, and its allocated size.  */
+@@ -993,7 +1070,11 @@
+   YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
+ #endif
+-#define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))
++#ifdef YYLTYPE_IS_DECLARED
++# define YYPOPSTACK(N)  (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
++#else
++# define YYPOPSTACK(N)  (yyvsp -= (N), yyssp -= (N))
++#endif
+   /* The number of symbols on the RHS of the reduced rule.
+      Keep to zero when no symbol should be popped.  */
+@@ -1001,6 +1082,9 @@
+   yyssp = yyss = yyssa;
+   yyvsp = yyvs = yyvsa;
++#ifdef YYLTYPE_IS_DECLARED
++  yylsp = yyls = yylsa;
++#endif 
+   yystacksize = YYINITDEPTH;
+   YYDPRINTF ((stderr, "Starting parse\n"));
+@@ -1075,6 +1159,9 @@
+       yyssp = yyss + yysize - 1;
+       yyvsp = yyvs + yysize - 1;
++#ifdef YYLTYPE_IS_DECLARED
++      yylsp = yyls + yysize - 1;
++#endif
+       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
+                   (unsigned long int) yystacksize));
+@@ -1109,7 +1196,15 @@
    if (yychar == YYEMPTY)
      {
        YYDPRINTF ((stderr, "Reading a token: "));
 +#if YYPURE
++# ifdef YYLTYPE_IS_DECLARED
++      yychar = yylex (&yylval, &yylloc);
++# else
 +      yychar = yylex (&yylval);
++# endif
 +#else
        yychar = yylex ();
 +#endif
      }
  
    if (yychar <= YYEOF)
-@@ -1187,14 +1048,7 @@
+@@ -1152,7 +1247,9 @@
+   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+   *++yyvsp = yylval;
+   YY_IGNORE_MAYBE_UNINITIALIZED_END
+-
++#ifdef YYLTYPE_IS_DECLARED
++  *++yylsp = yylloc;
++#endif
+   goto yynewstate;
+@@ -1183,18 +1280,14 @@
+      GCC warning that YYVAL may be used uninitialized.  */
+   yyval = yyvsp[1-yylen];
+-
++#ifdef YYLTYPE_IS_DECLARED
++  /* Default location.  */
++  YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
++#endif
    YY_REDUCE_PRINT (yyn);
    switch (yyn)
      {
  
        default: break;
      }
-@@ -1423,3 +1277,5 @@
+@@ -1216,6 +1309,9 @@
+   YY_STACK_PRINT (yyss, yyssp);
+   *++yyvsp = yyval;
++#ifdef YYLTYPE_IS_DECLARED
++  *++yylsp = yyloc;
++#endif
+   /* Now 'shift' the result of the reduction.  Determine what state
+      that goes to, based on the state we popped back to and the rule
+@@ -1245,7 +1341,11 @@
+     {
+       ++yynerrs;
+ #if ! YYERROR_VERBOSE
++# if YYPURE >= 2 && defined YYLTYPE_IS_DECLARED
++      yyerror (&yylloc, YY_("syntax error"));
++# else
+       yyerror (YY_("syntax error"));
++# endif
+ #else
+ # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
+                                         yyssp, yytoken)
+@@ -1272,7 +1372,11 @@
+                 yymsgp = yymsg;
+               }
+           }
++#if YYPURE >= 2 && defined YYLTYPE_IS_DECLARED
++        yyerror (&yylloc, yymsgp);
++#else
+         yyerror (yymsgp);
++#endif
+         if (yysyntax_error_status == 2)
+           goto yyexhaustedlab;
+       }
+@@ -1280,7 +1384,9 @@
+ #endif
+     }
+-
++#ifdef YYLTYPE_IS_DECLARED
++  yyerror_range[1] = yylloc;
++#endif
+   if (yyerrstatus == 3)
+     {
+@@ -1295,8 +1401,13 @@
+         }
+       else
+         {
++#ifdef YYLTYPE_IS_DECLARED
++          yydestruct ("Error: discarding",
++                      yytoken, &yylval, &yylloc);
++#else
+           yydestruct ("Error: discarding",
+                       yytoken, &yylval);
++#endif
+           yychar = YYEMPTY;
+         }
+     }
+@@ -1317,6 +1428,9 @@
+   if (/*CONSTCOND*/ 0)
+      goto yyerrorlab;
++#ifdef YYLTYPE_IS_DECLARED
++  yyerror_range[1] = yylsp[1-yylen];
++#endif 
+   /* Do not reclaim the symbols of the rule whose action triggered
+      this YYERROR.  */
+   YYPOPSTACK (yylen);
+@@ -1350,9 +1464,14 @@
+       if (yyssp == yyss)
+         YYABORT;
+-
++#ifdef YYLTYPE_IS_DECLARED
++      yyerror_range[1] = *yylsp;
++      yydestruct ("Error: popping",
++                  yystos[yystate], yyvsp, yylsp);
++#else
+       yydestruct ("Error: popping",
+                   yystos[yystate], yyvsp);
++#endif
+       YYPOPSTACK (1);
+       yystate = *yyssp;
+       YY_STACK_PRINT (yyss, yyssp);
+@@ -1362,6 +1481,13 @@
+   *++yyvsp = yylval;
+   YY_IGNORE_MAYBE_UNINITIALIZED_END
++#ifdef YYLTYPE_IS_DECLARED
++  yyerror_range[2] = yylloc;
++  /* Using YYLLOC is tempting, but would change the location of
++     the lookahead.  YYLOC is available though.  */
++  YYLLOC_DEFAULT (yyloc, yyerror_range, 2);
++  *++yylsp = yyloc;
++#endif
+   /* Shift the error token.  */
+   YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
+@@ -1389,7 +1515,11 @@
+ | yyexhaustedlab -- memory exhaustion comes here.  |
+ `-------------------------------------------------*/
+ yyexhaustedlab:
++#if YYPURE >= 2 && defined YYLTYPE_IS_DECLARED
++  yyerror (&yylloc, YY_("memory exhausted"));
++#else
+   yyerror (YY_("memory exhausted"));
++#endif
+   yyresult = 2;
+   /* Fall through.  */
+ #endif
+@@ -1400,8 +1530,13 @@
+       /* Make sure we have latest lookahead translation.  See comments at
+          user semantic actions for why this is necessary.  */
+       yytoken = YYTRANSLATE (yychar);
++#ifdef YYLTYPE_IS_DECLARED
++      yydestruct ("Cleanup: discarding lookahead",
++                  yytoken, &yylval, &yylloc);
++#else
+       yydestruct ("Cleanup: discarding lookahead",
+                   yytoken, &yylval);
++#endif
+     }
+   /* Do not reclaim the symbols of the rule whose action triggered
+      this YYABORT or YYACCEPT.  */
+@@ -1409,8 +1544,13 @@
+   YY_STACK_PRINT (yyss, yyssp);
+   while (yyssp != yyss)
+     {
++#ifdef YYLTYPE_IS_DECLARED
++      yydestruct ("Cleanup: popping",
++                  yystos[*yyssp], yyvsp, yylsp);
++#else
+       yydestruct ("Cleanup: popping",
+                   yystos[*yyssp], yyvsp);
++#endif
+       YYPOPSTACK (1);
+     }
+ #ifndef yyoverflow
+@@ -1423,3 +1563,5 @@
  #endif
    return yyresult;
  }