Fix missing #defines for tokens bug in y.tab.h, generate YYSTYPE not just union
authorNick Downing <downing.nick@gmail.com>
Sun, 29 Jul 2018 07:22:02 +0000 (17:22 +1000)
committerNick Downing <downing.nick@gmail.com>
Sun, 29 Jul 2018 09:06:14 +0000 (19:06 +1000)
bison_lr1dfa.py
skel/Makefile
skel/y.tab.c.patch
skel/y.tab.h.patch

index 0c01235..6cc4712 100644 (file)
@@ -404,21 +404,25 @@ def generate(pyacc, skel_file, out_file, defines_file = None):
                 )
               )
             )
-          elif line == '/* GENERATE UNION */\n':
+          elif line == '/* GENERATE YYSTYPE */\n':
             fout.write(
-                '''/* GENERATE UNION BEGIN */
-typedef int YYSTYPE;
-/* GENERATE UNION END */
-'''
-              if len(pyacc.union_code) == 0 else
-                '''/* GENERATE UNION BEGIN */
-union YYSTYPE
+              '''/* GENERATE YYSTYPE BEGIN */
+#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
+{0:s}# define YYSTYPE_IS_TRIVIAL 1
+# define YYSTYPE_IS_DECLARED 1
+#endif
+/* GENERATE YYSTYPE END */
+'''.format(
+                  '''union YYSTYPE
 {0:s};
 typedef union YYSTYPE YYSTYPE;
-/* GENERATE UNION END */
 '''.format(
-                  ''.join([i.get_text() for i in pyacc.union_code])
-                )
+                    ''.join([i.get_text() for i in pyacc.union_code])
+                  )
+                if len(pyacc.union_code) else
+                  '''typedef int YYSTYPE;
+'''
+              )
             )
           elif line == '/* GENERATE SECTION1AFTERUNION */\n':
             fout.write(
index 5791e6a..2d79b50 100644 (file)
@@ -3,5 +3,6 @@ y.tab.c: skel.y
        grep -v "^#line " <$@ >$@.orig
        cp $@.orig $@
        patch $@ <$@.patch
-       cp y.tab.h y.tab.h.orig
+       grep -v "^#line " <y.tab.h >y.tab.h.orig
+       cp y.tab.h.orig y.tab.h
        patch y.tab.h <y.tab.h.patch
index 8c424f8..ecdf758 100644 (file)
@@ -1,5 +1,5 @@
---- y.tab.c.orig       2018-07-29 17:18:39.855497595 +1000
-+++ y.tab.c    2018-07-29 17:18:53.715497961 +1000
+--- y.tab.c.orig       2018-07-29 17:10:01.955483927 +1000
++++ y.tab.c    2018-07-29 17:15:22.683492391 +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,24 @@
+@@ -97,28 +97,20 @@
  # define YYTOKENTYPE
    enum yytokentype
    {
  /* Tokens.  */
 -#define TOKEN 258
 +/* GENERATE TOKENS */
-+
-+/* GENERATE SECTION1REQUIRES */
  
- /* Value type.  */
- #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
+-/* Value type.  */
+-#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
 -
 -union YYSTYPE
 -{
 -};
 -
 -typedef union YYSTYPE YYSTYPE;
-+/* GENERATE UNION */
- # define YYSTYPE_IS_TRIVIAL 1
- # define YYSTYPE_IS_DECLARED 1
- #endif
+-# define YYSTYPE_IS_TRIVIAL 1
+-# define YYSTYPE_IS_DECLARED 1
+-#endif
++/* GENERATE SECTION1REQUIRES */
++/* Value type.  */
++/* GENERATE YYSTYPE */
  
--
 +#if !YYPURE
  extern YYSTYPE yylval;
 +#endif
  
  int yyparse (void);
  
-@@ -126,6 +122,7 @@
+@@ -126,6 +118,7 @@
  
  /* Copy the second part of user declarations.  */
  
@@ -67,7 +67,7 @@
  
  #ifdef short
  # undef short
-@@ -364,155 +361,7 @@
+@@ -364,155 +357,7 @@
  # endif
  #endif /* !YYCOPY_NEEDED */
  
  
  #define yyerrok         (yyerrstatus = 0)
  #define yyclearin       (yychar = YYEMPTY)
-@@ -936,9 +785,7 @@
+@@ -936,9 +781,7 @@
    YY_IGNORE_MAYBE_UNINITIALIZED_END
  }
  
  /* The lookahead symbol.  */
  int yychar;
  
-@@ -946,7 +793,7 @@
+@@ -946,7 +789,7 @@
  YYSTYPE yylval;
  /* Number of syntax errors so far.  */
  int yynerrs;
  
  /*----------.
  | yyparse.  |
-@@ -955,6 +802,20 @@
+@@ -955,6 +798,20 @@
  int
  yyparse (void)
  {
      int yystate;
      /* Number of tokens to shift before error messages enabled.  */
      int yyerrstatus;
-@@ -1109,7 +970,11 @@
+@@ -1109,7 +966,11 @@
    if (yychar == YYEMPTY)
      {
        YYDPRINTF ((stderr, "Reading a token: "));
      }
  
    if (yychar <= YYEOF)
-@@ -1187,14 +1052,7 @@
+@@ -1187,14 +1048,7 @@
    YY_REDUCE_PRINT (yyn);
    switch (yyn)
      {
  
        default: break;
      }
-@@ -1423,3 +1281,5 @@
+@@ -1423,3 +1277,5 @@
  #endif
    return yyresult;
  }
index ee0a7ca..f4078d4 100644 (file)
@@ -1,6 +1,6 @@
---- y.tab.h.orig       2018-07-26 21:54:50.166480531 +1000
-+++ y.tab.h    2018-07-26 21:55:18.658481768 +1000
-@@ -45,24 +45,17 @@
+--- y.tab.h.orig       2018-07-29 17:10:01.979483927 +1000
++++ y.tab.h    2018-07-29 17:16:30.311494176 +1000
+@@ -45,26 +45,16 @@
  # define YYTOKENTYPE
    enum yytokentype
    {
@@ -9,23 +9,26 @@
    };
  #endif
  /* Tokens.  */
- #define TOKEN 258
+-#define TOKEN 258
++/* GENERATE TOKENS */
  
-+/* GENERATE SECTION1REQUIRES */
-+
- /* Value type.  */
- #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
+-/* Value type.  */
+-#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
 -
 -union YYSTYPE
 -{
--#line 3 "skel.y" /* yacc.c:1910  */
 - /* something */ 
 -
--#line 63 "y.tab.h" /* yacc.c:1910  */
 -};
 -
 -typedef union YYSTYPE YYSTYPE;
-+/* GENERATE UNION */
- # define YYSTYPE_IS_TRIVIAL 1
- # define YYSTYPE_IS_DECLARED 1
- #endif
+-# define YYSTYPE_IS_TRIVIAL 1
+-# define YYSTYPE_IS_DECLARED 1
+-#endif
++/* GENERATE SECTION1REQUIRES */
++/* Value type.  */
++/* GENERATE YYSTYPE */
+ extern YYSTYPE yylval;