[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RFC: yacc.c: factor (was: yacc.c does not prototype yyparse in the heade
From: |
Akim Demaille |
Subject: |
RFC: yacc.c: factor (was: yacc.c does not prototype yyparse in the header) |
Date: |
Tue, 12 Jun 2012 16:07:54 +0200 |
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.
Third act of refactoring. This time it is not installed
yet, as I would appreciate some opinion, as the generated
code is somewhat different:
The main difference is that in the *.c file we used the yy*
names (as %prefix is handled by "#define yy* <prefix>*" before), while
the *.hh used <prefix>* names. Keep only the later.
I don't think we care, but someone might have a different
opinion.
From b97378c27c24bcf6b249447419c3abe7c2c0b555 Mon Sep 17 00:00:00 2001
From: Akim Demaille <address@hidden>
Date: Tue, 12 Jun 2012 14:40:18 +0200
Subject: [PATCH] yacc.c: factor.
yacc.c used to include two almost identical sections, used in the
header when %defines is set, otherwise in the generated implementation
file. The main difference is that in the *.c file we used the yy*
names (as %prefix is handled by "#define yy* <prefix>*" before), while
the *.hh used <prefix>* names. Keep only the later. If this is
troublesome, b4_shared_declarations can easily take the desired prefix
as argument.
* data/yacc.c (b4_shared_declarations): New.
Use it to factor duplicated declarations.
---
data/yacc.c | 93 ++++++++++++++++++++++++-----------------------------------
1 file changed, 37 insertions(+), 56 deletions(-)
diff --git a/data/yacc.c b/data/yacc.c
index 5ba271c..6480d1a 100644
--- a/data/yacc.c
+++ b/data/yacc.c
@@ -224,6 +224,39 @@ m4_define([b4_declare_parser_state_variables],
[b4_pure_if([[
yytype_int16 *yyes;
YYSIZE_T yyes_capacity;]])])
+
+# b4_shared_declarations
+# ----------------------
+# 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]])[
+]b4_token_enums_defines(b4_tokens)[
+]b4_declare_yylstype[
+]b4_push_if([[
+#ifndef YYPUSH_DECLS
+# define YYPUSH_DECLS
+typedef struct ]b4_prefix[pstate ]b4_prefix[pstate;
+enum { YYPUSH_MORE = 4 };
+]b4_pull_if([b4_c_function_decl([b4_prefix[parse]], [[int]], b4_parse_param)
+])b4_c_function_decl([b4_prefix[push_parse]], [[int]],
+ [[b4_prefix[pstate *yyps]], [[yyps]]]b4_pure_if([,
+ [[[int yypushed_char]], [[yypushed_char]]],
+ [[[YYSTYPE const *yypushed_val]], [[yypushed_val]]]b4_locations_if([,
+ [[[YYLTYPE const *yypushed_loc]],
[[yypushed_loc]]]])])m4_ifset([b4_parse_param], [,
+ b4_parse_param]))
+b4_pull_if([b4_c_function_decl([b4_prefix[pull_parse]], [[int]],
+ [[b4_prefix[pstate *yyps]], [[yyps]]]m4_ifset([b4_parse_param], [,
+ b4_parse_param]))])
+b4_c_function_decl([b4_prefix[pstate_new]], [b4_prefix[pstate *]],
+ [[[void]], []])
+b4_c_function_decl([b4_prefix[pstate_delete]], [[void]],
+ [[b4_prefix[pstate *yyps]], [[yyps]]])[
+#endif
+]])
+b4_percent_code_get([[provides]])[]dnl
+])
+
## -------------- ##
## Output files. ##
## -------------- ##
@@ -286,34 +319,9 @@ m4_if(b4_prefix, [yy], [],
# define YYTOKEN_TABLE ]b4_token_table[
#endif
-]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;
-typedef struct yypstate yypstate;
-enum { YYPUSH_MORE = 4 };
+]b4_shared_declarations[
-]b4_pull_if([b4_c_function_decl([[yyparse]], [[int]], b4_parse_param)
-])b4_c_function_decl([[yypush_parse]], [[int]],
- [[[yypstate *yyps]], [[yyps]]]b4_pure_if([,
- [[[int yypushed_char]], [[yypushed_char]]],
- [[[YYSTYPE const *yypushed_val]], [[yypushed_val]]]b4_locations_if([,
- [[[YYLTYPE const *yypushed_loc]],
[[yypushed_loc]]]])])m4_ifset([b4_parse_param], [,
- b4_parse_param]))
-b4_pull_if([b4_c_function_decl([[yypull_parse]], [[int]],
- [[[yypstate *yyps]], [[yyps]]]m4_ifset([b4_parse_param], [,
- b4_parse_param]))])
-b4_c_function_decl([[yypstate_new]], [[yypstate *]], [[[void]], []])
-b4_c_function_decl([[yypstate_delete]], [[void]],
- [[[yypstate *yyps]], [[yyps]]])[
-#endif]])
-
-b4_percent_code_get([[provides]])[]dnl
-
-[/* Copy the second part of user declarations. */
+/* Copy the second part of user declarations. */
]b4_user_post_prologue
b4_percent_code_get[]dnl
@@ -2044,36 +2052,9 @@ yypushreturn:]])[
b4_defines_if(
address@hidden(b4_spec_defines_file@)@
b4_copyright([Bison interface for Yacc-like parsers in C],
- [1984, 1989-1990, 2000-2012])
-
-b4_percent_code_get([[requires]])[]dnl
-
-b4_token_enums_defines(b4_tokens)[
-]b4_declare_yylstype[
+ [1984, 1989-1990, 2000-2012])[
+]b4_shared_declarations[
]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
-struct ]b4_prefix[pstate;
-typedef struct ]b4_prefix[pstate ]b4_prefix[pstate;
-enum { YYPUSH_MORE = 4 };
-]b4_pull_if([b4_c_function_decl([b4_prefix[parse]], [[int]], b4_parse_param)
-])b4_c_function_decl([b4_prefix[push_parse]], [[int]],
- [[b4_prefix[pstate *yyps]], [[yyps]]]b4_pure_if([,
- [[[int yypushed_char]], [[yypushed_char]]],
- [[[YYSTYPE const *yypushed_val]], [[yypushed_val]]]b4_locations_if([,
- [[[YYLTYPE const *yypushed_loc]],
[[yypushed_loc]]]])])m4_ifset([b4_parse_param], [,
- b4_parse_param]))
-b4_pull_if([b4_c_function_decl([b4_prefix[pull_parse]], [[int]],
- [[b4_prefix[pstate *yyps]], [[yyps]]]m4_ifset([b4_parse_param], [,
- b4_parse_param]))])
-b4_c_function_decl([b4_prefix[pstate_new]], [b4_prefix[pstate *]],
- [[[void]], []])
-b4_c_function_decl([b4_prefix[pstate_delete]], [[void]],
- [[b4_prefix[pstate *yyps]], [[yyps]]])[
-#endif
-]])
-b4_percent_code_get([[provides]])[]dnl
])dnl b4_defines_if
m4_divert_pop(0)
--
1.7.10.4
- yacc.c does not prototype yyparse in the header, (continued)
- Message not available
- Message not available
- Message not available
- yacc.c does not prototype yyparse in the header, Akim Demaille, 2012/06/11
- Re: yacc.c does not prototype yyparse in the header, Paul Eggert, 2012/06/11
- Re: yacc.c does not prototype yyparse in the header, Akim Demaille, 2012/06/12
- Re: yacc.c does not prototype yyparse in the header, Paul Eggert, 2012/06/12
- Re: yacc.c does not prototype yyparse in the header, Akim Demaille, 2012/06/13
- Re: yacc.c does not prototype yyparse in the header, Paul Eggert, 2012/06/13
- Re: yacc.c does not prototype yyparse in the header, Akim Demaille, 2012/06/28
- Re: yacc.c does not prototype yyparse in the header, Akim Demaille, 2012/06/29
- FYI: glr.c: minor refactoring (was: yacc.c does not prototype yyparse in the header), Akim Demaille, 2012/06/12
- FYI: skeletons: factor yacc.c and glr.c (was: yacc.c does not prototype yyparse in the header), Akim Demaille, 2012/06/12
- RFC: yacc.c: factor (was: yacc.c does not prototype yyparse in the header),
Akim Demaille <=
- Re: RFC: yacc.c: factor (was: yacc.c does not prototype yyparse in the header), Akim Demaille, 2012/06/12
- Re: RFC: yacc.c: factor (was: yacc.c does not prototype yyparse in the header), Akim Demaille, 2012/06/13
- Re: yacc.c: instead of duplicating y.tab.h inside y.tac.c, include it (was: RFC: yacc.c: factor), Akim Demaille, 2012/06/15
- ylwrap does not rename y.tab.h in y.tab.c (was: yacc.c: instead of duplicating y.tab.h inside y.tac.c, include it), Akim Demaille, 2012/06/20
- Re: ylwrap does not rename y.tab.h in y.tab.c (was: yacc.c: instead of duplicating y.tab.h inside y.tac.c, include it), Akim Demaille, 2012/06/25
- Re: ylwrap does not rename y.tab.h in y.tab.c, Stefano Lattarini, 2012/06/25
- [PATCH] yacc, lex: new 'no-ylwrap' option to prevent use of the 'ylwrap' script, Stefano Lattarini, 2012/06/25
- Re: [PATCH] yacc, lex: new 'no-ylwrap' option to prevent use of the 'ylwrap' script, Akim Demaille, 2012/06/26
- Re: [PATCH] yacc, lex: new 'no-ylwrap' option to prevent use of the 'ylwrap' script, Stefano Lattarini, 2012/06/26
- Re: [PATCH] yacc, lex: new 'no-ylwrap' option to prevent use of the 'ylwrap' script, Akim Demaille, 2012/06/26