bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FYI: skeletons: factor yacc.c and glr.c (was: yacc.c does not prototype


From: Akim Demaille
Subject: FYI: skeletons: factor yacc.c and glr.c (was: yacc.c does not prototype yyparse in the header)
Date: Tue, 12 Jun 2012 16:02:54 +0200

Hi all,

Le 11 juin 2012 à 10:54, Akim Demaille a écrit :

> Bruce Korb just pointed out to me that Bison 2.5.1 does
> not prototype yyparse in the generated header, with yacc.c.
> The other skeletons do.  I don't understand why.  I see
> nothing in the documentation of Yacc that prevents this,
> and surely this is troublesome for many uses.

Again, instead of duplicating even more code in maint (to declare
yyparse in the generated header), I refactored bits of yacc.c and
glr.c.

From c0828abf9d81ce665d5dc9b5a2b2062e267d4114 Mon Sep 17 00:00:00 2001
From: Akim Demaille <address@hidden>
Date: Tue, 12 Jun 2012 10:55:18 +0200
Subject: [PATCH] skeletons: factor yacc.c and glr.c.

yacc.c and glr.c share common declarations.  Their YYLTYPE are exactly
equal, and their YYSTYPE are sufficiently alike to be fused (its
declaration was protected by YYSTYPE_IS_DECLARED in yacc.c, but not in
glr.c).  Besides, yacc.c duplicated the definitions of YYLTYPE and
YYSTYPE (*.h/*.c).

* data/c.m4 (b4_declare_yylstype): New.
* data/yacc.c, data/glr.c: Use it.
---
 data/c.m4   |   37 +++++++++++++++++++++++++
 data/glr.c  |   31 +++------------------
 data/yacc.c |   86 ++++++++++-------------------------------------------------
 3 files changed, 54 insertions(+), 100 deletions(-)

diff --git a/data/c.m4 b/data/c.m4
index b49d6dc..64f68fe 100644
--- a/data/c.m4
+++ b/data/c.m4
@@ -530,3 +530,40 @@ b4_locations_if([, yylocationp])[]b4_user_args[);
   YYFPRINTF (yyoutput, ")");
 }]dnl
 ])
+
+## -------------- ##
+## Declarations.  ##
+## -------------- ##
+
+# b4_declare_yylstype
+# ------------------
+# Declaration that might either go into the header (if --defines)
+# or open coded in the parser body.  Declare YYSTYPE and YYLTYPE.
+m4_define([b4_declare_yylstype],
+[[#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
+]m4_ifdef([b4_stype],
+[[typedef union ]b4_union_name[
+{
+]b4_user_stype[
+} YYSTYPE;
+# define YYSTYPE_IS_TRIVIAL 1]],
+[m4_if(b4_tag_seen_flag, 0,
+[[typedef int YYSTYPE;
+# define YYSTYPE_IS_TRIVIAL 1]])])[
+# define yystype YYSTYPE /* obsolescent; will be withdrawn */
+# define YYSTYPE_IS_DECLARED 1
+#endif]b4_locations_if([[
+
+#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
+typedef struct YYLTYPE
+{
+  int first_line;
+  int first_column;
+  int last_line;
+  int last_column;
+} YYLTYPE;
+# define yyltype YYLTYPE /* obsolescent; will be withdrawn */
+# define YYLTYPE_IS_DECLARED 1
+# define YYLTYPE_IS_TRIVIAL 1
+#endif]])
+])
diff --git a/data/glr.c b/data/glr.c
index 7588bd1..7ebc65c 100644
--- a/data/glr.c
+++ b/data/glr.c
@@ -163,34 +163,9 @@ m4_define([b4_rhs_location],
 # Declaration that might either go into the header (if --defines)
 # or open coded in the parser body.
 m4_define([b4_shared_declarations],
-[b4_percent_code_get([[requires]])[]dnl
-
-b4_token_enums(b4_tokens)
-
-[#ifndef YYSTYPE
-]m4_ifdef([b4_stype],
-[[typedef union ]b4_union_name[
-{
-]b4_user_stype[
-} YYSTYPE;
-# define YYSTYPE_IS_TRIVIAL 1]],
-[m4_if(b4_tag_seen_flag, 0,
-[[typedef int YYSTYPE;
-# define YYSTYPE_IS_TRIVIAL 1]])])[
-#endif
-]b4_locations_if([[
-#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
-typedef struct YYLTYPE
-{
-  int first_line;
-  int first_column;
-  int last_line;
-  int last_column;
-} YYLTYPE;
-# define YYLTYPE_IS_DECLARED 1
-# define YYLTYPE_IS_TRIVIAL 1
-#endif
-]])[
+[b4_percent_code_get([[requires]])[
+]b4_token_enums(b4_tokens)[
+]b4_declare_yylstype[
 ]b4_percent_code_get([[provides]])[]dnl
 ])
 
diff --git a/data/yacc.c b/data/yacc.c
index dbaff87..5ba271c 100644
--- a/data/yacc.c
+++ b/data/yacc.c
@@ -158,9 +158,9 @@ m4_define([b4_rhs_location],
 [(address@hidden($2) - ($1)@})])
 
 
-## ------------------ ##
-## Parser variables.  ##
-## ------------------ ##
+## -------------- ##
+## Declarations.  ##
+## -------------- ##
 
 # b4_declare_scanner_communication_variables
 # ------------------------------------------
@@ -224,10 +224,9 @@ m4_define([b4_declare_parser_state_variables], 
[b4_pure_if([[
     yytype_int16 *yyes;
     YYSIZE_T yyes_capacity;]])])
 
-
-## --------------------------------------------------------- ##
-## Defining symbol actions, e.g., printers and destructors.  ##
-## --------------------------------------------------------- ##
+## -------------- ##
+## Output files.  ##
+## -------------- ##
 
 # We do want M4 expansion after # for CPP macros.
 m4_changecom()
@@ -287,37 +286,10 @@ m4_if(b4_prefix, [yy], [],
 # define YYTOKEN_TABLE ]b4_token_table[
 #endif
 
-]b4_percent_code_get([[requires]])[]dnl
-
-b4_token_enums_defines(b4_tokens)[
-
-#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
-]m4_ifdef([b4_stype],
-[[typedef union ]b4_union_name[
-{
-]b4_user_stype[
-} YYSTYPE;
-# define YYSTYPE_IS_TRIVIAL 1]],
-[m4_if(b4_tag_seen_flag, 0,
-[[typedef int YYSTYPE;
-# define YYSTYPE_IS_TRIVIAL 1]])])[
-# define yystype YYSTYPE /* obsolescent; will be withdrawn */
-# define YYSTYPE_IS_DECLARED 1
-#endif]b4_locations_if([[
-
-#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
-typedef struct YYLTYPE
-{
-  int first_line;
-  int first_column;
-  int last_line;
-  int last_column;
-} YYLTYPE;
-# define yyltype YYLTYPE /* obsolescent; will be withdrawn */
-# define YYLTYPE_IS_DECLARED 1
-# define YYLTYPE_IS_TRIVIAL 1
-#endif]])b4_push_if([[
-
+]b4_percent_code_get([[requires]])[
+]b4_token_enums_defines(b4_tokens)[
+]b4_declare_yylstype[
+]b4_push_if([[
 #ifndef YYPUSH_DECLS
 #  define YYPUSH_DECLS
 struct yypstate;
@@ -2076,40 +2048,10 @@ b4_copyright([Bison interface for Yacc-like parsers in 
C],
 
 b4_percent_code_get([[requires]])[]dnl
 
-b4_token_enums_defines(b4_tokens)
-
-[#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
-]m4_ifdef([b4_stype],
-[[typedef union ]b4_union_name[
-{
-]b4_user_stype[
-} YYSTYPE;
-# define YYSTYPE_IS_TRIVIAL 1]],
-[m4_if(b4_tag_seen_flag, 0,
-[[typedef int YYSTYPE;
-# define YYSTYPE_IS_TRIVIAL 1]])])[
-# define yystype YYSTYPE /* obsolescent; will be withdrawn */
-# define YYSTYPE_IS_DECLARED 1
-#endif
-
-]b4_pure_if([], [[extern YYSTYPE ]b4_prefix[lval;]])
-
-b4_locations_if(
-[#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
-typedef struct YYLTYPE
-{
-  int first_line;
-  int first_column;
-  int last_line;
-  int last_column;
-} YYLTYPE;
-# define yyltype YYLTYPE /* obsolescent; will be withdrawn */
-# define YYLTYPE_IS_DECLARED 1
-# define YYLTYPE_IS_TRIVIAL 1
-#endif
-
-]b4_pure_if([], [[extern YYLTYPE ]b4_prefix[lloc;]])
-)dnl b4_locations_if
+b4_token_enums_defines(b4_tokens)[
+]b4_declare_yylstype[
+]b4_pure_if([], [[extern YYSTYPE ]b4_prefix[lval;
+]b4_locations_if([[extern YYLTYPE ]b4_prefix[lloc;]])])dnl
 b4_push_if([[
 #ifndef YYPUSH_DECLS
 #  define YYPUSH_DECLS
-- 
1.7.10.4





reply via email to

[Prev in Thread] Current Thread [Next in Thread]