Egregious hacks, and fix a genuine bug in the #ifdef YYLTYPE_IS_DECLARED stuff
authorNick Downing <downing.nick@gmail.com>
Sun, 29 Jul 2018 11:54:58 +0000 (21:54 +1000)
committerNick Downing <downing.nick@gmail.com>
Sun, 29 Jul 2018 11:54:58 +0000 (21:54 +1000)
bison_lr1dfa.py
skel/y.tab.c.patch
skel/y.tab.h.patch

index a7b0477..1f98d6a 100644 (file)
@@ -332,7 +332,14 @@ def generate(pyacc, skel_file, out_file, defines_file = None):
     translate_nonterminals
   )
 
-  def generate(skel_file, out_file):
+  def generate(
+    skel_file,
+    out_file,
+    file_prefix,
+    type_prefix,
+    name_prefix,
+    is_header
+  ):
     with open(skel_file, 'r') as fin:
       with open(out_file, 'w+') as fout:
         line = fin.readline()
@@ -344,7 +351,7 @@ def generate(pyacc, skel_file, out_file, defines_file = None):
 /* GENERATE YYPURE END */
 '''.format(
                 pyacc[0].api_pure
-              )
+              ).replace('YY', type_prefix if is_header else 'YY').replace('yy', name_prefix if is_header else 'yy') # hack
             )
           elif line == '/* GENERATE TYPEPREFIX */\n':
             fout.write(
@@ -407,7 +414,12 @@ def generate(pyacc, skel_file, out_file, defines_file = None):
               '''/* GENERATE SECTION1TOP BEGIN */
 {0:s}/* GENERATE SECTION1TOP END */
 '''.format(
-                ''.join([i.get_text() for i in pyacc.top_code])
+                ''.join(
+                  [
+                    '{0:s}\n'.format(i.get_text()[1:-1])
+                    for i in pyacc.top_code
+                  ]
+                )
               )
             )
           elif line == '/* GENERATE SECTION1BEFOREUNION */\n':
@@ -415,7 +427,12 @@ def generate(pyacc, skel_file, out_file, defines_file = None):
               '''/* GENERATE SECTION1BEFOREUNION BEGIN */
 {0:s}/* GENERATE SECTION1BEFOREUNION END */
 '''.format(
-                ''.join([i.get_text() for i in pyacc.before_union_code])
+                ''.join(
+                  [
+                    '{0:s}\n'.format(i.get_text()[1:-1])
+                    for i in pyacc.before_union_code
+                  ]
+                )
               )
             )
           elif line == '/* GENERATE YYERROR_VERBOSE */\n':
@@ -437,7 +454,12 @@ def generate(pyacc, skel_file, out_file, defines_file = None):
               '''/* GENERATE SECTION1REQUIRES BEGIN */
 {0:s}/* GENERATE SECTION1REQUIRES END */
 '''.format(
-                ''.join([i.get_text() for i in pyacc.requires_code])
+                ''.join(
+                  [
+                    '{0:s}\n'.format(i.get_text()[1:-1])
+                    for i in pyacc.requires_code
+                  ]
+                )
               )
             )
           elif line == '/* GENERATE YYDEBUG */\n':
@@ -446,10 +468,13 @@ def generate(pyacc, skel_file, out_file, defines_file = None):
 #ifndef YYDEBUG
 # define YYDEBUG {0:d}
 #endif
+#if YYDEBUG
+extern int yydebug;
+#endif
 /* GENERATE YYDEBUG END */
 '''.format(
                 int(pyacc[0].debug)
-              )
+              ).replace('YY', type_prefix).replace('yy', name_prefix) # hack
             )
           elif line == '/* GENERATE TOKENSEQUAL */\n':
             fout.write(
@@ -495,15 +520,21 @@ def generate(pyacc, skel_file, out_file, defines_file = None):
 /* GENERATE YYSTYPE END */
 '''.format(
                   '''union YYSTYPE
-{0:s};
+{{
+{0:s}}};
 typedef union YYSTYPE YYSTYPE;
 '''.format(
-                    ''.join([i.get_text() for i in pyacc.union_code])
+                    ''.join(
+                      [
+                        '{0:s}\n'.format(i.get_text()[1:-1])
+                        for i in pyacc.union_code
+                      ]
+                    )
                   )
                 if len(pyacc.union_code) else
                   '''typedef int YYSTYPE;
 '''
-              )
+              ).replace('YY', type_prefix).replace('yy', name_prefix) # hack
             )
           elif line == '/* GENERATE YYLTYPE */\n':
             fout.write(
@@ -525,14 +556,19 @@ struct YYLTYPE
 '''
                 if pyacc[0].locations else
                   ''
-              )
+              ).replace('YY', type_prefix).replace('yy', name_prefix) # hack
             )
           elif line == '/* GENERATE SECTION1AFTERUNION */\n':
             fout.write(
               '''/* GENERATE SECTION1AFTERUNION BEGIN */
 {0:s}/* GENERATE SECTION1AFTERUNION END */
 '''.format(
-                ''.join([i.get_text() for i in pyacc.after_union_code])
+                ''.join(
+                  [
+                    '{0:s}\n'.format(i.get_text()[1:-1])
+                    for i in pyacc.after_union_code
+                  ]
+                )
               )
             )
           elif line == '/* GENERATE TABLES */\n':
@@ -891,7 +927,7 @@ static const yytype_int16 yyr2[] =
                     for i in range(0, bison_lr1dfa.rules.shape[0], 10)
                   ]
                 )
-              )
+              ).replace('YYDEBUG', type_prefix + 'DEBUG') # hack
             )
           elif line == '/* GENERATE SECTION2INITIAL */\n':
             fout.write(
@@ -930,13 +966,35 @@ static const yytype_int16 yyr2[] =
               )
             )
           else:
+            if file_prefix != 'YY_YY_Y_':
+              line = line.replace('YY_YY_Y_', file_prefix)
+            if is_header:
+              if type_prefix != 'YY':
+                line = line.replace('YY_YY_Y_', 'YY').replace('YY', type_prefix)
+              if name_prefix != 'yy':
+                line = line.replace('yy', name_prefix)
+            elif type_prefix != 'YY':
+              line = line.replace('YYDEBUG', type_prefix + 'DEBUG')
+              line = line.replace('YYSTYPE_IS_', type_prefix + 'STYPE_IS_')
+              line = line.replace('YYLTYPE_IS_', type_prefix + 'LTYPE_IS_')
             fout.write(line)
           line = fin.readline()
-  generate(skel_file, out_file)
+  generate(
+    skel_file,
+    out_file,
+    pyacc[0].type_prefix,
+    pyacc[0].type_prefix,
+    pyacc[0].name_prefix,
+    False
+  )
   if defines_file is not None:
     generate(
       '{0:s}.h'.format(
         skel_file[:-2] if skel_file[-2:] == '.c' else skel_file
       ),
-      defines_file
+      defines_file,
+      pyacc[0].type_prefix,
+      pyacc[0].type_prefix,
+      pyacc[0].name_prefix,
+      True
     )
index 57368cb..d3600dc 100644 (file)
@@ -1,5 +1,5 @@
---- y.tab.c.orig       2018-07-29 20:02:05.723756386 +1000
-+++ y.tab.c    2018-07-29 20:32:07.283803932 +1000
+--- y.tab.c.orig       2018-07-29 21:31:56.731898662 +1000
++++ y.tab.c    2018-07-29 21:34:16.699902356 +1000
 @@ -50,7 +50,7 @@
  #define YYSKELETON_NAME "yacc.c"
  
@@ -25,7 +25,7 @@
  
  # ifndef YY_NULLPTR
  #  if defined __cplusplus && 201103L <= __cplusplus
-@@ -73,21 +77,14 @@
+@@ -73,52 +77,40 @@
  # endif
  
  /* Enabling verbose error messages.  */
 -#ifndef YYDEBUG
 -# define YYDEBUG 0
 -#endif
+-#if YYDEBUG
+-extern int yydebug;
+-#endif
 +/* GENERATE YYDEBUG */
- #if YYDEBUG
- extern int yydebug;
- #endif
-@@ -97,28 +94,26 @@
+ /* Token type.  */
+ #ifndef YYTOKENTYPE
  # define YYTOKENTYPE
    enum yytokentype
    {
 -
 -/* Value type.  */
 -#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
--
++/* GENERATE TOKENS */
 -union YYSTYPE
 -{
 - /* something */ 
-+/* GENERATE TOKENS */
+-
 -};
 +/* GENERATE SECTION1REQUIRES */
  
  
 +#if !YYPURE
  extern YYSTYPE yylval;
-+# ifdef YYLTYPE_IS_DECLARED
++# if defined YYLTYPE || defined YYLTYPE_IS_DECLARED
 +extern YYLTYPE yylloc;
 +# endif
 +#endif
  
  int yyparse (void);
  
-@@ -126,6 +121,7 @@
+@@ -126,6 +118,7 @@
  
  /* Copy the second part of user declarations.  */
  
  
  #ifdef short
  # undef short
-@@ -306,13 +302,20 @@
+@@ -306,13 +299,20 @@
  
  #if (! defined yyoverflow \
       && (! defined __cplusplus \
 -         || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
-+         || (!defined YYLTYPE_IS_DECLARED \
++         || (!(defined YYLTYPE || defined YYLTYPE_IS_DECLARED) \
 +             && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL) \
-+         || (defined YYLTYPE_IS_DECLARED \
++         || ((defined YYLTYPE || defined YYLTYPE_IS_DECLARED) \
 +             && defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
 +             && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
  
  {
    yytype_int16 yyss_alloc;
    YYSTYPE yyvs_alloc;
-+# ifdef YYLTYPE_IS_DECLARED
++# if defined YYLTYPE || defined YYLTYPE_IS_DECLARED
 +  YYLTYPE yyls_alloc;
 +# endif
  };
  
  /* The size of the maximum gap between one aligned stack and the next.  */
-@@ -320,9 +323,15 @@
+@@ -320,9 +320,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
++# if defined YYLTYPE || defined YYLTYPE_IS_DECLARED
 +#  define YYSTACK_BYTES(N) \
 +     ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
 +      + 2 * YYSTACK_GAP_MAXIMUM)
  
  # define YYCOPY_NEEDED 1
  
-@@ -364,155 +373,7 @@
+@@ -364,155 +370,7 @@
  # endif
  #endif /* !YYCOPY_NEEDED */
  
  
  #define yyerrok         (yyerrstatus = 0)
  #define yyclearin       (yychar = YYEMPTY)
-@@ -526,7 +387,25 @@
+@@ -526,7 +384,25 @@
  
  #define YYRECOVERING()  (!!yyerrstatus)
  
 -#define YYBACKUP(Token, Value)                                  \
-+#if YYPURE >= 2 && defined YYLTYPE_IS_DECLARED
++#if YYPURE >= 2 && (defined YYLTYPE || defined YYLTYPE_IS_DECLARED)
 +# define YYBACKUP(Token, Value)                                 \
 +do                                                              \
 +  if (yychar == YYEMPTY)                                        \
  do                                                              \
    if (yychar == YYEMPTY)                                        \
      {                                                           \
-@@ -542,12 +421,39 @@
+@@ -542,12 +418,39 @@
        YYERROR;                                                  \
      }                                                           \
  while (0)
  #define YYTERROR        1
  #define YYERRCODE       256
  
-+#ifdef YYLTYPE_IS_DECLARED
++#if defined YYLTYPE || defined 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                                                                  \
 +        }                                                               \
 +    while (0)
 +# endif
++
 +# define YYRHSLOC(Rhs, K) ((Rhs)[K])
 +#endif
  
  /* Enable debugging if requested.  */
  #if YYDEBUG
-@@ -563,13 +469,64 @@
+@@ -563,13 +466,64 @@
      YYFPRINTF Args;                             \
  } while (0)
  
  #ifndef YY_LOCATION_PRINT
 -# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
 -#endif
-+# if defined YYLTYPE_IS_DECLARED \
++# if (defined YYLTYPE || defined YYLTYPE_IS_DECLARED) \
 +     && defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
 +
 +/* Print *YYLOCP on YYO.  Private, do not rely on its existence. */
 +# endif
 +#endif
 +
-+# ifdef YYLTYPE_IS_DECLARED
++# if defined YYLTYPE || defined YYLTYPE_IS_DECLARED
 +#  define YY_SYMBOL_PRINT(Title, Type, Value, Location)                   \
 +do {                                                                      \
 +  if (yydebug)                                                            \
  do {                                                                      \
    if (yydebug)                                                            \
      {                                                                     \
-@@ -579,12 +536,29 @@
+@@ -579,12 +533,29 @@
        YYFPRINTF (stderr, "\n");                                           \
      }                                                                     \
  } while (0)
  | Print this symbol's value on YYOUTPUT.  |
  `----------------------------------------*/
  
-+# ifdef YYLTYPE_IS_DECLARED
++# if defined YYLTYPE || defined YYLTYPE_IS_DECLARED
 +static void
 +yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
 +{
  static void
  yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
  {
-@@ -592,18 +566,32 @@
+@@ -592,18 +563,32 @@
    YYUSE (yyo);
    if (!yyvaluep)
      return;
  | Print this symbol on YYOUTPUT.  |
  `--------------------------------*/
  
-+# ifdef YYLTYPE_IS_DECLARED
++# if defined YYLTYPE || defined YYLTYPE_IS_DECLARED
 +static void
 +yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
 +{
  static void
  yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
  {
-@@ -613,6 +601,7 @@
+@@ -613,6 +598,7 @@
    yy_symbol_value_print (yyoutput, yytype, yyvaluep);
    YYFPRINTF (yyoutput, ")");
  }
  
  /*------------------------------------------------------------------.
  | yy_stack_print -- Print the state stack from its BOTTOM up to its |
-@@ -642,6 +631,33 @@
+@@ -642,6 +628,33 @@
  | Report that the YYRULE is going to be reduced.  |
  `------------------------------------------------*/
  
-+# ifdef YYLTYPE_IS_DECLARED
++# if defined YYLTYPE || defined YYLTYPE_IS_DECLARED
 +static void
 +yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule)
 +{
  static void
  yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule)
  {
-@@ -662,11 +678,12 @@
+@@ -662,11 +675,12 @@
      }
  }
  
  
  /* Nonzero means print parse trace.  It is left uninitialized so that
     multiple parsers can coexist.  */
-@@ -923,10 +940,12 @@
+@@ -923,10 +937,12 @@
  | Release the memory associated to this symbol.  |
  `-----------------------------------------------*/
  
-+#ifdef YYLTYPE_IS_DECLARED
++#if defined YYLTYPE || defined YYLTYPE_IS_DECLARED
  static void
 -yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
 +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp)
    if (!yymsg)
      yymsg = "Deleting";
    YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
-@@ -935,18 +954,38 @@
+@@ -935,18 +951,38 @@
    YYUSE (yytype);
    YY_IGNORE_MAYBE_UNINITIALIZED_END
  }
  
  /* The semantic value of the lookahead symbol.  */
  YYSTYPE yylval;
-+# ifdef YYLTYPE_IS_DECLARED
++# if defined YYLTYPE || defined YYLTYPE_IS_DECLARED
 +/* Location data for the lookahead symbol.  */
 +YYLTYPE yylloc
 +#  if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
  
  /*----------.
  | yyparse.  |
-@@ -955,6 +994,27 @@
+@@ -955,6 +991,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
++# if defined YYLTYPE || defined YYLTYPE_IS_DECLARED
 +    /* Location data for the lookahead symbol.  */
 +    YYLTYPE yylloc
 +#  if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
      int yystate;
      /* Number of tokens to shift before error messages enabled.  */
      int yyerrstatus;
-@@ -962,6 +1022,7 @@
+@@ -962,6 +1019,7 @@
      /* The stacks and their tools:
         'yyss': related to states.
         'yyvs': related to semantic values.
  
         Refer to the stacks through separate pointers, to allow yyoverflow
         to reallocate them elsewhere.  */
-@@ -976,6 +1037,16 @@
+@@ -976,6 +1034,16 @@
      YYSTYPE *yyvs;
      YYSTYPE *yyvsp;
  
-+#ifdef YYLTYPE_IS_DECLARED
++#if defined YYLTYPE || defined YYLTYPE_IS_DECLARED
 +    /* The location stack.  */
 +    YYLTYPE yylsa[YYINITDEPTH];
 +    YYLTYPE *yyls;
      YYSIZE_T yystacksize;
  
    int yyn;
-@@ -985,6 +1056,9 @@
+@@ -985,6 +1053,9 @@
    /* The variables used to return semantic value and location from the
       action routines.  */
    YYSTYPE yyval;
-+#ifdef YYLTYPE_IS_DECLARED
++#if defined YYLTYPE || defined YYLTYPE_IS_DECLARED
 +  YYLTYPE yyloc;
 +#endif
  
  #if YYERROR_VERBOSE
    /* Buffer for error messages, and its allocated size.  */
-@@ -993,7 +1067,11 @@
+@@ -993,7 +1064,11 @@
    YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
  #endif
  
 -#define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))
-+#ifdef YYLTYPE_IS_DECLARED
++#if defined YYLTYPE || defined YYLTYPE_IS_DECLARED
 +# define YYPOPSTACK(N)  (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
 +#else
 +# define YYPOPSTACK(N)  (yyvsp -= (N), yyssp -= (N))
  
    /* The number of symbols on the RHS of the reduced rule.
       Keep to zero when no symbol should be popped.  */
-@@ -1001,6 +1079,9 @@
+@@ -1001,6 +1076,9 @@
  
    yyssp = yyss = yyssa;
    yyvsp = yyvs = yyvsa;
-+#ifdef YYLTYPE_IS_DECLARED
++#if defined YYLTYPE || defined YYLTYPE_IS_DECLARED
 +  yylsp = yyls = yylsa;
 +#endif 
    yystacksize = YYINITDEPTH;
  
    YYDPRINTF ((stderr, "Starting parse\n"));
-@@ -1075,6 +1156,9 @@
+@@ -1075,6 +1153,9 @@
  
        yyssp = yyss + yysize - 1;
        yyvsp = yyvs + yysize - 1;
-+#ifdef YYLTYPE_IS_DECLARED
++#if defined YYLTYPE || defined YYLTYPE_IS_DECLARED
 +      yylsp = yyls + yysize - 1;
 +#endif
  
        YYDPRINTF ((stderr, "Stack size increased to %lu\n",
                    (unsigned long int) yystacksize));
-@@ -1109,7 +1193,15 @@
+@@ -1109,7 +1190,15 @@
    if (yychar == YYEMPTY)
      {
        YYDPRINTF ((stderr, "Reading a token: "));
 +#if YYPURE
-+# ifdef YYLTYPE_IS_DECLARED
++# if defined YYLTYPE || defined YYLTYPE_IS_DECLARED
 +      yychar = yylex (&yylval, &yylloc);
 +# else
 +      yychar = yylex (&yylval);
      }
  
    if (yychar <= YYEOF)
-@@ -1152,7 +1244,9 @@
+@@ -1152,7 +1241,9 @@
    YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
    *++yyvsp = yylval;
    YY_IGNORE_MAYBE_UNINITIALIZED_END
 -
-+#ifdef YYLTYPE_IS_DECLARED
++#if defined YYLTYPE || defined YYLTYPE_IS_DECLARED
 +  *++yylsp = yylloc;
 +#endif
    goto yynewstate;
  
  
-@@ -1183,18 +1277,14 @@
+@@ -1183,18 +1274,14 @@
       GCC warning that YYVAL may be used uninitialized.  */
    yyval = yyvsp[1-yylen];
  
 -
-+#ifdef YYLTYPE_IS_DECLARED
++#if defined YYLTYPE || defined YYLTYPE_IS_DECLARED
 +  /* Default location.  */
 +  YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
 +#endif
  
        default: break;
      }
-@@ -1216,6 +1306,9 @@
+@@ -1216,6 +1303,9 @@
    YY_STACK_PRINT (yyss, yyssp);
  
    *++yyvsp = yyval;
-+#ifdef YYLTYPE_IS_DECLARED
++#if defined YYLTYPE || defined 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 +1338,11 @@
+@@ -1245,7 +1335,11 @@
      {
        ++yynerrs;
  #if ! YYERROR_VERBOSE
-+# if YYPURE >= 2 && defined YYLTYPE_IS_DECLARED
++# if YYPURE >= 2 && (defined YYLTYPE || defined YYLTYPE_IS_DECLARED)
 +      yyerror (&yylloc, YY_("syntax error"));
 +# else
        yyerror (YY_("syntax error"));
  #else
  # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
                                          yyssp, yytoken)
-@@ -1272,7 +1369,11 @@
+@@ -1272,7 +1366,11 @@
                  yymsgp = yymsg;
                }
            }
-+#if YYPURE >= 2 && defined YYLTYPE_IS_DECLARED
++#if YYPURE >= 2 && (defined YYLTYPE || defined YYLTYPE_IS_DECLARED)
 +        yyerror (&yylloc, yymsgp);
 +#else
          yyerror (yymsgp);
          if (yysyntax_error_status == 2)
            goto yyexhaustedlab;
        }
-@@ -1280,7 +1381,9 @@
+@@ -1280,7 +1378,9 @@
  #endif
      }
  
 -
-+#ifdef YYLTYPE_IS_DECLARED
++#if defined YYLTYPE || defined YYLTYPE_IS_DECLARED
 +  yyerror_range[1] = yylloc;
 +#endif
  
    if (yyerrstatus == 3)
      {
-@@ -1295,8 +1398,13 @@
+@@ -1295,8 +1395,13 @@
          }
        else
          {
-+#ifdef YYLTYPE_IS_DECLARED
++#if defined YYLTYPE || defined YYLTYPE_IS_DECLARED
 +          yydestruct ("Error: discarding",
 +                      yytoken, &yylval, &yylloc);
 +#else
            yychar = YYEMPTY;
          }
      }
-@@ -1317,6 +1425,9 @@
+@@ -1317,6 +1422,9 @@
    if (/*CONSTCOND*/ 0)
       goto yyerrorlab;
  
-+#ifdef YYLTYPE_IS_DECLARED
++#if defined YYLTYPE || defined 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 +1461,14 @@
+@@ -1350,9 +1458,14 @@
        if (yyssp == yyss)
          YYABORT;
  
 -
-+#ifdef YYLTYPE_IS_DECLARED
++#if defined YYLTYPE || defined YYLTYPE_IS_DECLARED
 +      yyerror_range[1] = *yylsp;
 +      yydestruct ("Error: popping",
 +                  yystos[yystate], yyvsp, yylsp);
        YYPOPSTACK (1);
        yystate = *yyssp;
        YY_STACK_PRINT (yyss, yyssp);
-@@ -1362,6 +1478,13 @@
+@@ -1362,6 +1475,13 @@
    *++yyvsp = yylval;
    YY_IGNORE_MAYBE_UNINITIALIZED_END
  
-+#ifdef YYLTYPE_IS_DECLARED
++#if defined YYLTYPE || defined YYLTYPE_IS_DECLARED
 +  yyerror_range[2] = yylloc;
 +  /* Using YYLLOC is tempting, but would change the location of
 +     the lookahead.  YYLOC is available though.  */
  
    /* Shift the error token.  */
    YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
-@@ -1389,7 +1512,11 @@
+@@ -1389,7 +1509,11 @@
  | yyexhaustedlab -- memory exhaustion comes here.  |
  `-------------------------------------------------*/
  yyexhaustedlab:
-+#if YYPURE >= 2 && defined YYLTYPE_IS_DECLARED
++#if YYPURE >= 2 && (defined YYLTYPE || defined YYLTYPE_IS_DECLARED)
 +  yyerror (&yylloc, YY_("memory exhausted"));
 +#else
    yyerror (YY_("memory exhausted"));
    yyresult = 2;
    /* Fall through.  */
  #endif
-@@ -1400,8 +1527,13 @@
+@@ -1400,8 +1524,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
++#if defined YYLTYPE || defined YYLTYPE_IS_DECLARED
 +      yydestruct ("Cleanup: discarding lookahead",
 +                  yytoken, &yylval, &yylloc);
 +#else
      }
    /* Do not reclaim the symbols of the rule whose action triggered
       this YYABORT or YYACCEPT.  */
-@@ -1409,8 +1541,13 @@
+@@ -1409,8 +1538,13 @@
    YY_STACK_PRINT (yyss, yyssp);
    while (yyssp != yyss)
      {
-+#ifdef YYLTYPE_IS_DECLARED
++#if defined YYLTYPE || defined YYLTYPE_IS_DECLARED
 +      yydestruct ("Cleanup: popping",
 +                  yystos[*yyssp], yyvsp, yylsp);
 +#else
        YYPOPSTACK (1);
      }
  #ifndef yyoverflow
-@@ -1423,3 +1560,5 @@
+@@ -1423,3 +1557,5 @@
  #endif
    return yyresult;
  }
index bbb28bb..cdd20f1 100644 (file)
@@ -1,17 +1,19 @@
---- y.tab.h.orig       2018-07-29 19:39:22.199720400 +1000
-+++ y.tab.h    2018-07-29 19:40:18.731721892 +1000
-@@ -33,9 +33,7 @@
+--- y.tab.h.orig       2018-07-29 21:31:56.747898663 +1000
++++ y.tab.h    2018-07-29 21:34:24.931902574 +1000
+@@ -33,40 +33,36 @@
  #ifndef YY_YY_Y_TAB_H_INCLUDED
  # define YY_YY_Y_TAB_H_INCLUDED
  /* Debug traces.  */
 -#ifndef YYDEBUG
 -# define YYDEBUG 0
 -#endif
+-#if YYDEBUG
+-extern int yydebug;
+-#endif
 +/* GENERATE YYDEBUG */
- #if YYDEBUG
- extern int yydebug;
- #endif
-@@ -45,26 +43,16 @@
+ /* Token type.  */
+ #ifndef YYTOKENTYPE
  # define YYTOKENTYPE
    enum yytokentype
    {
 -
 -/* Value type.  */
 -#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
--
++/* GENERATE TOKENS */
 -union YYSTYPE
 -{
 - /* something */ 
-+/* GENERATE TOKENS */
++/* GENERATE SECTION1REQUIRES */
  
 -};
--
++/* Value type.  */
++/* GENERATE YYSTYPE */
 -typedef union YYSTYPE YYSTYPE;
 -# define YYSTYPE_IS_TRIVIAL 1
 -# define YYSTYPE_IS_DECLARED 1
 -#endif
-+/* GENERATE SECTION1REQUIRES */
++/* Location type.  */
++/* GENERATE YYLTYPE */
  
-+/* Value type.  */
-+/* GENERATE YYSTYPE */
++/* we shouldn't really be generating YYPURE here, fix this later! */
++/* GENERATE YYPURE */
  
++#if !YYPURE
  extern YYSTYPE yylval;
++# if defined YYLTYPE || defined YYLTYPE_IS_DECLARED
++extern YYLTYPE yylloc;
++# endif
++#endif
+ int yyparse (void);