From ae6bdabbf6bfe6a8a0ab26b26ab66c0c0406fd15 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Tue, 12 Jun 2012 14:40:18 +0200 Subject: [PATCH 01/15] yacc.c: factor. yacc.c used to include two almost identical sections: one for the *.h file, and another for the *.c file. The main difference is that in the *.c file we used the yy* names (as %name-prefix is handled by "#define yy* *" before), while the *.hh used * 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 5ba271cb..079e488c 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( [@output(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) From 0f11eec272453d5646e5aeda135650b4fb8ac33d Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Tue, 12 Jun 2012 16:15:14 +0200 Subject: [PATCH 02/15] yacc.c: instead of duplicating y.tab.h inside y.tac.c, include it. This is already what glr.c and lalr1.cc do. * data/yacc.c: here. --- NEWS | 14 ++++++++++++++ data/glr.c | 2 +- data/yacc.c | 3 ++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 393538c7..fd51b61b 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,20 @@ GNU Bison NEWS * Noteworthy changes in release ?.? (????-??-??) [?] +** Future changes: + + The next major release will drop support for generating parsers in K&R C, + and remove the definition of yystype (removal announced since Bison + 1.875). + +** Changes in regular C parsers (yacc.c): + +*** The generated header is included + + Instead of duplicating the content of the generated header (definition of + YYSTYPE, yyltype etc.), the generated parser now includes it, as was + already the case for GLR or C++ parsers. + * Noteworthy changes in release 2.5.1 (2012-06-05) [stable] ** Future changes: diff --git a/data/glr.c b/data/glr.c index 7ebc65c0..223aa1e9 100644 --- a/data/glr.c +++ b/data/glr.c @@ -203,7 +203,7 @@ m4_if(b4_prefix, [yy], [], ]b4_null_define[ ]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]], - [b4_shared_declarations])[ + [b4_shared_declarations])[ /* Enabling traces. */ #ifndef YYDEBUG diff --git a/data/yacc.c b/data/yacc.c index 079e488c..d5000da0 100644 --- a/data/yacc.c +++ b/data/yacc.c @@ -319,7 +319,8 @@ m4_if(b4_prefix, [yy], [], # define YYTOKEN_TABLE ]b4_token_table[ #endif -]b4_shared_declarations[ +]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]], + [b4_shared_declarations])[ /* Copy the second part of user declarations. */ ]b4_user_post_prologue From 9d67a52ad6f9aa1241d64b9766525362715b16e8 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Tue, 12 Jun 2012 18:14:49 +0200 Subject: [PATCH 03/15] tests: strengthen the test on generated headers inclusion * tests/headers.at (AT_TEST_CPP_GUARD_H): Accept Bison directives. (Invalid CPP headers): Check glr. --- tests/headers.at | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/headers.at b/tests/headers.at index 9d4946d6..9710e0ce 100644 --- a/tests/headers.at +++ b/tests/headers.at @@ -46,17 +46,19 @@ AT_CLEANUP ## Invalid CPP headers. ## ## --------------------- ## -# AT_TEST_CPP_GUARD_H([INPUT-FILE-BASE) -# ------------------------------------- +# AT_TEST_CPP_GUARD_H(BASE-NAME, [DIRECTIVES]) +# -------------------------------------------- +# FIXME: Much of this can be covered by calc.at. m4_define([AT_TEST_CPP_GUARD_H], -[AT_SETUP([Invalid CPP guards: $1]) +[AT_SETUP([Invalid CPP guards: $2 --defines=$1.h]) # Possibly create inner directories. dirname=`AS_DIRNAME([$1])` AS_MKDIR_P([$dirname]) AT_DATA_GRAMMAR([$1.y], -[%{ +[$2 +%{ #include <$1.h> void yyerror (const char *); int yylex (void); @@ -67,15 +69,17 @@ dummy:; #include <$1.h> ]) -AT_BISON_CHECK([--defines=$1.h --output=y.tab.c $1.y]) +AT_BISON_CHECK([--defines=$1.h --output=$1.c $1.y]) -AT_COMPILE([y.tab.o], [-I. -c y.tab.c]) +AT_COMPILE([$1.o], [-I. -c $1.c]) AT_CLEANUP ]) AT_TEST_CPP_GUARD_H([input/input]) AT_TEST_CPP_GUARD_H([9foo]) +AT_TEST_CPP_GUARD_H([input/input], [%glr-parser]) +AT_TEST_CPP_GUARD_H([9foo], [%glr-parser]) From 3d8082ad27164bc0eb49af394400dbecc275e922 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 11 Jun 2012 16:43:42 +0200 Subject: [PATCH 04/15] tests: reorder. * tests/calc.at (power): Move its definition, as a preparation for forthcoming changes. And space changes. --- tests/calc.at | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/tests/calc.at b/tests/calc.at index c5040083..790c4e63 100644 --- a/tests/calc.at +++ b/tests/calc.at @@ -250,7 +250,7 @@ int yylex (]AT_LEX_FORMALS[); %token NUM "number" %type exp -%nonassoc '=' /* comparison */ +%nonassoc '=' /* comparison */ %left '-' '+' %left '*' '/' %left NEG /* negation--unary minus */ @@ -289,6 +289,16 @@ exp: ; %% +static int +power (int base, int exponent) +{ + int res = 1; + assert (0 <= exponent); + for (/* Niente */; exponent; --exponent) + res *= base; + return res; +} + ]AT_SKEL_CC_IF( [AT_LOCATION_TYPE_IF([[ std::ostream& @@ -334,27 +344,16 @@ AT_YYERROR_SEES_LOC_IF([ AT_LOC_FIRST_LINE, AT_LOC_FIRST_COLUMN); if (AT_LOC_FIRST_LINE != AT_LOC_LAST_LINE) fprintf (stderr, "-%d.%d", - AT_LOC_LAST_LINE, AT_LOC_LAST_COLUMN - 1); + AT_LOC_LAST_LINE, AT_LOC_LAST_COLUMN - 1); else if (AT_LOC_FIRST_COLUMN != AT_LOC_LAST_COLUMN - 1) fprintf (stderr, "-%d", - AT_LOC_LAST_COLUMN - 1); + AT_LOC_LAST_COLUMN - 1); fprintf (stderr, ": ");]) fprintf (stderr, "%s\n", s); }])[ ]AT_DEFINES_IF(, [AT_CALC_LEX])[ -static int -power (int base, int exponent) -{ - int res = 1; - assert (0 <= exponent); - for (/* Niente */; exponent; --exponent) - res *= base; - return res; -} - - /* A C main function. */ int main (int argc, const char **argv) From 6aef2e01a4ec078fcc1b4c3aa7bedd63f14fa5fb Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 11 Jun 2012 16:45:45 +0200 Subject: [PATCH 05/15] tests: improve AT_FULL_COMPILE. * tests/local.at: Accept a third argument. Simplify quotation pattern. Calls for better refactoring, but will suffice for a while. --- tests/local.at | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/tests/local.at b/tests/local.at index 54ac833d..6efe66f8 100644 --- a/tests/local.at +++ b/tests/local.at @@ -450,8 +450,8 @@ AT_CHECK([[test -n "$CONF_JAVA" || exit 77 AT_CHECK([[$SHELL ../../../javacomp.sh ]$1], [[0]], [ignore], [ignore])]) -# AT_FULL_COMPILE(OUTPUT, [OTHER]) -# -------------------------------- +# AT_FULL_COMPILE(OUTPUT, [OTHER1], [OTHER2]) +# ------------------------------------------- # Compile OUTPUT.y to OUTPUT.c, OUTPUT.cc, or OUTPUT.java, and then # compile it to OUTPUT or OUTPUT.class. If OTHER is specified, compile # OUTPUT-OTHER.c, OUTPUT-OTHER.cc, or OUTPUT-OTHER.java to OUTPUT or @@ -459,16 +459,27 @@ AT_CHECK([[$SHELL ../../../javacomp.sh ]$1], # AT_SKEL_JAVA_IF. m4_define([AT_FULL_COMPILE], [ AT_SKEL_JAVA_IF([ - AT_BISON_CHECK([[-o ]$1[.java ]$1[.y]]) - AT_JAVA_COMPILE([$1[.java]]m4_ifval($2, - [[$1[.java ]$1[-]$2[.java]]])) + AT_BISON_CHECK([-o $1.java $1.y]) + AT_JAVA_COMPILE([$1.java], + m4_join([ ], + [$1.java], + m4_ifval($2, [[$1-$2.java]]), + m4_ifval($3, [[$1-$3.java]]))) ], [ AT_SKEL_CC_IF([ - AT_BISON_CHECK([[-o ]$1[.cc ]$1[.y]]) - AT_COMPILE_CXX([$1]m4_ifval($2, [, [$1[.cc ]$1[-]$2[.cc]]])) + AT_BISON_CHECK([-o $1.cc $1.y]) + AT_COMPILE_CXX([$1], + m4_join([ ], + [$1.cc], + m4_ifval($2, [[$1-$2.cc]]), + m4_ifval($3, [[$1-$3.cc]]))) ], [ - AT_BISON_CHECK([[-o ]$1[.c ]$1[.y]]) - AT_COMPILE([$1]m4_ifval($2, [, [$1[.c ]$1[-]$2[.c]]])) + AT_BISON_CHECK([-o $1.c $1.y]) + AT_COMPILE([$1], + m4_join([ ], + [$1.c], + m4_ifval($2, [[$1-$2.c]]), + m4_ifval($3, [[$1-$3.c]]))) ]) ]) ]) From c3e9f08f93bc8bbabcd4f4093e52ad8f8b5454ca Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Fri, 15 Jun 2012 14:21:16 +0200 Subject: [PATCH 06/15] skeletons: use header guards. * data/glr.c, data/glr.cc, data/yacc.c: here. * NEWS: Document it. --- NEWS | 15 ++++++++--- data/glr.c | 21 ++++++--------- data/glr.cc | 11 +++----- data/yacc.c | 73 +++++++++++++++++++++++++++++++++-------------------- 4 files changed, 69 insertions(+), 51 deletions(-) diff --git a/NEWS b/NEWS index fd51b61b..118aae38 100644 --- a/NEWS +++ b/NEWS @@ -8,14 +8,23 @@ GNU Bison NEWS and remove the definition of yystype (removal announced since Bison 1.875). -** Changes in regular C parsers (yacc.c): - -*** The generated header is included +** The generated header is included (yacc.c) Instead of duplicating the content of the generated header (definition of YYSTYPE, yyltype etc.), the generated parser now includes it, as was already the case for GLR or C++ parsers. +** Header guards (yacc.c, glr.c, glr.cc) + + The generated headers are now guarded, as is already the case for C++ + parsers (lalr1.cc). For intance, with --defines=foo.h: + + #ifndef YY_FOO_H + # define YY_FOO_H + ... + #endif /* !YY_FOO_H */ + + * Noteworthy changes in release 2.5.1 (2012-06-05) [stable] ** Future changes: diff --git a/data/glr.c b/data/glr.c index 223aa1e9..d1d61fe6 100644 --- a/data/glr.c +++ b/data/glr.c @@ -166,6 +166,7 @@ m4_define([b4_shared_declarations], [b4_percent_code_get([[requires]])[ ]b4_token_enums(b4_tokens)[ ]b4_declare_yylstype[ +]b4_c_ansi_function_decl(b4_prefix[parse], [int], b4_parse_param)[ ]b4_percent_code_get([[provides]])[]dnl ]) @@ -472,9 +473,6 @@ static const ]b4_int_type_for([b4_stos])[ yystos[] = }; -/* Prevent warning if -Wmissing-prototypes. */ -]b4_c_ansi_function_decl([yyparse], [int], b4_parse_param)[ - /* Error token number */ #define YYTERROR 1 @@ -2637,15 +2635,12 @@ m4_if(b4_skeleton, ["glr.c"], [b4_defines_if( [@output(b4_spec_defines_file@)@ b4_copyright([Skeleton interface for Bison GLR parsers in C], - [2002-2012]) + [2002-2012])[ -b4_shared_declarations - -b4_pure_if([], -[[extern YYSTYPE ]b4_prefix[lval;]]) - -b4_locations_if([b4_pure_if([], -[extern YYLTYPE ]b4_prefix[lloc;]) -]) -])]) +]b4_cpp_guard_open([b4_spec_defines_file])[ +]b4_shared_declarations[ +]b4_pure_if([], [[extern YYSTYPE ]b4_prefix[lval; +]b4_locations_if([[extern YYLTYPE ]b4_prefix[lloc;]])])[ +]b4_cpp_guard_close([b4_spec_defines_file])[ +]])]) m4_divert_pop(0) diff --git a/data/glr.cc b/data/glr.cc index d4f21adc..0bc1f9fa 100644 --- a/data/glr.cc +++ b/data/glr.cc @@ -230,8 +230,7 @@ b4_copyright([Skeleton interface for Bison GLR parsers in C++], /* C++ GLR parser skeleton written by Akim Demaille. */ -#ifndef PARSER_HEADER_H -# define PARSER_HEADER_H +]b4_cpp_guard_open([b4_spec_defines_file])[ ]b4_percent_code_get([[requires]])[ @@ -362,8 +361,6 @@ b4_percent_define_flag_if([[global_tokens_and_yystype]], #endif ]b4_namespace_close[ - -]b4_percent_code_get([[provides]])[]dnl - -[#endif /* ! defined PARSER_HEADER_H */] -m4_divert_pop(0) +]b4_percent_code_get([[provides]])[ +]b4_cpp_guard_close([b4_spec_defines_file])[ +]m4_divert_pop(0) diff --git a/data/yacc.c b/data/yacc.c index d5000da0..7f73c26d 100644 --- a/data/yacc.c +++ b/data/yacc.c @@ -225,18 +225,10 @@ m4_define([b4_declare_parser_state_variables], [b4_pure_if([[ 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; +# b4_declare_yyparse_push_ +# ------------------------ +m4_define([b4_declare_yyparse_push_], +[[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]], @@ -251,10 +243,40 @@ b4_pull_if([b4_c_function_decl([b4_prefix[pull_parse]], [[int]], 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 + [[b4_prefix[pstate *yyps]], [[yyps]]])dnl +]) + +# b4_declare_yyparse_ +# ------------------- +# When not the push parser. +m4_define([b4_declare_yyparse_], +[[#ifdef YYPARSE_PARAM +]b4_c_function_decl(b4_prefix[parse], [int], + [[void *YYPARSE_PARAM], [YYPARSE_PARAM]])[ +#else /* ! YYPARSE_PARAM */ +]b4_c_function_decl(b4_prefix[parse], [int], b4_parse_param)[ +#endif /* ! YYPARSE_PARAM */]dnl +]) + + +# b4_declare_yyparse +# ------------------ +m4_define([b4_declare_yyparse], +[b4_push_if([b4_declare_yyparse_push_], + [b4_declare_yyparse_])[]dnl +]) + + +# 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_declare_yyparse[ +]b4_percent_code_get([[provides]])[]dnl ]) ## -------------- ## @@ -1373,20 +1395,12 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, } #endif /* YYERROR_VERBOSE */ -]b4_yydestruct_generate([b4_c_function_def])b4_push_if([], [[ +]b4_yydestruct_generate([b4_c_function_def])[ - -/* Prevent warnings from -Wmissing-prototypes. */ -#ifdef YYPARSE_PARAM -]b4_c_function_decl([yyparse], [int], - [[void *YYPARSE_PARAM], [YYPARSE_PARAM]])[ -#else /* ! YYPARSE_PARAM */ -]b4_c_function_decl([yyparse], [int], b4_parse_param)[ -#endif /* ! YYPARSE_PARAM */]])b4_pure_if([], [ +]b4_pure_if([], [ b4_declare_scanner_communication_variables])[]b4_push_if([[ - struct yypstate {]b4_declare_parser_state_variables[ /* Used to determine if this is the first time this instance has @@ -2054,8 +2068,11 @@ b4_defines_if( [@output(b4_spec_defines_file@)@ b4_copyright([Bison interface for Yacc-like parsers in C], [1984, 1989-1990, 2000-2012])[ + +]b4_cpp_guard_open([b4_spec_defines_file])[ ]b4_shared_declarations[ ]b4_pure_if([], [[extern YYSTYPE ]b4_prefix[lval; -]b4_locations_if([[extern YYLTYPE ]b4_prefix[lloc;]])])dnl -])dnl b4_defines_if +]b4_locations_if([[extern YYLTYPE ]b4_prefix[lloc;]])])[ +]b4_cpp_guard_close([b4_spec_defines_file])[ +]])dnl b4_defines_if m4_divert_pop(0) From 56ca3d8fce0c9db2f2829d7a7a07a9ad06cdf6a8 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Fri, 15 Jun 2012 15:19:16 +0200 Subject: [PATCH 07/15] glr.c, yacc.c: declare yydebug in the header. * data/c.m4 (b4_declare_yydebug): New. * data/glr.c, data/yacc.c (b4_shared_declarations): Use it. Remove the corresponding code from the parser body. * NEWS: Doc this. --- NEWS | 18 +++++++++++++++++- data/c.m4 | 12 ++++++++++++ data/glr.c | 8 ++------ data/yacc.c | 8 ++------ 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/NEWS b/NEWS index 118aae38..ae8b297c 100644 --- a/NEWS +++ b/NEWS @@ -14,7 +14,9 @@ GNU Bison NEWS YYSTYPE, yyltype etc.), the generated parser now includes it, as was already the case for GLR or C++ parsers. -** Header guards (yacc.c, glr.c, glr.cc) +** Headers (yacc.c, glr.c, glr.cc) + +*** Guards The generated headers are now guarded, as is already the case for C++ parsers (lalr1.cc). For intance, with --defines=foo.h: @@ -24,6 +26,20 @@ GNU Bison NEWS ... #endif /* !YY_FOO_H */ +*** New declarations + + The generated header now declares yydebug and yyparse. Both honor + --name-prefix=bar_, and yield + + int bar_parse (void); + + rather than + + #define yyparse bar_parse + int yyparse (void); + + in order to facilitate the inclusion of several parser headers inside a + single compilation unit. * Noteworthy changes in release 2.5.1 (2012-06-05) [stable] diff --git a/data/c.m4 b/data/c.m4 index 64f68fec..78b12325 100644 --- a/data/c.m4 +++ b/data/c.m4 @@ -567,3 +567,15 @@ typedef struct YYLTYPE # define YYLTYPE_IS_TRIVIAL 1 #endif]]) ]) + +# b4_declare_yydebug +# ------------------ +m4_define([b4_declare_yydebug], +[[/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG ]b4_debug_flag[ +#endif +#if YYDEBUG +extern int ]b4_prefix[debug; +#endif][]dnl +]) diff --git a/data/glr.c b/data/glr.c index d1d61fe6..9bbf9a72 100644 --- a/data/glr.c +++ b/data/glr.c @@ -163,7 +163,8 @@ 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]])[ +[b4_declare_yydebug[ +]b4_percent_code_get([[requires]])[ ]b4_token_enums(b4_tokens)[ ]b4_declare_yylstype[ ]b4_c_ansi_function_decl(b4_prefix[parse], [int], b4_parse_param)[ @@ -206,11 +207,6 @@ m4_if(b4_prefix, [yy], [], ]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]], [b4_shared_declarations])[ -/* Enabling traces. */ -#ifndef YYDEBUG -# define YYDEBUG ]b4_debug_flag[ -#endif - /* Enabling verbose error messages. */ #ifdef YYERROR_VERBOSE # undef YYERROR_VERBOSE diff --git a/data/yacc.c b/data/yacc.c index 7f73c26d..30c5f672 100644 --- a/data/yacc.c +++ b/data/yacc.c @@ -272,7 +272,8 @@ m4_define([b4_declare_yyparse], # 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_declare_yydebug[ +]b4_percent_code_get([[requires]])[ ]b4_token_enums_defines(b4_tokens)[ ]b4_declare_yylstype[ ]b4_declare_yyparse[ @@ -323,11 +324,6 @@ m4_if(b4_prefix, [yy], [], ]b4_null_define[ -/* Enabling traces. */ -#ifndef YYDEBUG -# define YYDEBUG ]b4_debug_flag[ -#endif - /* Enabling verbose error messages. */ #ifdef YYERROR_VERBOSE # undef YYERROR_VERBOSE From c8c220d19ae0a8ea22f04cd2580b28f773b1a74e Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 11 Jun 2012 16:47:46 +0200 Subject: [PATCH 08/15] tests: call the parser from another compilation unit. In order to improve the testing of %defines, which exports the interface of the generated parser, change the calc.at tests so that when %defines is passed, main will be in another compilation unit. It loads the generated header. * tests/calc.at (AT_CALC_MAIN): New. Includes the definition of the global variables. Therefore, now declare them from the %requires section of the parser. Adjust to yydebug and yyparse being renamed by %name-prefix. --- tests/calc.at | 144 +++++++++++++++++++++++++++++--------------------- 1 file changed, 85 insertions(+), 59 deletions(-) diff --git a/tests/calc.at b/tests/calc.at index 790c4e63..e54a3670 100644 --- a/tests/calc.at +++ b/tests/calc.at @@ -33,9 +33,79 @@ # Don't call this macro directly, because it contains some occurrences # of `$1' etc. which will be interpreted by m4. So you should call it # with $1, $2, and $3 as arguments, which is what AT_DATA_CALC_Y does. +# +# When %defines is not passed, generate a single self-contained file. +# Otherwise, generate three: calc.y with the parser, calc-lex.c with +# the scanner, and calc-main.c with "main()". This is in order to +# stress the use of the generated parser header. To avoid code +# duplication, AT_CALC_LEX and AT_CALC_MAIN contain the body of these +# two later files. m4_define([_AT_DATA_CALC_Y], [m4_if([$1$2$3], $[1]$[2]$[3], [], [m4_fatal([$0: Invalid arguments: $@])])dnl + +m4_pushdef([AT_CALC_MAIN], +[#if HAVE_UNISTD_H +# include +#else +# undef alarm +# define alarm(seconds) /* empty */ +#endif + +AT_SKEL_CC_IF([[ +/* A C++ ]AT_NAME_PREFIX[parse that simulates the C signature. */ +int +]AT_NAME_PREFIX[parse (]AT_PARAM_IF([semantic_value *result, int *count]))[ +{ + ]AT_NAME_PREFIX[::parser parser]AT_PARAM_IF([ (result, count)])[; +#if YYDEBUG + parser.set_debug_level (1); +#endif + return parser.parse (); +} +]])[ + +semantic_value global_result = 0; +int global_count = 0; + +/* A C main function. */ +int +main (int argc, const char **argv) +{ + semantic_value result = 0; + int count = 0; + int status; + + /* This used to be alarm (10), but that isn't enough time for + a July 1995 vintage DEC Alphastation 200 4/100 system, + according to Nelson H. F. Beebe. 100 seconds is enough. */ + alarm (100); + + if (argc == 2) + input = fopen (argv[1], "r"); + else + input = stdin; + + if (!input) + { + perror (argv[1]); + return 3; + } + +]AT_SKEL_CC_IF([], [m4_bmatch([$4], [%debug], +[ ]AT_NAME_PREFIX[debug = 1;])])[ + status = ]AT_NAME_PREFIX[parse (]AT_PARAM_IF([[&result, &count]])[); + if (fclose (input)) + perror ("fclose"); + if (global_result != result) + abort (); + if (global_count != count) + abort (); + return status; +} +]]) + + m4_pushdef([AT_CALC_LEX], [[#include @@ -198,7 +268,9 @@ AT_SKEL_CC_IF( { #include /* The input. */ -extern FILE *input;]AT_SKEL_CC_IF([[ +extern FILE *input; +extern semantic_value global_result; +extern int global_count;]AT_SKEL_CC_IF([[ #ifndef YYLTYPE # define YYLTYPE ]AT_NAME_PREFIX[::parser::location_type #endif @@ -210,17 +282,9 @@ extern FILE *input;]AT_SKEL_CC_IF([[ #include #include #include -#if HAVE_UNISTD_H -# include -#else -# undef alarm -# define alarm(seconds) /* empty */ -#endif #define USE(Var) FILE *input; -static semantic_value global_result = 0; -static int global_count = 0; static int power (int base, int exponent); ]AT_SKEL_CC_IF(, @@ -320,17 +384,6 @@ AT_NAME_PREFIX::parser::error (const location_type& l, const std::string& m) (void) l; std::cerr << AT_LOCATION_IF([l << ": " << ])m << std::endl; } - -/* A C++ yyparse that simulates the C signature. */ -int -yyparse (AT_PARAM_IF([semantic_value *result, int *count])) -{ - AT_NAME_PREFIX::parser parser[]AT_PARAM_IF([ (result, count)]); -#if YYDEBUG - parser.set_debug_level (1); -#endif - return parser.parse (); -} ], [/* A C error reporting function. */ static void @@ -352,48 +405,21 @@ AT_YYERROR_SEES_LOC_IF([ fprintf (stderr, "%s\n", s); }])[ -]AT_DEFINES_IF(, [AT_CALC_LEX])[ - -/* A C main function. */ -int -main (int argc, const char **argv) -{ - semantic_value result = 0; - int count = 0; - int status; - - /* This used to be alarm (10), but that isn't enough time for - a July 1995 vintage DEC Alphastation 200 4/100 system, - according to Nelson H. F. Beebe. 100 seconds is enough. */ - alarm (100); - - if (argc == 2) - input = fopen (argv[1], "r"); - else - input = stdin; - - if (!input) - { - perror (argv[1]); - return 3; - } - -]AT_SKEL_CC_IF([], [m4_bmatch([$4], [%debug], -[ yydebug = 1;])])[ - status = yyparse (]AT_PARAM_IF([[&result, &count]])[); - if (fclose (input)) - perror ("fclose"); - if (global_result != result) - abort (); - if (global_count != count) - abort (); - return status; -} +]AT_DEFINES_IF([], +[AT_CALC_LEX +AT_CALC_MAIN])[ ]]) + AT_DEFINES_IF([AT_DATA_SOURCE([[calc-lex.c]AT_SKEL_CC_IF([[c]])], [[#include "calc.h]AT_SKEL_CC_IF([[h]])[" -]AT_CALC_LEX])]) +]AT_CALC_LEX]) +AT_DATA_SOURCE([[calc-main.c]AT_SKEL_CC_IF([[c]])], +[[#include "calc.h]AT_SKEL_CC_IF([[h]])[" + +]AT_CALC_MAIN]) +]) +m4_popdef([AT_CALC_MAIN]) m4_popdef([AT_CALC_LEX]) ])# _AT_DATA_CALC_Y @@ -506,7 +532,7 @@ m4_ifval([$2], [AT_CHECK([exit 77])]) AT_BISON_OPTION_PUSHDEFS([$1]) AT_DATA_CALC_Y([$1]) -AT_FULL_COMPILE([calc], [AT_DEFINES_IF([[lex]])]) +AT_FULL_COMPILE([calc], AT_DEFINES_IF([[lex], [main]])) # Test the priorities. _AT_CHECK_CALC([$1], From 363bf73276e2d60ddbe76ededc24d6d9b467bac8 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sun, 17 Jun 2012 11:19:51 +0200 Subject: [PATCH 09/15] tests: portability issues. * tests/calc.at (AT_CALC_MAIN): Missing include reported by Hydra. --- tests/calc.at | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/calc.at b/tests/calc.at index e54a3670..77f70cd3 100644 --- a/tests/calc.at +++ b/tests/calc.at @@ -45,7 +45,8 @@ m4_define([_AT_DATA_CALC_Y], [m4_fatal([$0: Invalid arguments: $@])])dnl m4_pushdef([AT_CALC_MAIN], -[#if HAVE_UNISTD_H +[#include /* abort */ +#if HAVE_UNISTD_H # include #else # undef alarm @@ -280,7 +281,6 @@ extern int global_count;]AT_SKEL_CC_IF([[ %code { #include -#include #include #define USE(Var) From 34d867d7d213d4bee890c40efeea383b383cef7a Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sun, 17 Jun 2012 11:17:46 +0200 Subject: [PATCH 10/15] regen. --- src/parse-gram.c | 494 +++++++++++++++-------------------------------- src/parse-gram.h | 34 +++- 2 files changed, 182 insertions(+), 346 deletions(-) diff --git a/src/parse-gram.c b/src/parse-gram.c index c5bf878c..31d20854 100644 --- a/src/parse-gram.c +++ b/src/parse-gram.c @@ -1,4 +1,4 @@ -/* A Bison parser, made by GNU Bison 2.5.1_rc2. */ +/* A Bison parser, made by GNU Bison 2.5.1.19-ced26-dirty. */ /* Bison implementation for Yacc-like parsers in C @@ -44,7 +44,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "2.5.1_rc2" +#define YYBISON_VERSION "2.5.1.19-ced26-dirty" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -73,7 +73,7 @@ /* Copy the first part of user declarations. */ -/* Line 268 of yacc.c */ +/* Line 323 of yacc.c */ #line 1 "parse-gram.y" /* Bison Grammar Parser -*- C -*- @@ -169,7 +169,7 @@ current_lhs(symbol *sym, location loc, named_ref *ref) #define YYTYPE_UINT8 uint_fast8_t -/* Line 268 of yacc.c */ +/* Line 323 of yacc.c */ #line 174 "parse-gram.c" # ifndef YY_NULL @@ -180,11 +180,6 @@ current_lhs(symbol *sym, location loc, named_ref *ref) # endif # endif -/* Enabling traces. */ -#ifndef YYDEBUG -# define YYDEBUG 1 -#endif - /* Enabling verbose error messages. */ #ifdef YYERROR_VERBOSE # undef YYERROR_VERBOSE @@ -198,178 +193,13 @@ current_lhs(symbol *sym, location loc, named_ref *ref) # define YYTOKEN_TABLE 0 #endif - -/* Tokens. */ -#ifndef YYTOKENTYPE -# define YYTOKENTYPE - /* Put the tokens into the symbol table, so that GDB and other debuggers - know about them. */ - enum yytokentype { - GRAM_EOF = 0, - STRING = 258, - INT = 259, - PERCENT_TOKEN = 260, - PERCENT_NTERM = 261, - PERCENT_TYPE = 262, - PERCENT_DESTRUCTOR = 263, - PERCENT_PRINTER = 264, - PERCENT_LEFT = 265, - PERCENT_RIGHT = 266, - PERCENT_NONASSOC = 267, - PERCENT_PREC = 268, - PERCENT_DPREC = 269, - PERCENT_MERGE = 270, - PERCENT_CODE = 271, - PERCENT_DEBUG = 272, - PERCENT_DEFAULT_PREC = 273, - PERCENT_DEFINE = 274, - PERCENT_DEFINES = 275, - PERCENT_ERROR_VERBOSE = 276, - PERCENT_EXPECT = 277, - PERCENT_EXPECT_RR = 278, - PERCENT_FILE_PREFIX = 279, - PERCENT_GLR_PARSER = 280, - PERCENT_INITIAL_ACTION = 281, - PERCENT_LANGUAGE = 282, - PERCENT_LEX_PARAM = 283, - PERCENT_LOCATIONS = 284, - PERCENT_NAME_PREFIX = 285, - PERCENT_NO_DEFAULT_PREC = 286, - PERCENT_NO_LINES = 287, - PERCENT_NONDETERMINISTIC_PARSER = 288, - PERCENT_OUTPUT = 289, - PERCENT_PARSE_PARAM = 290, - PERCENT_PURE_PARSER = 291, - PERCENT_REQUIRE = 292, - PERCENT_SKELETON = 293, - PERCENT_START = 294, - PERCENT_TOKEN_TABLE = 295, - PERCENT_VERBOSE = 296, - PERCENT_YACC = 297, - BRACED_CODE = 298, - BRACKETED_ID = 299, - CHAR = 300, - EPILOGUE = 301, - EQUAL = 302, - ID = 303, - ID_COLON = 304, - PERCENT_PERCENT = 305, - PIPE = 306, - PROLOGUE = 307, - SEMICOLON = 308, - TYPE = 309, - TYPE_TAG_ANY = 310, - TYPE_TAG_NONE = 311, - PERCENT_UNION = 312 - }; -#endif -/* Tokens. */ -#define GRAM_EOF 0 -#define STRING 258 -#define INT 259 -#define PERCENT_TOKEN 260 -#define PERCENT_NTERM 261 -#define PERCENT_TYPE 262 -#define PERCENT_DESTRUCTOR 263 -#define PERCENT_PRINTER 264 -#define PERCENT_LEFT 265 -#define PERCENT_RIGHT 266 -#define PERCENT_NONASSOC 267 -#define PERCENT_PREC 268 -#define PERCENT_DPREC 269 -#define PERCENT_MERGE 270 -#define PERCENT_CODE 271 -#define PERCENT_DEBUG 272 -#define PERCENT_DEFAULT_PREC 273 -#define PERCENT_DEFINE 274 -#define PERCENT_DEFINES 275 -#define PERCENT_ERROR_VERBOSE 276 -#define PERCENT_EXPECT 277 -#define PERCENT_EXPECT_RR 278 -#define PERCENT_FILE_PREFIX 279 -#define PERCENT_GLR_PARSER 280 -#define PERCENT_INITIAL_ACTION 281 -#define PERCENT_LANGUAGE 282 -#define PERCENT_LEX_PARAM 283 -#define PERCENT_LOCATIONS 284 -#define PERCENT_NAME_PREFIX 285 -#define PERCENT_NO_DEFAULT_PREC 286 -#define PERCENT_NO_LINES 287 -#define PERCENT_NONDETERMINISTIC_PARSER 288 -#define PERCENT_OUTPUT 289 -#define PERCENT_PARSE_PARAM 290 -#define PERCENT_PURE_PARSER 291 -#define PERCENT_REQUIRE 292 -#define PERCENT_SKELETON 293 -#define PERCENT_START 294 -#define PERCENT_TOKEN_TABLE 295 -#define PERCENT_VERBOSE 296 -#define PERCENT_YACC 297 -#define BRACED_CODE 298 -#define BRACKETED_ID 299 -#define CHAR 300 -#define EPILOGUE 301 -#define EQUAL 302 -#define ID 303 -#define ID_COLON 304 -#define PERCENT_PERCENT 305 -#define PIPE 306 -#define PROLOGUE 307 -#define SEMICOLON 308 -#define TYPE 309 -#define TYPE_TAG_ANY 310 -#define TYPE_TAG_NONE 311 -#define PERCENT_UNION 312 - - - - -#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED -typedef union YYSTYPE -{ - -/* Line 295 of yacc.c */ -#line 114 "parse-gram.y" - - symbol *symbol; - symbol_list *list; - int integer; - char const *chars; - char *code; - assoc assoc; - uniqstr uniqstr; - unsigned char character; - named_ref *named_ref; - - - -/* Line 295 of yacc.c */ -#line 348 "parse-gram.c" -} YYSTYPE; -# define YYSTYPE_IS_TRIVIAL 1 -# define yystype YYSTYPE /* obsolescent; will be withdrawn */ -# define YYSTYPE_IS_DECLARED 1 -#endif - -#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 - +#include "parse-gram.h" /* Copy the second part of user declarations. */ -/* Line 345 of yacc.c */ -#line 373 "parse-gram.c" +/* Line 344 of yacc.c */ +#line 203 "parse-gram.c" #ifdef short # undef short @@ -1060,165 +890,165 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp) { case 3: /* "\"string\"" */ -/* Line 823 of yacc.c */ +/* Line 822 of yacc.c */ #line 204 "parse-gram.y" { fputs (quotearg_style (c_quoting_style, (yyvaluep->chars)), stderr); }; -/* Line 823 of yacc.c */ -#line 1069 "parse-gram.c" +/* Line 822 of yacc.c */ +#line 899 "parse-gram.c" break; case 4: /* "\"integer\"" */ -/* Line 823 of yacc.c */ +/* Line 822 of yacc.c */ #line 216 "parse-gram.y" { fprintf (stderr, "%d", (yyvaluep->integer)); }; -/* Line 823 of yacc.c */ -#line 1078 "parse-gram.c" +/* Line 822 of yacc.c */ +#line 908 "parse-gram.c" break; case 43: /* "\"{...}\"" */ -/* Line 823 of yacc.c */ +/* Line 822 of yacc.c */ #line 206 "parse-gram.y" { fprintf (stderr, "{\n%s\n}", (yyvaluep->code)); }; -/* Line 823 of yacc.c */ -#line 1087 "parse-gram.c" +/* Line 822 of yacc.c */ +#line 917 "parse-gram.c" break; case 44: /* "\"[identifier]\"" */ -/* Line 823 of yacc.c */ +/* Line 822 of yacc.c */ #line 211 "parse-gram.y" { fprintf (stderr, "[%s]", (yyvaluep->uniqstr)); }; -/* Line 823 of yacc.c */ -#line 1096 "parse-gram.c" +/* Line 822 of yacc.c */ +#line 926 "parse-gram.c" break; case 45: /* "\"char\"" */ -/* Line 823 of yacc.c */ +/* Line 822 of yacc.c */ #line 198 "parse-gram.y" { fputs (char_name ((yyvaluep->character)), stderr); }; -/* Line 823 of yacc.c */ -#line 1105 "parse-gram.c" +/* Line 822 of yacc.c */ +#line 935 "parse-gram.c" break; case 46: /* "\"epilogue\"" */ -/* Line 823 of yacc.c */ +/* Line 822 of yacc.c */ #line 206 "parse-gram.y" { fprintf (stderr, "{\n%s\n}", (yyvaluep->chars)); }; -/* Line 823 of yacc.c */ -#line 1114 "parse-gram.c" +/* Line 822 of yacc.c */ +#line 944 "parse-gram.c" break; case 48: /* "\"identifier\"" */ -/* Line 823 of yacc.c */ +/* Line 822 of yacc.c */ #line 210 "parse-gram.y" { fputs ((yyvaluep->uniqstr), stderr); }; -/* Line 823 of yacc.c */ -#line 1123 "parse-gram.c" +/* Line 822 of yacc.c */ +#line 953 "parse-gram.c" break; case 49: /* "\"identifier:\"" */ -/* Line 823 of yacc.c */ +/* Line 822 of yacc.c */ #line 212 "parse-gram.y" { fprintf (stderr, "%s:", (yyvaluep->uniqstr)); }; -/* Line 823 of yacc.c */ -#line 1132 "parse-gram.c" +/* Line 822 of yacc.c */ +#line 962 "parse-gram.c" break; case 52: /* "\"%{...%}\"" */ -/* Line 823 of yacc.c */ +/* Line 822 of yacc.c */ #line 206 "parse-gram.y" { fprintf (stderr, "{\n%s\n}", (yyvaluep->chars)); }; -/* Line 823 of yacc.c */ -#line 1141 "parse-gram.c" +/* Line 822 of yacc.c */ +#line 971 "parse-gram.c" break; case 54: /* "\"type\"" */ -/* Line 823 of yacc.c */ +/* Line 822 of yacc.c */ #line 213 "parse-gram.y" { fprintf (stderr, "<%s>", (yyvaluep->uniqstr)); }; -/* Line 823 of yacc.c */ -#line 1150 "parse-gram.c" +/* Line 822 of yacc.c */ +#line 980 "parse-gram.c" break; case 71: /* "symbol.prec" */ -/* Line 823 of yacc.c */ +/* Line 822 of yacc.c */ #line 219 "parse-gram.y" { fprintf (stderr, "%s", (yyvaluep->symbol)->tag); }; -/* Line 823 of yacc.c */ -#line 1159 "parse-gram.c" +/* Line 822 of yacc.c */ +#line 989 "parse-gram.c" break; case 84: /* "variable" */ -/* Line 823 of yacc.c */ +/* Line 822 of yacc.c */ #line 210 "parse-gram.y" { fputs ((yyvaluep->uniqstr), stderr); }; -/* Line 823 of yacc.c */ -#line 1168 "parse-gram.c" +/* Line 822 of yacc.c */ +#line 998 "parse-gram.c" break; case 85: /* "content.opt" */ -/* Line 823 of yacc.c */ +/* Line 822 of yacc.c */ #line 206 "parse-gram.y" { fprintf (stderr, "{\n%s\n}", (yyvaluep->chars)); }; -/* Line 823 of yacc.c */ -#line 1177 "parse-gram.c" +/* Line 822 of yacc.c */ +#line 1007 "parse-gram.c" break; case 86: /* "braceless" */ -/* Line 823 of yacc.c */ +/* Line 822 of yacc.c */ #line 206 "parse-gram.y" { fprintf (stderr, "{\n%s\n}", (yyvaluep->chars)); }; -/* Line 823 of yacc.c */ -#line 1186 "parse-gram.c" +/* Line 822 of yacc.c */ +#line 1016 "parse-gram.c" break; case 87: /* "id" */ -/* Line 823 of yacc.c */ +/* Line 822 of yacc.c */ #line 219 "parse-gram.y" { fprintf (stderr, "%s", (yyvaluep->symbol)->tag); }; -/* Line 823 of yacc.c */ -#line 1195 "parse-gram.c" +/* Line 822 of yacc.c */ +#line 1025 "parse-gram.c" break; case 88: /* "id_colon" */ -/* Line 823 of yacc.c */ +/* Line 822 of yacc.c */ #line 220 "parse-gram.y" { fprintf (stderr, "%s:", (yyvaluep->symbol)->tag); }; -/* Line 823 of yacc.c */ -#line 1204 "parse-gram.c" +/* Line 822 of yacc.c */ +#line 1034 "parse-gram.c" break; case 89: /* "symbol" */ -/* Line 823 of yacc.c */ +/* Line 822 of yacc.c */ #line 219 "parse-gram.y" { fprintf (stderr, "%s", (yyvaluep->symbol)->tag); }; -/* Line 823 of yacc.c */ -#line 1213 "parse-gram.c" +/* Line 822 of yacc.c */ +#line 1043 "parse-gram.c" break; case 90: /* "string_as_id" */ -/* Line 823 of yacc.c */ +/* Line 822 of yacc.c */ #line 219 "parse-gram.y" { fprintf (stderr, "%s", (yyvaluep->symbol)->tag); }; -/* Line 823 of yacc.c */ -#line 1222 "parse-gram.c" +/* Line 822 of yacc.c */ +#line 1052 "parse-gram.c" break; default: break; @@ -1862,20 +1692,6 @@ yydestruct (yymsg, yytype, yyvaluep, yylocationp) } -/* Prevent warnings from -Wmissing-prototypes. */ -#ifdef YYPARSE_PARAM -#if defined __STDC__ || defined __cplusplus -int yyparse (void *YYPARSE_PARAM); -#else -int yyparse (); -#endif -#else /* ! YYPARSE_PARAM */ -#if defined __STDC__ || defined __cplusplus -int yyparse (void); -#else -int yyparse (); -#endif -#endif /* ! YYPARSE_PARAM */ /*----------. @@ -2009,7 +1825,7 @@ YYLTYPE yylloc; /* User initialization code. */ -/* Line 1594 of yacc.c */ +/* Line 1585 of yacc.c */ #line 106 "parse-gram.y" { /* Bison's grammar can initial empty locations, hence a default @@ -2018,8 +1834,8 @@ YYLTYPE yylloc; boundary_set (&yylloc.end, current_file, 1, 1); } -/* Line 1594 of yacc.c */ -#line 2023 "parse-gram.c" +/* Line 1585 of yacc.c */ +#line 1839 "parse-gram.c" yylsp[0] = yylloc; goto yysetstate; @@ -2213,7 +2029,7 @@ yyreduce: { case 6: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 245 "parse-gram.y" { code_props plain_code; @@ -2228,14 +2044,14 @@ yyreduce: case 7: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 254 "parse-gram.y" { debug_flag = true; } break; case 8: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 256 "parse-gram.y" { muscle_percent_define_insert ((yyvsp[(2) - (3)].uniqstr), (yylsp[(2) - (3)]), (yyvsp[(3) - (3)].chars), @@ -2245,14 +2061,14 @@ yyreduce: case 9: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 260 "parse-gram.y" { defines_flag = true; } break; case 10: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 262 "parse-gram.y" { defines_flag = true; @@ -2262,42 +2078,42 @@ yyreduce: case 11: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 266 "parse-gram.y" { error_verbose = true; } break; case 12: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 267 "parse-gram.y" { expected_sr_conflicts = (yyvsp[(2) - (2)].integer); } break; case 13: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 268 "parse-gram.y" { expected_rr_conflicts = (yyvsp[(2) - (2)].integer); } break; case 14: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 269 "parse-gram.y" { spec_file_prefix = (yyvsp[(2) - (2)].chars); } break; case 15: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 270 "parse-gram.y" { spec_file_prefix = (yyvsp[(3) - (3)].chars); } break; case 16: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 272 "parse-gram.y" { nondeterministic_parser = true; @@ -2307,7 +2123,7 @@ yyreduce: case 17: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 277 "parse-gram.y" { code_props action; @@ -2321,77 +2137,77 @@ yyreduce: case 18: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 285 "parse-gram.y" { language_argmatch ((yyvsp[(2) - (2)].chars), grammar_prio, (yylsp[(1) - (2)])); } break; case 19: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 286 "parse-gram.y" { add_param ("lex_param", (yyvsp[(2) - (2)].code), (yylsp[(2) - (2)])); } break; case 20: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 287 "parse-gram.y" { locations_flag = true; } break; case 21: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 288 "parse-gram.y" { spec_name_prefix = (yyvsp[(2) - (2)].chars); } break; case 22: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 289 "parse-gram.y" { spec_name_prefix = (yyvsp[(3) - (3)].chars); } break; case 23: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 290 "parse-gram.y" { no_lines_flag = true; } break; case 24: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 291 "parse-gram.y" { nondeterministic_parser = true; } break; case 25: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 292 "parse-gram.y" { spec_outfile = (yyvsp[(2) - (2)].chars); } break; case 26: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 293 "parse-gram.y" { spec_outfile = (yyvsp[(3) - (3)].chars); } break; case 27: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 294 "parse-gram.y" { add_param ("parse_param", (yyvsp[(2) - (2)].code), (yylsp[(2) - (2)])); } break; case 28: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 296 "parse-gram.y" { /* %pure-parser is deprecated in favor of `%define api.pure', so use @@ -2411,14 +2227,14 @@ yyreduce: case 29: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 310 "parse-gram.y" { version_check (&(yylsp[(2) - (2)]), (yyvsp[(2) - (2)].chars)); } break; case 30: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 312 "parse-gram.y" { char const *skeleton_user = (yyvsp[(2) - (2)].chars); @@ -2447,28 +2263,28 @@ yyreduce: case 31: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 335 "parse-gram.y" { token_table_flag = true; } break; case 32: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 336 "parse-gram.y" { report_flag |= report_states; } break; case 33: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 337 "parse-gram.y" { yacc_flag = true; } break; case 37: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 345 "parse-gram.y" { grammar_start_symbol_set ((yyvsp[(2) - (2)].symbol), (yylsp[(2) - (2)])); @@ -2477,7 +2293,7 @@ yyreduce: case 38: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 349 "parse-gram.y" { symbol_list *list; @@ -2489,7 +2305,7 @@ yyreduce: case 39: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 356 "parse-gram.y" { symbol_list *list; @@ -2501,7 +2317,7 @@ yyreduce: case 40: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 363 "parse-gram.y" { default_prec = true; @@ -2510,7 +2326,7 @@ yyreduce: case 41: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 367 "parse-gram.y" { default_prec = false; @@ -2519,7 +2335,7 @@ yyreduce: case 42: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 371 "parse-gram.y" { /* Do not invoke muscle_percent_code_grow here since it invokes @@ -2531,7 +2347,7 @@ yyreduce: case 43: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 378 "parse-gram.y" { muscle_percent_code_grow ((yyvsp[(2) - (3)].uniqstr), (yylsp[(2) - (3)]), (yyvsp[(3) - (3)].chars), (yylsp[(3) - (3)])); @@ -2541,21 +2357,21 @@ yyreduce: case 44: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 392 "parse-gram.y" {} break; case 45: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 393 "parse-gram.y" { muscle_code_grow ("union_name", (yyvsp[(1) - (1)].uniqstr), (yylsp[(1) - (1)])); } break; case 46: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 398 "parse-gram.y" { union_seen = true; @@ -2566,14 +2382,14 @@ yyreduce: case 47: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 409 "parse-gram.y" { current_class = nterm_sym; } break; case 48: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 410 "parse-gram.y" { current_class = unknown_sym; @@ -2583,14 +2399,14 @@ yyreduce: case 49: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 414 "parse-gram.y" { current_class = token_sym; } break; case 50: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 415 "parse-gram.y" { current_class = unknown_sym; @@ -2600,7 +2416,7 @@ yyreduce: case 51: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 420 "parse-gram.y" { symbol_list *list; @@ -2613,7 +2429,7 @@ yyreduce: case 52: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 431 "parse-gram.y" { symbol_list *list; @@ -2630,126 +2446,126 @@ yyreduce: case 53: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 445 "parse-gram.y" { (yyval.assoc) = left_assoc; } break; case 54: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 446 "parse-gram.y" { (yyval.assoc) = right_assoc; } break; case 55: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 447 "parse-gram.y" { (yyval.assoc) = non_assoc; } break; case 56: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 451 "parse-gram.y" { current_type = NULL; } break; case 57: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 452 "parse-gram.y" { current_type = (yyvsp[(1) - (1)].uniqstr); tag_seen = true; } break; case 58: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 458 "parse-gram.y" { (yyval.list) = symbol_list_sym_new ((yyvsp[(1) - (1)].symbol), (yylsp[(1) - (1)])); } break; case 59: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 460 "parse-gram.y" { (yyval.list) = symbol_list_prepend ((yyvsp[(1) - (2)].list), symbol_list_sym_new ((yyvsp[(2) - (2)].symbol), (yylsp[(2) - (2)]))); } break; case 60: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 464 "parse-gram.y" { (yyval.symbol) = (yyvsp[(1) - (1)].symbol); } break; case 61: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 465 "parse-gram.y" { (yyval.symbol) = (yyvsp[(1) - (2)].symbol); symbol_user_token_number_set ((yyvsp[(1) - (2)].symbol), (yyvsp[(2) - (2)].integer), (yylsp[(2) - (2)])); } break; case 62: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 471 "parse-gram.y" { (yyval.list) = symbol_list_sym_new ((yyvsp[(1) - (1)].symbol), (yylsp[(1) - (1)])); } break; case 63: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 473 "parse-gram.y" { (yyval.list) = symbol_list_prepend ((yyvsp[(1) - (2)].list), symbol_list_sym_new ((yyvsp[(2) - (2)].symbol), (yylsp[(2) - (2)]))); } break; case 64: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 477 "parse-gram.y" { (yyval.list) = (yyvsp[(1) - (1)].list); } break; case 65: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 478 "parse-gram.y" { (yyval.list) = symbol_list_prepend ((yyvsp[(1) - (2)].list), (yyvsp[(2) - (2)].list)); } break; case 66: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 482 "parse-gram.y" { (yyval.list) = symbol_list_sym_new ((yyvsp[(1) - (1)].symbol), (yylsp[(1) - (1)])); } break; case 67: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 483 "parse-gram.y" { (yyval.list) = symbol_list_type_new ((yyvsp[(1) - (1)].uniqstr), (yylsp[(1) - (1)])); } break; case 68: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 484 "parse-gram.y" { (yyval.list) = symbol_list_default_tagged_new ((yylsp[(1) - (1)])); } break; case 69: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 485 "parse-gram.y" { (yyval.list) = symbol_list_default_tagless_new ((yylsp[(1) - (1)])); } break; case 70: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 491 "parse-gram.y" { current_type = (yyvsp[(1) - (1)].uniqstr); @@ -2759,7 +2575,7 @@ yyreduce: case 71: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 496 "parse-gram.y" { symbol_class_set ((yyvsp[(1) - (1)].symbol), current_class, (yylsp[(1) - (1)]), true); @@ -2769,7 +2585,7 @@ yyreduce: case 72: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 501 "parse-gram.y" { symbol_class_set ((yyvsp[(1) - (2)].symbol), current_class, (yylsp[(1) - (2)]), true); @@ -2780,7 +2596,7 @@ yyreduce: case 73: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 507 "parse-gram.y" { symbol_class_set ((yyvsp[(1) - (2)].symbol), current_class, (yylsp[(1) - (2)]), true); @@ -2791,7 +2607,7 @@ yyreduce: case 74: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 513 "parse-gram.y" { symbol_class_set ((yyvsp[(1) - (3)].symbol), current_class, (yylsp[(1) - (3)]), true); @@ -2803,7 +2619,7 @@ yyreduce: case 81: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 543 "parse-gram.y" { yyerrok; @@ -2812,14 +2628,14 @@ yyreduce: case 82: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 549 "parse-gram.y" { current_lhs ((yyvsp[(1) - (2)].symbol), (yylsp[(1) - (2)]), (yyvsp[(2) - (2)].named_ref)); } break; case 83: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 550 "parse-gram.y" { /* Free the current lhs. */ @@ -2829,21 +2645,21 @@ yyreduce: case 84: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 557 "parse-gram.y" { grammar_current_rule_end ((yylsp[(1) - (1)])); } break; case 85: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 558 "parse-gram.y" { grammar_current_rule_end ((yylsp[(3) - (3)])); } break; case 87: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 564 "parse-gram.y" { grammar_current_rule_begin (current_lhs_symbol, current_lhs_location, current_lhs_named_ref); } @@ -2851,77 +2667,77 @@ yyreduce: case 88: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 567 "parse-gram.y" { grammar_current_rule_symbol_append ((yyvsp[(2) - (3)].symbol), (yylsp[(2) - (3)]), (yyvsp[(3) - (3)].named_ref)); } break; case 89: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 569 "parse-gram.y" { grammar_current_rule_action_append ((yyvsp[(2) - (3)].code), (yylsp[(2) - (3)]), (yyvsp[(3) - (3)].named_ref)); } break; case 90: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 571 "parse-gram.y" { grammar_current_rule_prec_set ((yyvsp[(3) - (3)].symbol), (yylsp[(3) - (3)])); } break; case 91: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 573 "parse-gram.y" { grammar_current_rule_dprec_set ((yyvsp[(3) - (3)].integer), (yylsp[(3) - (3)])); } break; case 92: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 575 "parse-gram.y" { grammar_current_rule_merge_set ((yyvsp[(3) - (3)].uniqstr), (yylsp[(3) - (3)])); } break; case 93: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 579 "parse-gram.y" { (yyval.named_ref) = 0; } break; case 94: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 581 "parse-gram.y" { (yyval.named_ref) = named_ref_new((yyvsp[(1) - (1)].uniqstr), (yylsp[(1) - (1)])); } break; case 96: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 593 "parse-gram.y" { (yyval.uniqstr) = uniqstr_new ((yyvsp[(1) - (1)].chars)); } break; case 97: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 598 "parse-gram.y" { (yyval.chars) = ""; } break; case 98: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 599 "parse-gram.y" { (yyval.chars) = (yyvsp[(1) - (1)].uniqstr); } break; case 100: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 610 "parse-gram.y" { code_props plain_code; @@ -2935,14 +2751,14 @@ yyreduce: case 101: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 630 "parse-gram.y" { (yyval.symbol) = symbol_from_uniqstr ((yyvsp[(1) - (1)].uniqstr), (yylsp[(1) - (1)])); } break; case 102: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 632 "parse-gram.y" { (yyval.symbol) = symbol_get (char_name ((yyvsp[(1) - (1)].character)), (yylsp[(1) - (1)])); @@ -2953,14 +2769,14 @@ yyreduce: case 103: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 640 "parse-gram.y" { (yyval.symbol) = symbol_from_uniqstr ((yyvsp[(1) - (1)].uniqstr), (yylsp[(1) - (1)])); } break; case 106: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 652 "parse-gram.y" { (yyval.symbol) = symbol_get (quotearg_style (c_quoting_style, (yyvsp[(1) - (1)].chars)), (yylsp[(1) - (1)])); @@ -2970,7 +2786,7 @@ yyreduce: case 108: -/* Line 1810 of yacc.c */ +/* Line 1801 of yacc.c */ #line 661 "parse-gram.y" { code_props plain_code; @@ -2984,8 +2800,8 @@ yyreduce: -/* Line 1810 of yacc.c */ -#line 2989 "parse-gram.c" +/* Line 1801 of yacc.c */ +#line 2805 "parse-gram.c" default: break; } if (yychar_backup != yychar) @@ -3234,7 +3050,7 @@ yyreturn: -/* Line 2071 of yacc.c */ +/* Line 2062 of yacc.c */ #line 671 "parse-gram.y" diff --git a/src/parse-gram.h b/src/parse-gram.h index 2beec477..97dbfcf3 100644 --- a/src/parse-gram.h +++ b/src/parse-gram.h @@ -1,4 +1,4 @@ -/* A Bison parser, made by GNU Bison 2.5.1_rc2. */ +/* A Bison parser, made by GNU Bison 2.5.1.19-ced26-dirty. */ /* Bison interface for Yacc-like parsers in C @@ -30,6 +30,15 @@ This special exception was added by the Free Software Foundation in version 2.2 of Bison. */ +#ifndef GRAM__________SRC_PARSE_GRAM_H +# define GRAM__________SRC_PARSE_GRAM_H +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 1 +#endif +#if YYDEBUG +extern int gram_debug; +#endif /* Tokens. */ #ifndef YYTOKENTYPE @@ -155,12 +164,11 @@ - #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED typedef union YYSTYPE { -/* Line 2072 of yacc.c */ +/* Line 2063 of yacc.c */ #line 114 "parse-gram.y" symbol *symbol; @@ -175,16 +183,14 @@ typedef union YYSTYPE -/* Line 2072 of yacc.c */ -#line 180 "parse-gram.h" +/* Line 2063 of yacc.c */ +#line 188 "parse-gram.h" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define YYSTYPE_IS_DECLARED 1 #endif - - #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED typedef struct YYLTYPE { @@ -198,5 +204,19 @@ typedef struct YYLTYPE # define YYLTYPE_IS_TRIVIAL 1 #endif +#ifdef YYPARSE_PARAM +#if defined __STDC__ || defined __cplusplus +int gram_parse (void *YYPARSE_PARAM); +#else +int gram_parse (); +#endif +#else /* ! YYPARSE_PARAM */ +#if defined __STDC__ || defined __cplusplus +int gram_parse (void); +#else +int gram_parse (); +#endif +#endif /* ! YYPARSE_PARAM */ +#endif /* !GRAM__________SRC_PARSE_GRAM_H */ From 55f48c48314bf63e224f5cbfad7f9c52b6d78df7 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sun, 17 Jun 2012 18:01:14 +0200 Subject: [PATCH 11/15] tests: factor the declaration/definition of yyerror and yylex. * tests/local.at (AT_YYERROR_DECLARE, AT_YYERROR_DECLARE_EXTERN) (AT_YYERROR_DEFINE, AT_YYLEX_DECLARE, AT_YYLEX_DECLARE_EXTERN) (AT_YYLEX_DEFINE): New. Must be used inside AT_BISON_OPTION_PUSHDEFS/POPDEFS pair. * tests/actions.at, tests/conflicts.at, tests/glr-regression.at, * tests/headers.at, tests/input.at, tests/named-refs.at, * tests/regression.at, tests/skeletons.at, tests/synclines.at, * tests/torture.at: Use them. --- tests/actions.at | 265 ++++++++++------------------------- tests/conflicts.at | 59 ++------ tests/glr-regression.at | 303 ++++++++++++++-------------------------- tests/headers.at | 8 +- tests/input.at | 12 +- tests/local.at | 82 +++++++++-- tests/named-refs.at | 24 ++-- tests/regression.at | 160 ++++++++------------- tests/skeletons.at | 11 +- tests/synclines.at | 26 ++-- tests/torture.at | 27 ++-- 11 files changed, 378 insertions(+), 599 deletions(-) diff --git a/tests/actions.at b/tests/actions.at index 22c3aa25..cfac2992 100644 --- a/tests/actions.at +++ b/tests/actions.at @@ -28,14 +28,13 @@ AT_SETUP([Mid-rule actions]) # instead of being attached to the empty rule dedicated to this # action. +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([[input.y]], [[%error-verbose %debug %{ -# include -# include - static void yyerror (const char *msg); - static int yylex (void); +]AT_YYERROR_DECLARE[ +]AT_YYLEX_DECLARE[ %} %% exp: { putchar ('0'); } @@ -51,28 +50,15 @@ exp: { putchar ('0'); } { putchar ('\n'); } ; %% -static int -yylex (void) -{ - static char const input[] = "123456789"; - static size_t toknum; - if (! (toknum < sizeof input)) - abort (); - return input[toknum++]; -} - -static void -yyerror (const char *msg) -{ - fprintf (stderr, "%s\n", msg); -} - +]AT_YYERROR_DEFINE[ +]AT_YYLEX_DEFINE(123456789)[ int main (void) { return yyparse (); } ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([-d -v -o input.c input.y]) AT_COMPILE([input]) @@ -92,14 +78,13 @@ AT_CLEANUP AT_SETUP([Exotic Dollars]) +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([[input.y]], [[%error-verbose %debug %{ -# include -# include - static void yyerror (const char *msg); - static int yylex (void); +]AT_YYERROR_DECLARE[ +]AT_YYLEX_DECLARE[ # define USE(Var) %} @@ -130,21 +115,8 @@ sum_of_the_five_previous_values: ; %% -static int -yylex (void) -{ - static int called; - if (called++) - abort (); - return EOF; -} - -static void -yyerror (const char *msg) -{ - fprintf (stderr, "%s\n", msg); -} - +]AT_YYERROR_DEFINE[ +]AT_YYLEX_DEFINE([])[ int main (void) { @@ -164,9 +136,9 @@ AT_PARSER_CHECK([./input], 0, AT_DATA_GRAMMAR([[input.y]], [[ %{ -# include - static int yylex (void); - static void yyerror (char const *msg); +#include +]AT_YYERROR_DECLARE[ +]AT_YYLEX_DECLARE[ typedef struct { int val; } stype; # define YYSTYPE stype %} @@ -185,12 +157,7 @@ yylex (void) return 0; } -static void -yyerror (char const *msg) -{ - fprintf (stderr, "%s\n", msg); -} - +]AT_YYERROR_DEFINE[ int main (void) { @@ -204,6 +171,7 @@ AT_PARSER_CHECK([[./input]], [[0]], [[6 ]]) +AT_BISON_OPTION_POPDEFS AT_CLEANUP @@ -245,7 +213,7 @@ AT_LALR1_CC_IF([%define global_tokens_and_yystype]) m4_ifval([$6], [[%code provides {]], [[%code {]]) AT_LALR1_CC_IF([typedef yy::location YYLTYPE;]) [static int yylex (]AT_LEX_FORMALS[); -]AT_LALR1_CC_IF([], [static void yyerror (const char *msg);]) +]AT_LALR1_CC_IF([], [AT_YYERROR_DECLARE]) [} ]m4_ifval([$6], [%type '(' 'x' 'y' ')' ';' thing line input END])[ @@ -593,7 +561,8 @@ Parsing FAILED (status 2). ]]) ]) -]) +AT_BISON_OPTION_POPDEFS +])# _AT_CHECK_PRINTER_AND_DESTRUCTOR # AT_CHECK_PRINTER_AND_DESTRUCTOR([BISON-OPTIONS], [UNION-FLAG], [SKIP_FLAG]) @@ -632,7 +601,7 @@ AT_CHECK_PRINTER_AND_DESTRUCTOR([%glr-parser], [with union]) # called for $end, and that $$ and @$ work correctly. AT_SETUP([Default tagless %printer and %destructor]) - +AT_BISON_OPTION_PUSHDEFS([%locations]) AT_DATA_GRAMMAR([[input.y]], [[%error-verbose %debug @@ -645,8 +614,8 @@ AT_DATA_GRAMMAR([[input.y]], %{ # include # include - static void yyerror (const char *msg); - static int yylex (void); +]AT_YYLEX_DECLARE[ +]AT_YYERROR_DECLARE[ # define USE(SYM) %} @@ -677,25 +646,8 @@ AT_DATA_GRAMMAR([[input.y]], start: 'a' 'b' 'c' 'd' 'e' { $$ = 'S'; USE(($1, $2, $3, $4, $5)); } ; %% - -static int -yylex (void) -{ - static char const input[] = "abcd"; - static size_t toknum; - if (! (toknum < sizeof input)) - abort (); - yylval = input[toknum++]; - yylloc.first_line = yylloc.last_line = 1; - yylloc.first_column = yylloc.last_column = toknum; - return yylval; -} - -static void -yyerror (const char *msg) -{ - fprintf (stderr, "%s\n", msg); -} +]AT_YYERROR_DEFINE[ +]AT_YYLEX_DEFINE([abcd], [[yylval = res]])[ int main (void) @@ -741,6 +693,7 @@ Cleanup: discarding lookahead token $end (1.5-1.5: ) Stack now 0 ]]) +AT_BISON_OPTION_POPDEFS AT_CLEANUP @@ -750,7 +703,7 @@ AT_CLEANUP ## ------------------------------------------------------ ## AT_SETUP([Default tagged and per-type %printer and %destructor]) - +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([[input.y]], [[%error-verbose %debug @@ -758,8 +711,8 @@ AT_DATA_GRAMMAR([[input.y]], %{ # include # include - static void yyerror (const char *msg); - static int yylex (void); +]AT_YYERROR_DECLARE[ +]AT_YYLEX_DECLARE[ # define USE(SYM) %} @@ -805,22 +758,8 @@ start: ; %% - -static int -yylex (void) -{ - static char const input[] = "abcdef"; - static size_t toknum; - if (! (toknum < sizeof input)) - abort (); - return input[toknum++]; -} - -static void -yyerror (const char *msg) -{ - fprintf (stderr, "%s\n", msg); -} +]AT_YYERROR_DEFINE[ +]AT_YYLEX_DEFINE([abcdef])[ int main (void) @@ -878,6 +817,7 @@ Cleanup: discarding lookahead token $end () Stack now 0 ]]) +AT_BISON_OPTION_POPDEFS AT_CLEANUP @@ -895,6 +835,7 @@ m4_define([_AT_CHECK_DEFAULT_PRINTER_AND_DESTRUCTOR_FOR_END_TOKEN], [m4_pushdef([kind], []) m4_pushdef([not_kind], [*])], [m4_pushdef([kind], [*]) m4_pushdef([not_kind], [])]) +AT_BISON_OPTION_PUSHDEFS([%locations]) AT_DATA_GRAMMAR([[input]]$1[[.y]], [[%error-verbose %debug @@ -907,8 +848,8 @@ AT_DATA_GRAMMAR([[input]]$1[[.y]], %{ # include # include - static void yyerror (const char *msg); - static int yylex (void); +]AT_YYERROR_DECLARE[ +]AT_YYLEX_DECLARE[ # define USE(SYM) %} @@ -950,12 +891,7 @@ yylex (void) yylloc.first_column = yylloc.last_column = 1; return 0; } - -static void -yyerror (const char *msg) -{ - fprintf (stderr, "%s\n", msg); -} +]AT_YYERROR_DEFINE[ int main (void) @@ -964,6 +900,7 @@ main (void) return yyparse (); } ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([-o input$1.c input$1.y]) AT_COMPILE([input$1]) @@ -1010,15 +947,15 @@ AT_SETUP([Default %printer and %destructor are not for error or $undefined]) # semantic value, which would be initialized from the lookahead, which # would be destroyed separately. # - For $undefined, who knows what the semantic value would be. - +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([[input.y]], [[%debug %{ # include # include - static void yyerror (const char *msg); - static int yylex (void); +]AT_YYERROR_DECLARE[ +]AT_YYLEX_DECLARE[ # define USE(SYM) %} @@ -1039,24 +976,8 @@ start: ; %% - -static int -yylex (void) -{ - static char const input[] = "abd"; - static size_t toknum; - if (! (toknum < sizeof input)) - abort (); - yylval = input[toknum++]; - return yylval; -} - -static void -yyerror (const char *msg) -{ - fprintf (stderr, "%s\n", msg); -} - +]AT_YYERROR_DEFINE[ +]AT_YYLEX_DEFINE([abd], [yylval = res])[ int main (void) { @@ -1064,6 +985,7 @@ main (void) return yyparse (); } ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([-o input.c input.y]) AT_COMPILE([input]) @@ -1125,14 +1047,15 @@ AT_SETUP([Default %printer and %destructor are not for $accept]) # true for $undefined and the error token, so there are three warnings for # %printer and three for %destructor.) +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([[input.y]], [[%debug /* So that %printer is actually compiled. */ %{ # include # include - static void yyerror (const char *msg); - static int yylex (void); +]AT_YYERROR_DECLARE[ +]AT_YYLEX_DECLARE[ # define USE(SYM) %} @@ -1153,28 +1076,15 @@ AT_DATA_GRAMMAR([[input.y]], start: { USE($$); } ; %% - -static int -yylex (void) -{ - static int called; - if (called++) - abort (); - return 0; -} - -static void -yyerror (const char *msg) -{ - fprintf (stderr, "%s\n", msg); -} - +]AT_YYERROR_DEFINE[ +]AT_YYLEX_DEFINE([])[ int main (void) { return yyparse (); } ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([-o input.c input.y]) AT_COMPILE([input]) @@ -1189,14 +1099,15 @@ AT_CLEANUP AT_SETUP([Default %printer and %destructor for mid-rule values]) +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([[input.y]], [[%debug /* So that %printer is actually compiled. */ %{ # include # include - static void yyerror (const char *msg); - static int yylex (void); +]AT_YYERROR_DECLARE[ +]AT_YYLEX_DECLARE[ # define USE(SYM) # define YYLTYPE int # define YYLLOC_DEFAULT(Current, Rhs, N) (void)(Rhs) @@ -1220,22 +1131,8 @@ start: ; %% - -static int -yylex (void) -{ - static int called; - if (called++) - abort (); - return 0; -} - -static void -yyerror (const char *msg) -{ - fprintf (stderr, "%s\n", msg); -} - +]AT_YYERROR_DEFINE[ +]AT_YYLEX_DEFINE([])[ int main (void) { @@ -1243,6 +1140,7 @@ main (void) return yyparse (); } ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([-o input.c input.y], 0,, [[input.y:33.3-23: warning: unset value: $$ @@ -1296,15 +1194,15 @@ AT_CLEANUP # Bison once forgot to check for @$ in actions other than semantic actions. # AT_CHECK_ACTION_LOCATIONS(ACTION-DIRECTIVE) -# ------------------------------------------------------- +# ------------------------------------------- m4_define([AT_CHECK_ACTION_LOCATIONS], [AT_SETUP([[@$ in ]$1[ implies %locations]]) - +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([[input.y]], [[%code { #include - static int yylex (void); - static void yyerror (char const *msg); +]AT_YYERROR_DECLARE[ +]AT_YYLEX_DECLARE[ } %debug @@ -1325,12 +1223,7 @@ yylex (void) return 0; } -static void -yyerror (char const *msg) -{ - fprintf (stderr, "%s\n", msg); -} - +]AT_YYERROR_DEFINE[ int main (void) { @@ -1340,7 +1233,7 @@ main (void) AT_BISON_CHECK([[-o input.c input.y]]) AT_COMPILE([[input]]) - +AT_BISON_OPTION_POPDEFS AT_CLEANUP]) AT_CHECK_ACTION_LOCATIONS([[%initial-action]]) @@ -1357,7 +1250,7 @@ AT_SETUP([[Fix user actions without a trailing semicolon]]) # This feature is undocumented, but we accidentally broke it in 2.3a, # and there was a complaint at: # . - +AT_BISON_OPTION_PUSHDEFS AT_DATA([input.y], [[%% start: test2 test1 test0 testc; @@ -1407,6 +1300,7 @@ no_semi []"broken\" $ @ $$ @$ [];\ string;"} ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([[-o input.c input.y]], [0], [], [[input.y:8.48: warning: a ';' might be needed at the end of action code @@ -1462,13 +1356,14 @@ AT_CLEANUP AT_SETUP([[Destroying lookahead assigned by semantic action]]) +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([input.y], [[ %code { #include #include - static void yyerror (char const *); - static int yylex (void); +]AT_YYERROR_DECLARE[ +]AT_YYLEX_DECLARE[ #define USE(Var) } @@ -1496,27 +1391,15 @@ accept: /*empty*/ { } ; %% - -static void -yyerror (char const *msg) -{ - fprintf (stderr, "%s\n", msg); -} - -static int -yylex (void) -{ - static char const *input = "a"; - return *input++; -} - +]AT_YYERROR_DEFINE[ +]AT_YYLEX_DEFINE([a])[ int main (void) { return yyparse (); } ]]) - +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([[-o input.c input.y]]) AT_COMPILE([[input]]) AT_PARSER_CHECK([[./input]], [[0]], [], @@ -1532,6 +1415,8 @@ AT_CLEANUP AT_SETUP([[YYBACKUP]]) +AT_BISON_OPTION_PUSHDEFS([%pure-parser]) + AT_DATA_GRAMMAR([input.y], [[ %error-verbose @@ -1542,7 +1427,7 @@ AT_DATA_GRAMMAR([input.y], # include # include - static void yyerror (const char *msg); + ]AT_YYERROR_DECLARE[ static int yylex (YYSTYPE *yylval); } %% @@ -1557,6 +1442,7 @@ exp: ; %% +]AT_YYERROR_DEFINE[ static int yylex (YYSTYPE *yylval) { @@ -1567,12 +1453,6 @@ yylex (YYSTYPE *yylval) return input[toknum++]; } -static void -yyerror (const char *msg) -{ - fprintf (stderr, "%s\n", msg); -} - int main (void) { @@ -1580,6 +1460,7 @@ main (void) return yyparse (); } ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([[-o input.c input.y]]) AT_COMPILE([[input]]) diff --git a/tests/conflicts.at b/tests/conflicts.at index 76cb6aa9..54df0511 100644 --- a/tests/conflicts.at +++ b/tests/conflicts.at @@ -50,6 +50,7 @@ AT_CLEANUP AT_SETUP([%nonassoc and eof]) +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([input.y], [[ %{ @@ -58,12 +59,7 @@ AT_DATA_GRAMMAR([input.y], #include #define YYERROR_VERBOSE 1 -static void -yyerror (const char *msg) -{ - fprintf (stderr, "%s\n", msg); -} - +]AT_YYERROR_DEFINE[ /* The current argument. */ static const char *input; @@ -93,6 +89,7 @@ main (int argc, const char *argv[]) return yyparse (); } ]]) +AT_BISON_OPTION_POPDEFS m4_pushdef([AT_NONASSOC_AND_EOF_CHECK], [AT_BISON_CHECK([$1[ -o input.c input.y]]) @@ -171,7 +168,7 @@ AT_SKEL_JAVA_IF([AT_DATA], [AT_DATA_GRAMMAR])([input.y], #include ]], [[ #include #include - void yyerror (char const *msg);]])[ + ]AT_YYERROR_DECLARE])[ ]AT_YYLEX_PROTOTYPE[; #define USE(Var) } @@ -212,31 +209,11 @@ public Object getLVal () *lvalp = 1; return *input++; }]])[ - -/*----------. -| yyerror. | -`----------*/]AT_SKEL_JAVA_IF([[ - -public void yyerror (String msg) -{ - System.err.println (msg); -} - +]AT_YYERROR_DEFINE[ +]AT_SKEL_JAVA_IF([[ }; -%%]], [AT_SKEL_CC_IF([[ - -void -yy::parser::error (const yy::location &, std::string const &msg) -{ - std::cerr << msg << std::endl; -}]], [[ - -void -yyerror (char const *msg) -{ - fprintf (stderr, "%s\n", msg); -}]])])[ +%%]])[ /*-------. | main. | @@ -471,12 +448,12 @@ AT_CLEANUP # with minimal LR parser tables. AT_SETUP([[LAC: %nonassoc requires splitting canonical LR states]]) - +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([[input.y]], [[%code { #include - void yyerror (char const *); - int yylex (void); + ]AT_YYERROR_DECLARE[ + ]AT_YYLEX_DECLARE[ } %error-verbose @@ -513,19 +490,8 @@ look: reduce-nonassoc: %prec 'a'; %% - -void -yyerror (char const *msg) -{ - fprintf (stderr, "%s\n", msg); -} - -int -yylex (void) -{ - char const *input = "aaa"; - return *input++; -} +]AT_YYERROR_DEFINE[ +]AT_YYLEX_DEFINE([aaa])[ int main (void) @@ -533,6 +499,7 @@ main (void) return yyparse (); } ]]) +AT_BISON_OPTION_POPDEFS # Show canonical LR's failure. AT_BISON_CHECK([[-Dlr.type=canonical-lr -o input.c input.y]], diff --git a/tests/glr-regression.at b/tests/glr-regression.at index 0cbffd19..9c534631 100644 --- a/tests/glr-regression.at +++ b/tests/glr-regression.at @@ -24,6 +24,7 @@ AT_BANNER([[GLR Regression Tests]]) AT_SETUP([Badly Collapsed GLR States]) +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([glr-regr1.y], [[/* Regression Test: Improper state compression */ /* Reported by Scott McPeak */ @@ -34,8 +35,8 @@ AT_DATA_GRAMMAR([glr-regr1.y], #define YYSTYPE int static YYSTYPE exprMerge (YYSTYPE x0, YYSTYPE x1); -int yylex (void); -void yyerror (char const *msg); +]AT_YYLEX_DECLARE[ +]AT_YYERROR_DECLARE[ %} @@ -71,12 +72,7 @@ main (void) return yyparse (); } -void -yyerror (char const *msg) -{ - fprintf (stderr, "%s\n", msg); -} - +]AT_YYERROR_DEFINE[ int yylex (void) @@ -94,6 +90,7 @@ yylex (void) } } ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([[-o glr-regr1.c glr-regr1.y]], 0, [], [glr-regr1.y: conflicts: 1 shift/reduce @@ -119,6 +116,7 @@ AT_CLEANUP AT_SETUP([Improper handling of embedded actions and dollar(-N) in GLR parsers]) +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([glr-regr2a.y], [[/* Regression Test: Improper handling of embedded actions and $-N */ /* Reported by S. Eken */ @@ -130,8 +128,8 @@ AT_DATA_GRAMMAR([glr-regr2a.y], #include #include #include - int yylex (void); - void yyerror (char const *); + ]AT_YYLEX_DECLARE[ + ]AT_YYERROR_DECLARE[ %} %glr-parser @@ -171,7 +169,7 @@ var_printer: 'v' { printf ("Variable: '%s'\n", $-1); } %% - +]AT_YYERROR_DEFINE[ FILE *input; int @@ -181,7 +179,8 @@ yylex (void) char *s; if (feof (stdin)) abort (); - switch (fscanf (input, " %1[a-z,]", buf)) { + switch (fscanf (input, " %1[a-z,]", buf)) + { case 1: return buf[0]; case EOF: @@ -199,11 +198,6 @@ yylex (void) return 'V'; } -void -yyerror (char const *s) -{ printf ("%s\n", s); -} - int main (int argc, char **argv) { @@ -212,6 +206,7 @@ main (int argc, char **argv) return yyparse (); } ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([[-o glr-regr2a.c glr-regr2a.y]], 0, [], [glr-regr2a.y: conflicts: 2 shift/reduce @@ -238,6 +233,7 @@ AT_CLEANUP AT_SETUP([Improper merging of GLR delayed action sets]) +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([glr-regr3.y], [[/* Regression Test: Improper merging of GLR delayed action sets. */ /* Reported by M. Rosien */ @@ -248,8 +244,8 @@ AT_DATA_GRAMMAR([glr-regr3.y], #include static int MergeRule (int x0, int x1); -static void yyerror (char const * s); -int yylex (void); +]AT_YYERROR_DECLARE[ +]AT_YYLEX_DECLARE[ #define RULE(x) (1 << (x)) @@ -290,13 +286,12 @@ NT6 : P1 NT1 O1 T3 P2 { $$ = RULE(11) | $2; } %merge %% -static int MergeRule (int x0, int x1) { +static int +MergeRule (int x0, int x1) +{ return x0 | x1; } - -static void yyerror(char const * s) { - fprintf(stderr,"error: %s\n",s); -} +]AT_YYERROR_DEFINE[ FILE *input = YY_NULL; @@ -320,12 +315,15 @@ int yylex (void) return BAD_CHAR; } -int main(int argc, char* argv[]) { +int +main(int argc, char* argv[]) +{ input = stdin; if (argc == 2 && !(input = fopen (argv[1], "r"))) return 3; return yyparse (); } ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([[-o glr-regr3.c glr-regr3.y]], 0, [], [glr-regr3.y: conflicts: 1 shift/reduce, 1 reduce/reduce @@ -347,6 +345,7 @@ AT_CLEANUP AT_SETUP([Duplicate representation of merged trees]) +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([glr-regr4.y], [[ %union { char *ptr; } @@ -359,8 +358,8 @@ AT_DATA_GRAMMAR([glr-regr4.y], #include static char *merge (YYSTYPE, YYSTYPE); static char *make_value (char const *, char const *); - static void yyerror (char const *); - static int yylex (void); + ]AT_YYERROR_DECLARE[ + ]AT_YYLEX_DECLARE[ static char *ptrs[100]; static char **ptrs_next = ptrs; %} @@ -384,16 +383,8 @@ A2: 'a' { $$ = make_value ("A2", "'a'"); } ; B: 'a' { $$ = make_value ("B", "'a'"); } ; %% - -static int -yylex (void) -{ - static char const input[] = "a"; - static size_t toknum; - if (! (toknum < sizeof input)) - abort (); - return input[toknum++]; -} +]AT_YYERROR_DEFINE[ +]AT_YYLEX_DEFINE([a])[ int main (void) @@ -423,13 +414,8 @@ merge (YYSTYPE s1, YYSTYPE s2) sprintf (value, format, s1.ptr, s2.ptr); return value; } - -static void -yyerror (char const *msg) -{ - fprintf (stderr, "%s\n", msg); -} ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([[-o glr-regr4.c glr-regr4.y]], 0, [], [glr-regr4.y: conflicts: 1 reduce/reduce @@ -450,13 +436,14 @@ AT_CLEANUP AT_SETUP([User destructor for unresolved GLR semantic value]) +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([glr-regr5.y], [[ %{ #include #include - static void yyerror (char const *); - static int yylex (void); + ]AT_YYERROR_DECLARE[ + ]AT_YYLEX_DECLARE[ enum { MAGIC_VALUE = -1057808125 }; /* originally chosen at random */ %} @@ -480,29 +467,15 @@ start: ; %% - -static int -yylex (void) -{ - static char const input[] = "a"; - static size_t toknum; - if (! (toknum < sizeof input)) - abort (); - return input[toknum++]; -} - -static void -yyerror (char const *msg) -{ - fprintf (stderr, "%s\n", msg); -} - +]AT_YYLEX_DEFINE(a)[ +]AT_YYERROR_DEFINE[ int main (void) { return yyparse () != 1; } ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([[-o glr-regr5.c glr-regr5.y]], 0, [], [glr-regr5.y: conflicts: 1 reduce/reduce @@ -523,13 +496,14 @@ AT_CLEANUP AT_SETUP([User destructor after an error during a split parse]) +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([glr-regr6.y], [[ %{ #include #include - static void yyerror (char const *); - static int yylex (void); + ]AT_YYERROR_DECLARE[ + ]AT_YYLEX_DECLARE[ %} %glr-parser @@ -556,18 +530,14 @@ yylex (void) return input[toknum++]; } -static void -yyerror (char const *msg) -{ - fprintf (stderr, "%s\n", msg); -} - +]AT_YYERROR_DEFINE[ int main (void) { return yyparse () != 1; } ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([[-o glr-regr6.c glr-regr6.y]], 0, [], [glr-regr6.y: conflicts: 1 reduce/reduce @@ -590,13 +560,14 @@ AT_CLEANUP AT_SETUP([Duplicated user destructor for lookahead]) +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([glr-regr7.y], [[ %{ #include #include - static void yyerror (char const *); - static int yylex (void); + ]AT_YYERROR_DECLARE[ + ]AT_YYLEX_DECLARE[ #define YYSTACKEXPANDABLE 0 typedef struct count_node { int count; @@ -641,12 +612,7 @@ yylex (void) return 'a'; } -static void -yyerror (char const *msg) -{ - fprintf (stderr, "%s\n", msg); -} - +]AT_YYERROR_DEFINE[ int main (void) { @@ -660,6 +626,7 @@ main (void) return status; } ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([[-o glr-regr7.c glr-regr7.y]], 0, [], [glr-regr7.y: conflicts: 2 reduce/reduce @@ -682,14 +649,15 @@ AT_CLEANUP AT_SETUP([Incorrectly initialized location for empty right-hand side in GLR]) +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([glr-regr8.y], [[ %{ #include #include - static void yyerror (char const *); - static int yylex (void); - static void yyerror (char const *msg); + ]AT_YYERROR_DECLARE[ + ]AT_YYLEX_DECLARE[ + ]AT_YYERROR_DECLARE[ %} %token T_CONSTANT @@ -723,12 +691,7 @@ OptSignalWord : /* empty */ %% -void -yyerror (char const *msg) -{ - fprintf (stderr, "%s\n", msg); -} - +]AT_YYERROR_DEFINE[ static int lexIndex; int yylex (void) @@ -758,6 +721,7 @@ main (void) return 0; } ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([[-o glr-regr8.c glr-regr8.y]], 0, [], [glr-regr8.y: conflicts: 1 reduce/reduce @@ -780,13 +744,14 @@ AT_CLEANUP AT_SETUP([No users destructors if stack 0 deleted]) +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([glr-regr9.y], [[ %{ # include # include - static void yyerror (char const *); - static int yylex (void); + ]AT_YYERROR_DECLARE[ + ]AT_YYLEX_DECLARE[ # define YYSTACKEXPANDABLE 0 static int tokens = 0; static int destructors = 0; @@ -822,12 +787,7 @@ yylex (void) return 'a'; } -static void -yyerror (char const *msg) -{ - fprintf (stderr, "%s\n", msg); -} - +]AT_YYERROR_DEFINE[ int main (void) { @@ -841,6 +801,7 @@ main (void) return !exit_status; } ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([[-o glr-regr9.c glr-regr9.y]], 0, [], [glr-regr9.y: conflicts: 1 reduce/reduce @@ -860,13 +821,14 @@ AT_CLEANUP AT_SETUP([Corrupted semantic options if user action cuts parse]) +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([glr-regr10.y], [[ %{ # include # include - static void yyerror (char const *); - static int yylex (void); + ]AT_YYERROR_DECLARE[ + ]AT_YYLEX_DECLARE[ #define GARBAGE_SIZE 50 static char garbage[GARBAGE_SIZE]; %} @@ -884,12 +846,7 @@ start: %% -static void -yyerror (char const *msg) -{ - fprintf (stderr, "%s\n", msg); -} - +]AT_YYERROR_DEFINE[ static int yylex (void) { @@ -908,6 +865,7 @@ main (void) return yyparse (); } ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([[-o glr-regr10.c glr-regr10.y]], 0, [], [glr-regr10.y: conflicts: 1 reduce/reduce @@ -925,12 +883,13 @@ AT_CLEANUP AT_SETUP([Undesirable destructors if user action cuts parse]) +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([glr-regr11.y], [[ %{ # include - static void yyerror (char const *); - static int yylex (void); + ]AT_YYERROR_DECLARE[ + ]AT_YYLEX_DECLARE[ static int destructors = 0; # define USE(val) %} @@ -949,21 +908,8 @@ start: %% -static void -yyerror (char const *msg) -{ - fprintf (stderr, "%s\n", msg); -} - -static int -yylex (void) -{ - static char const input[] = "a"; - static size_t toknum; - if (! (toknum < sizeof input)) - abort (); - return input[toknum++]; -} +]AT_YYERROR_DEFINE[ +]AT_YYLEX_DEFINE([a])[ int main (void) @@ -977,6 +923,7 @@ main (void) return exit_status; } ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([[-o glr-regr11.c glr-regr11.y]], 0, [], [glr-regr11.y: conflicts: 1 reduce/reduce @@ -994,6 +941,7 @@ AT_CLEANUP AT_SETUP([Leaked semantic values if user action cuts parse]) +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([glr-regr12.y], [[ %glr-parser @@ -1007,8 +955,8 @@ AT_DATA_GRAMMAR([glr-regr12.y], %{ # include static int merge (YYSTYPE, YYSTYPE); - static void yyerror (char const *); - static int yylex (void); + ]AT_YYERROR_DECLARE[ + ]AT_YYLEX_DECLARE[ static int parent_rhs_before_value = 0; static int merged_value = 0; static int parent_rhs_after_value = 0; @@ -1068,12 +1016,7 @@ merge (YYSTYPE s1, YYSTYPE s2) return dummy; } -static void -yyerror (char const *msg) -{ - fprintf (stderr, "%s\n", msg); -} - +]AT_YYERROR_DEFINE[ static int yylex (void) { @@ -1108,6 +1051,7 @@ main (void) return exit_status; } ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([[-o glr-regr12.c glr-regr12.y]], 0, [], [glr-regr12.y: conflicts: 1 shift/reduce, 1 reduce/reduce @@ -1127,6 +1071,7 @@ AT_CLEANUP AT_SETUP([Incorrect lookahead during deterministic GLR]) +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([glr-regr13.y], [[ /* Tests: @@ -1138,8 +1083,8 @@ AT_DATA_GRAMMAR([glr-regr13.y], %{ #include - static void yyerror (char const *); - static int yylex (void); + ]AT_YYERROR_DECLARE[ + ]AT_YYLEX_DECLARE[ static void print_lookahead (char const *); #define USE(value) %} @@ -1190,12 +1135,7 @@ change_lookahead: %% -static void -yyerror (char const *msg) -{ - fprintf (stderr, "%s\n", msg); -} - +]AT_YYERROR_DEFINE[ static int yylex (void) { @@ -1237,6 +1177,7 @@ main (void) return yyparse (); } ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([[-o glr-regr13.c glr-regr13.y]], 0, [], []) AT_COMPILE([glr-regr13]) @@ -1263,6 +1204,7 @@ AT_CLEANUP AT_SETUP([Incorrect lookahead during nondeterministic GLR]) +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([glr-regr14.y], [[ /* Tests: @@ -1289,8 +1231,8 @@ AT_DATA_GRAMMAR([glr-regr14.y], %{ #include #include - static void yyerror (char const *); - static int yylex (void); + ]AT_YYERROR_DECLARE[ + ]AT_YYLEX_DECLARE[ static void print_lookahead (char const *); static char merge (union YYSTYPE, union YYSTYPE); #define USE(value) @@ -1399,12 +1341,7 @@ no_look: %% -static void -yyerror (char const *msg) -{ - fprintf (stderr, "%s\n", msg); -} - +]AT_YYERROR_DEFINE[ static int yylex (void) { @@ -1453,6 +1390,7 @@ main (void) return yyparse (); } ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([[-o glr-regr14.c glr-regr14.y]], 0, [], [glr-regr14.y: conflicts: 3 reduce/reduce @@ -1483,6 +1421,7 @@ AT_CLEANUP AT_SETUP([Leaked semantic values when reporting ambiguity]) +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([glr-regr15.y], [[ %glr-parser @@ -1490,8 +1429,8 @@ AT_DATA_GRAMMAR([glr-regr15.y], %{ # include - static void yyerror (char const *); - static int yylex (void); + ]AT_YYERROR_DECLARE[ + ]AT_YYLEX_DECLARE[ static int parent_rhs_before_value = 0; # define USE(val) %} @@ -1530,12 +1469,7 @@ ambiguity2: ; %% -static void -yyerror (char const *msg) -{ - fprintf (stderr, "%s\n", msg); -} - +]AT_YYERROR_DEFINE[ static int yylex (void) { @@ -1557,6 +1491,7 @@ main (void) return exit_status; } ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([[-o glr-regr15.c glr-regr15.y]], 0, [], [glr-regr15.y: conflicts: 2 reduce/reduce @@ -1575,6 +1510,8 @@ AT_CLEANUP ## ------------------------------------------------------------------------- ## AT_SETUP([Leaked lookahead after nondeterministic parse syntax error]) + +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([glr-regr16.y], [[ %glr-parser @@ -1582,8 +1519,8 @@ AT_DATA_GRAMMAR([glr-regr16.y], %{ # include - static void yyerror (char const *); - static int yylex (void); + ]AT_YYERROR_DECLARE[ + ]AT_YYLEX_DECLARE[ static int lookahead_value = 0; # define USE(val) %} @@ -1596,12 +1533,7 @@ alt2: ; %% -static void -yyerror (char const *msg) -{ - fprintf (stderr, "%s\n", msg); -} - +]AT_YYERROR_DEFINE[ static int yylex (void) { @@ -1626,6 +1558,7 @@ main (void) return exit_status; } ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([[-o glr-regr16.c glr-regr16.y]], 0, [], [glr-regr16.y: conflicts: 1 reduce/reduce @@ -1644,6 +1577,8 @@ AT_CLEANUP ## ------------------------------------------------------------------------- ## AT_SETUP([Uninitialized location when reporting ambiguity]) + +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([glr-regr17.y], [[ %glr-parser @@ -1713,6 +1648,7 @@ main (void) return yyparse () != 1; } ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([[-o glr-regr17.c glr-regr17.y]], 0, [], [glr-regr17.y: conflicts: 3 reduce/reduce @@ -1731,12 +1667,14 @@ AT_CLEANUP ## -------------------------------------------------------------## AT_SETUP([Missed %merge type warnings when LHS type is declared later]) + +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([glr-regr18.y], [[%glr-parser %{ #include - static void yyerror (char const *); + ]AT_YYERROR_DECLARE[ static int yylex (); %} @@ -1758,27 +1696,15 @@ sym3: %merge { $$ = 0; } ; %% -static void -yyerror (char const *msg) -{ - fprintf (stderr, "%s\n", msg); -} - -static int -yylex () -{ - static int called; - if (called++) - abort (); - return 0; -} - +]AT_YYERROR_DEFINE[ +]AT_YYLEX_DEFINE()[ int main (void) { return yyparse (); } ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([[-o glr-regr18.c glr-regr18.y]], 1, [], [glr-regr18.y:26.18-24: result type clash on merge function 'merge': != @@ -1796,13 +1722,14 @@ AT_CLEANUP AT_SETUP([Ambiguity reports]) +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([input.y], [[ %{ #include #include - static void yyerror (char const *); - static int yylex (void); + ]AT_YYERROR_DECLARE[ + ]AT_YYLEX_DECLARE[ %} %debug @@ -1816,23 +1743,8 @@ start: b: 'b'; d: /* nada. */; %% - -static int -yylex (void) -{ - static char const input[] = "abc"; - static size_t toknum; - if (! (toknum < sizeof input)) - abort (); - return input[toknum++]; -} - -static void -yyerror (char const *msg) -{ - fprintf (stderr, "%s\n", msg); -} - +]AT_YYLEX_DEFINE([abc])[ +]AT_YYERROR_DEFINE[ int main (void) { @@ -1840,6 +1752,7 @@ main (void) return !!yyparse (); } ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([[-o input.c input.y]], 0, [], [input.y: conflicts: 1 reduce/reduce diff --git a/tests/headers.at b/tests/headers.at index 9710e0ce..0729f446 100644 --- a/tests/headers.at +++ b/tests/headers.at @@ -41,7 +41,6 @@ AT_BISON_CHECK([--defines input.y]) AT_CLEANUP - ## --------------------- ## ## Invalid CPP headers. ## ## --------------------- ## @@ -51,7 +50,7 @@ AT_CLEANUP # FIXME: Much of this can be covered by calc.at. m4_define([AT_TEST_CPP_GUARD_H], [AT_SETUP([Invalid CPP guards: $2 --defines=$1.h]) - +AT_BISON_OPTION_PUSHDEFS([$2]) # Possibly create inner directories. dirname=`AS_DIRNAME([$1])` AS_MKDIR_P([$dirname]) @@ -60,8 +59,8 @@ AT_DATA_GRAMMAR([$1.y], [$2 %{ #include <$1.h> -void yyerror (const char *); -int yylex (void); +]AT_YYERROR_DECLARE_EXTERN[ +]AT_YYLEX_DECLARE_EXTERN[ %} %% dummy:; @@ -73,6 +72,7 @@ AT_BISON_CHECK([--defines=$1.h --output=$1.c $1.y]) AT_COMPILE([$1.o], [-I. -c $1.c]) +AT_BISON_OPTION_POPDEFS AT_CLEANUP ]) diff --git a/tests/input.at b/tests/input.at index 93ae3de1..88498556 100644 --- a/tests/input.at +++ b/tests/input.at @@ -468,8 +468,8 @@ char quote[] = "@:>@@:>@,"; %} %{ -static void yyerror (const char *s); -static int yylex (void); +]AT_YYERROR_DECLARE[ +]AT_YYLEX_DECLARE[ %} %type '@<:@' @@ -621,14 +621,15 @@ AT_CLEANUP AT_SETUP([Symbols]) +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([input.y], [[%token WITH-DASH %token WITHOUT_DASH "WITHOUT-DASH" %token WITH.PERIOD %token WITHOUT_PERIOD "WITHOUT.PERIOD" %code { - void yyerror (char const *); - int yylex (void); + ]AT_YYERROR_DECLARE[ + ]AT_YYLEX_DECLARE[ } %% start: with-dash without_dash with.period without_period; @@ -637,7 +638,10 @@ without_dash: "WITHOUT-DASH"; with.period: WITH.PERIOD; without_period: "WITHOUT.PERIOD"; %% +]AT_YYERROR_DEFINE[ +]AT_YYLEX_DEFINE[ ]]) +AT_BISON_OPTION_POPDEFS # POSIX Yacc accept periods, but not dashes. AT_BISON_CHECK([--yacc input.y], [1], [], diff --git a/tests/local.at b/tests/local.at index 6efe66f8..e6e73549 100644 --- a/tests/local.at +++ b/tests/local.at @@ -267,6 +267,73 @@ m4_define([AT_DATA_GRAMMAR], $2]) ]) +# AT_YYLEX_DECLARE_EXTERN +# AT_YYLEX_DECLARE +# AT_YYLEX_DEFINE(INPUT-STRING, [ACTION]) +# --------------------------------------- +m4_define([AT_YYLEX_DECLARE_EXTERN], +[int yylex (void);dnl +]) + +m4_define([AT_YYLEX_DECLARE], +[static AT_YYLEX_DECLARE_EXTERN[]dnl +]) + +m4_define([AT_YYLEX_DEFINE], +[[#include /* abort */ +static int +yylex (void) +{ + static char const input[] = "$1"; + static size_t toknum = 0; + int res; + if (! (toknum < sizeof input)) + abort (); + res = input[toknum++]; + ]$2;[]AT_LOCATION_IF([[ + yylloc.first_line = yylloc.last_line = 1; + yylloc.first_column = yylloc.last_column = toknum;]])[ + return res; +}]dnl +]) + +# AT_YYERROR_DECLARE_EXTERN +# AT_YYERROR_DECLARE +# AT_YYERROR_DEFINE +# ------------------------- +# Beware that must be called inside a AT_BISON_OPTION_PUSHDEFS/POPDEFS +# pair. +m4_define([AT_YYERROR_DECLARE_EXTERN], +[void yyerror (const char *msg);dnl +]) + +m4_define([AT_YYERROR_DECLARE], +[static AT_YYERROR_DECLARE_EXTERN[]dnl +]) + +m4_define([AT_YYERROR_DEFINE], +[AT_SKEL_JAVA_IF([[ +public void yyerror (String msg) +{ + System.err.println (msg); +}]], [AT_SKEL_CC_IF([[ +void +yy::parser::error (const yy::location &, std::string const &msg) +{ + std::cerr << msg << std::endl; +}]], [[ +#include +static void +yyerror (char const *msg) +{ + fprintf (stderr, "%s\n", msg); +}]])])dnl +]) + +## --------------- ## +## Running Bison. ## +## --------------- ## + # AT_BISON_CHECK(BISON_ARGS, [OTHER_AT_CHECK_ARGS]) # ------------------------------------------------- # Check Bison by invoking `bison BISON_ARGS'. BISON_ARGS should not contain @@ -588,12 +655,12 @@ m4_define([AT_TEST_TABLES_AND_PARSE], [m4_pushdef([AT_COND_CASE], [m4_case([$2], $][@)]) AT_SETUP([$1]) - +AT_BISON_OPTION_PUSHDEFS([$4]) AT_DATA_GRAMMAR([[input.y]], [[%code { #include - static void yyerror (char const *msg); - static int yylex (void); + ]AT_YYERROR_DECLARE[ + ]AT_YYLEX_DECLARE[ } ]$4[ @@ -603,13 +670,7 @@ AT_DATA_GRAMMAR([[input.y]], ]$5[ %% - -static void -yyerror (char const *msg) -{ - fprintf (stderr, "%s\n", msg); -} - +]AT_YYERROR_DEFINE[ static int yylex (void) { @@ -665,6 +726,7 @@ AT_PARSER_CHECK([[./input]], m4_ifval([$11], [m4_dquote($11)]), m4_ifval([$12], [m4_dquote($12)])) +AT_BISON_OPTION_POPDEFS AT_CLEANUP m4_popdef([AT_COND_CASE])]) diff --git a/tests/named-refs.at b/tests/named-refs.at index d2942cfc..c9b91a0e 100644 --- a/tests/named-refs.at +++ b/tests/named-refs.at @@ -19,7 +19,7 @@ AT_BANNER([[Named references tests.]]) AT_SETUP([Tutorial calculator]) - +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([test.y], [[ %{ @@ -33,8 +33,8 @@ FILE *input; static semantic_value global_result = 0; static int global_count = 0; static int power (int base, int exponent); -static void yyerror (const char *s); -int yylex (void); +]AT_YYERROR_DECLARE[ +]AT_YYLEX_DECLARE[ %} %union @@ -83,12 +83,7 @@ exp: | '-' error { $$ = 0; YYERROR; } ; %% - -static void yyerror (const char *s) -{ - fprintf (stderr, "%s\n", s); -} - +]AT_YYERROR_DEFINE[ static int get_char (void) { int res = getc (input); @@ -119,7 +114,8 @@ static int read_signed_integer (void) return sign * n; } -int yylex (void) +static int +yylex (void) { int c; /* Skip white space. */ @@ -190,6 +186,7 @@ AT_DATA([input.txt], AT_BISON_CHECK([-o test.c test.y]) AT_COMPILE([[test]]) AT_PARSER_CHECK([./test input.txt], 0, [], [stderr]) +AT_BISON_OPTION_POPDEFS AT_CLEANUP @@ -198,13 +195,13 @@ AT_CLEANUP AT_SETUP([Undefined and ambiguous references]) - +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([test.y], [[ %{ static int power (int base, int exponent); -static void yyerror (const char *s); -int yylex (void); +]AT_YYERROR_DECLARE[ +]AT_YYLEX_DECLARE[ %} %union @@ -268,6 +265,7 @@ test.y:55.3-53: symbol not found in production: r12 test.y:56.29-33: invalid reference: '$expo' test.y:56.3-46: symbol not found in production: expo ]]) +AT_BISON_OPTION_POPDEFS AT_CLEANUP ####################################################################### diff --git a/tests/regression.at b/tests/regression.at index f5603eae..e93b901e 100644 --- a/tests/regression.at +++ b/tests/regression.at @@ -26,8 +26,8 @@ AT_SETUP([Trivial grammars]) AT_DATA_GRAMMAR([input.y], [[%{ -void yyerror (char const *); -int yylex (void); +]AT_YYERROR_DECLARE_EXTERN[ +]AT_YYLEX_DECLARE_EXTERN[ #define YYSTYPE int * %} @@ -54,8 +54,8 @@ AT_SETUP([YYSTYPE typedef]) AT_DATA_GRAMMAR([input.y], [[%{ -void yyerror (char const *); -int yylex (void); +]AT_YYERROR_DECLARE_EXTERN[ +]AT_YYLEX_DECLARE_EXTERN[ typedef union { char const *val; } YYSTYPE; %} @@ -85,8 +85,8 @@ AT_SETUP([Early token definitions with --yacc]) AT_DATA_GRAMMAR([input.y], [[%{ -void yyerror (const char *s); -int yylex (void); +]AT_YYERROR_DECLARE_EXTERN[ +]AT_YYLEX_DECLARE_EXTERN[ %} %union @@ -124,8 +124,8 @@ AT_SETUP([Early token definitions without --yacc]) AT_DATA_GRAMMAR([input.y], [[%{ #include -void yyerror (const char *s); -int yylex (void); +]AT_YYERROR_DECLARE_EXTERN[ +]AT_YYLEX_DECLARE_EXTERN[ void print_my_token (void); %} @@ -433,8 +433,8 @@ AT_DATA_GRAMMAR([input.y], [%{ #include #include -void yyerror (const char *s); -int yylex (void); +]AT_YYERROR_DECLARE[ +]AT_YYLEX_DECLARE[ %} [%error-verbose %token MYEOF 0 "end of file" @@ -498,19 +498,21 @@ AT_CLEANUP AT_SETUP([Characters Escapes]) +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([input.y], [%{ -void yyerror (const char *s); -int yylex (void); +]AT_YYERROR_DECLARE_EXTERN[ +]AT_YYLEX_DECLARE_EXTERN[ %} [%% exp: '\'' "\'" | '\"' "\"" -| '"' "'" +| '"' "'" /* Pacify font-lock-mode: ". */ ; ]]) -# Pacify font-lock-mode: " + +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([-o input.c input.y]) AT_COMPILE([input.o], [-c input.c]) @@ -837,7 +839,7 @@ static int yylex (AT_LALR1_CC_IF([int *], [void])); AT_LALR1_CC_IF([], [#include #include -static void yyerror (const char *);]) +]AT_YYERROR_DECLARE[]) %} $1 %token ARROW INVALID NUMBER STRING DATA @@ -965,7 +967,7 @@ static int yylex (AT_LALR1_CC_IF([int *], [void])); AT_LALR1_CC_IF([], [#include #include -static void yyerror (const char *);]) +]AT_YYERROR_DECLARE[]) %} $1 %defines @@ -1056,12 +1058,12 @@ AT_SETUP([Braced code in declaration in rules section]) # Bison once mistook braced code in a declaration in the rules section to be a # rule action. - +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([input.y], [[%{ #include -static void yyerror (char const *msg); -static int yylex (void); +]AT_YYERROR_DECLARE[ +]AT_YYLEX_DECLARE[ %} %error-verbose @@ -1080,12 +1082,7 @@ start: %% -static void -yyerror (char const *msg) -{ - fprintf (stderr, "%s\n", msg); -} - +]AT_YYERROR_DEFINE[ static int yylex (void) { @@ -1099,6 +1096,7 @@ main (void) return !yyparse (); } ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([-t -o input.c input.y]) AT_COMPILE([input]) @@ -1196,12 +1194,12 @@ AT_SETUP([[Token number in precedence declaration]]) # POSIX says token numbers can be declared in %left, %right, and %nonassoc, but # we lost this in Bison 1.50. - +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([input.y], [[%{ #include - void yyerror (char const *); - int yylex (void); + ]AT_YYERROR_DECLARE[ + ]AT_YYLEX_DECLARE[ %} %error-verbose @@ -1221,12 +1219,7 @@ sr_conflict: %% -void -yyerror (char const *msg) -{ - fprintf (stderr, "%s\n", msg); -} - +]AT_YYERROR_DEFINE[ int yylex (void) { @@ -1241,6 +1234,7 @@ main (void) return yyparse (); } ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([[-o input.c input.y]], [[0]],, [[input.y:23.5-19: warning: rule useless in parser due to conflicts: start: start @@ -1283,11 +1277,12 @@ AT_CLEANUP AT_SETUP([[%error-verbose and YYSTACK_USE_ALLOCA]]) +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([input.y], [[%code { #include - void yyerror (char const *); - int yylex (void); + ]AT_YYERROR_DECLARE[ + ]AT_YYLEX_DECLARE[ #define YYSTACK_USE_ALLOCA 1 } @@ -1323,28 +1318,18 @@ syntax_error: %% -void -yyerror (char const *msg) -{ - fprintf (stderr, "%s\n", msg); -} - -int -yylex (void) -{ - /* Induce two syntax error messages (which requires full error - recovery by shifting 3 tokens) in order to detect any loss of the - reallocated buffer. */ - static char const *input = "abc"; - return *input++; -} - +]AT_YYERROR_DEFINE[ +/* Induce two syntax error messages (which requires full error + recovery by shifting 3 tokens) in order to detect any loss of the + reallocated buffer. */ +]AT_YYLEX_DEFINE([abc])[ int main (void) { return yyparse (); } ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([[-o input.c input.y]]) AT_COMPILE([[input]]) @@ -1370,12 +1355,12 @@ AT_CLEANUP # yyparse would invoke yyerror using the old contents of yymsg. AT_SETUP([[%error-verbose overflow]]) - +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([input.y], [[%code { #include - void yyerror (char const *); - int yylex (void); + ]AT_YYERROR_DECLARE[ + ]AT_YYLEX_DECLARE[ /* This prevents this test case from having to induce error messages large enough to overflow size_t. */ @@ -1441,21 +1426,10 @@ syntax_error2: %% -void -yyerror (char const *msg) -{ - fprintf (stderr, "%s\n", msg); -} - -int -yylex (void) -{ - /* Induce two syntax error messages (which requires full error - recovery by shifting 3 tokens). */ - static char const *input = "abc"; - return *input++; -} - +]AT_YYERROR_DEFINE[ +/* Induce two syntax error messages (which requires full error + recovery by shifting 3 tokens). */ +]AT_YYLEX_DEFINE([abc])[ int main (void) { @@ -1481,7 +1455,7 @@ AT_PARSER_CHECK([[./input]], [[2]], [], syntax error memory exhausted ]]) - +AT_BISON_OPTION_POPDEFS AT_CLEANUP @@ -1499,7 +1473,7 @@ AT_BISON_OPTION_PUSHDEFS([$1]) AT_DATA_GRAMMAR([input.y], [[%code { #include - void yyerror (char const *); + ]AT_YYERROR_DECLARE[ int yylex (]AT_PURE_IF([[YYSTYPE *]], [[void]])[); } @@ -1520,13 +1494,7 @@ B: 'b' ; C: /*empty*/ { printf ("consistent default reduction\n"); } ; %% - -void -yyerror (char const *msg) -{ - fprintf (stderr, "%s\n", msg); -} - +]AT_YYERROR_DEFINE[ int yylex (]AT_PURE_IF([[YYSTYPE *v]], [[void]])[) { @@ -1592,13 +1560,13 @@ AT_CLEANUP AT_SETUP([[LAC: Memory exhaustion]]) -m4_pushdef([AT_LAC_CHECK], [ - +m4_pushdef([AT_LAC_CHECK], +[AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([input.y], [[%code { #include - void yyerror (char const *); - int yylex (void); + ]AT_YYERROR_DECLARE[ + ]AT_YYLEX_DECLARE[ #define YYMAXDEPTH 8 } @@ -1610,20 +1578,8 @@ S: A A A A A A A A A ; A: /*empty*/ | 'a' ; %% - -void -yyerror (char const *msg) -{ - fprintf (stderr, "%s\n", msg); -} - -int -yylex (void) -{ - static char const *input = "]$1["; - return *input++; -} - +]AT_YYERROR_DEFINE[ +]AT_YYLEX_DEFINE([$1])[ int main (void) { @@ -1637,12 +1593,12 @@ AT_BISON_CHECK([[-Dparse.lac=full -Dparse.lac.es-capacity-initial=1 \ [[input.y: conflicts: 8 shift/reduce ]]) AT_COMPILE([[input]]) - +AT_BISON_OPTION_POPDEFS ]) # Check for memory exhaustion during parsing. -AT_LAC_CHECK([[]]) -AT_PARSER_CHECK([[./input]], [[2]], [[]], +AT_LAC_CHECK([]) +AT_PARSER_CHECK([[./input]], [[2]], [], [[Starting parse Entering state 0 Reading a token: Now at end of input. @@ -1655,8 +1611,8 @@ Stack now 0 # Induce an immediate syntax error with an undefined token, and check # for memory exhaustion while building syntax error message. -AT_LAC_CHECK([[z]], [[0]]) -AT_PARSER_CHECK([[./input]], [[2]], [[]], +AT_LAC_CHECK([z], [[0]]) +AT_PARSER_CHECK([[./input]], [[2]], [], [[Starting parse Entering state 0 Reading a token: Next token is token $undefined () diff --git a/tests/skeletons.at b/tests/skeletons.at index 1a9933fe..76cf0662 100644 --- a/tests/skeletons.at +++ b/tests/skeletons.at @@ -83,10 +83,11 @@ AT_CLEANUP AT_SETUP([[Installed skeleton file names]]) +AT_BISON_OPTION_PUSHDEFS m4_pushdef([AT_GRAM], [[%{ #include - void yyerror (char const *msg); + ]AT_YYERROR_DECLARE[ int yylex (void); %} @@ -99,12 +100,7 @@ start: ; %% -void -yyerror (char const *msg) -{ - fprintf (stderr, "%s\n", msg); -} - +]AT_YYERROR_DEFINE[ int yylex (void) { @@ -139,6 +135,7 @@ AT_PARSER_CHECK([[./input-gram]], [[1]], [], m4_popdef([AT_GRAM]) +AT_BISON_OPTION_POPDEFS AT_CLEANUP diff --git a/tests/synclines.at b/tests/synclines.at index c12ab9b7..8d742d53 100644 --- a/tests/synclines.at +++ b/tests/synclines.at @@ -68,7 +68,7 @@ AT_CHECK([[sed -e '/^distcc\[[0-9]*\] /d' \ # to issue ERROR-MSG. m4_define([AT_TEST_SYNCLINE], [AT_SETUP([$1]) - +AT_BISON_OPTION_PUSHDEFS # It seems impossible to find a generic scheme to check the location # of an error. Even requiring GCC is not sufficient, since for instance # the version modified by Apple: @@ -98,6 +98,7 @@ AT_DATA([[input.y]], [$2]) AT_BISON_CHECK([-o input.c input.y]) AT_SYNCLINES_COMPILE([input.c]) AT_CHECK([cat stdout], 0, [$3]) +AT_BISON_OPTION_POPDEFS AT_CLEANUP ]) @@ -110,11 +111,12 @@ AT_CLEANUP AT_TEST_SYNCLINE([Prologue synch line], [[%{ #error "2" -void yyerror (const char *s); -int yylex (void); +]AT_YYERROR_DECLARE_EXTERN[ +]AT_YYLEX_DECLARE_EXTERN[ %} %% exp: '0'; +%% ]], [input.y:2: #error "2" ]) @@ -130,11 +132,12 @@ AT_TEST_SYNCLINE([%union synch line], char dummy; } %{ -void yyerror (const char *s); -int yylex (void); +]AT_YYERROR_DECLARE_EXTERN[ +]AT_YYLEX_DECLARE_EXTERN[ %} %% exp: '0'; +%% ]], [input.y:2: #error "2" ]) @@ -146,8 +149,8 @@ exp: '0'; AT_TEST_SYNCLINE([Postprologue synch line], [[%{ -void yyerror (const char *s); -int yylex (void); +]AT_YYERROR_DECLARE_EXTERN[ +]AT_YYLEX_DECLARE_EXTERN[ %} %union { @@ -158,6 +161,7 @@ int yylex (void); %} %% exp: '0'; +%% ]], [input.y:10: #error "10" ]) @@ -169,8 +173,8 @@ exp: '0'; AT_TEST_SYNCLINE([Action synch line], [[%{ -void yyerror (const char *s); -int yylex (void); +]AT_YYERROR_DECLARE_EXTERN[ +]AT_YYLEX_DECLARE_EXTERN[ %} %% exp: @@ -188,8 +192,8 @@ exp: AT_TEST_SYNCLINE([Epilogue synch line], [[%{ -void yyerror (const char *s); -int yylex (void); +]AT_YYERROR_DECLARE_EXTERN[ +]AT_YYLEX_DECLARE_EXTERN[ %} %% exp: '0'; diff --git a/tests/torture.at b/tests/torture.at index 2b2d4227..3fff08e6 100644 --- a/tests/torture.at +++ b/tests/torture.at @@ -56,8 +56,8 @@ print < #include -static int yylex (void); -static void yyerror (const char *msg); +]AT_YYLEX_DECLARE[ +]AT_YYERROR_DECLARE[ %} %union { @@ -171,8 +171,8 @@ print < #include -static int yylex (void); -static void yyerror (const char *msg); +]AT_YYLEX_DECLARE[ +]AT_YYERROR_DECLARE[ %} %token @@ -278,8 +278,8 @@ print < # include -static int yylex (void); -static void yyerror (const char *msg); +]AT_YYLEX_DECLARE[ +]AT_YYERROR_DECLARE[ %} %union { @@ -390,7 +390,8 @@ AT_CLEANUP # ------------------------------------------------ # A parser specialized in torturing the stack size. m4_define([AT_DATA_STACK_TORTURE], -[# A grammar of parens growing the stack thanks to right recursion. +[AT_BISON_OPTION_PUSHDEFS([$2]) +# A grammar of parens growing the stack thanks to right recursion. # exp: AT_DATA([input.y], [[%{ @@ -399,8 +400,8 @@ AT_DATA([input.y], #include #include ]$1[ - static int yylex (void); - static void yyerror (const char *msg); + ]AT_YYLEX_DECLARE[ + ]AT_YYERROR_DECLARE[ %} ]$2[ %error-verbose @@ -409,12 +410,7 @@ AT_DATA([input.y], %% exp: WAIT_FOR_EOF exp | ; %% -static void -yyerror (const char *msg) -{ - fprintf (stderr, "%s\n", msg); -} - +]AT_YYERROR_DEFINE[ static int yylex (void) { @@ -462,6 +458,7 @@ main (int argc, const char **argv) } } ]]) +AT_BISON_OPTION_POPDEFS([$2]) AT_BISON_CHECK([-o input.c input.y]) AT_COMPILE([input]) ]) From eb83259dc179d5facd1478ffa3a5dada0296e071 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sun, 17 Jun 2012 18:03:24 +0200 Subject: [PATCH 12/15] tests: remove test covered elsewhere. * tests/headers.at (%union and --defines): Remove, pretty useless and insignificant. --- tests/headers.at | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/tests/headers.at b/tests/headers.at index 0729f446..a28f2e1b 100644 --- a/tests/headers.at +++ b/tests/headers.at @@ -19,28 +19,6 @@ AT_BANNER([[Parser Headers.]]) -## ---------------------- ## -## %union and --defines. ## -## ---------------------- ## - - -AT_SETUP([%union and --defines]) - -AT_DATA([input.y], -[%union -{ - int integer; - char *string ; -} -%% -exp: {}; -]) - -AT_BISON_CHECK([--defines input.y]) - -AT_CLEANUP - - ## --------------------- ## ## Invalid CPP headers. ## ## --------------------- ## From 5f7f1e210b45977270f16532629107eb5c18227d Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sun, 17 Jun 2012 18:04:19 +0200 Subject: [PATCH 13/15] tests: pacify font-lock-mode. * tests/local.at: here. --- tests/local.at | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/local.at b/tests/local.at index e6e73549..e6227617 100644 --- a/tests/local.at +++ b/tests/local.at @@ -109,7 +109,7 @@ m4_pushdef([AT_SKEL_CC_IF], m4_pushdef([AT_SKEL_JAVA_IF], [m4_bmatch([$3], [%language "[Jj][Aa][Vv][Aa]"\|%skeleton "[a-z0-9]+\.java"], [$1], [$2])]) m4_pushdef([AT_GLR_IF], -[m4_bmatch([$3], [%glr-parser\|%skeleton "glr\.], [$1], [$2])]) +[m4_bmatch([$3], [%glr-parser\|%skeleton "glr\..*"], [$1], [$2])]) m4_pushdef([AT_LALR1_CC_IF], [AT_SKEL_CC_IF([AT_GLR_IF([$2], [$1])], [$2])]) m4_pushdef([AT_GLR_CC_IF], @@ -135,7 +135,7 @@ m4_pushdef([AT_GLR_OR_PARAM_IF], [m4_bmatch([$3], [%glr-parser\|%parse-param], [$1], [$2])]) m4_pushdef([AT_NAME_PREFIX], [m4_bmatch([$3], [%name-prefix ".*"], - [m4_bregexp([$3], [name-prefix "\([^"]*\)"], [\1])], + [m4_bregexp([$3], [name-prefix "\([^""]*\)"], [\1])], [yy])]) # yyerror receives the location if %location & %pure & (%glr or %parse-param). m4_pushdef([AT_YYERROR_ARG_LOC_IF], From 71c7e24f2e0190ea22e0ada09e7dafc3f37579cd Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sun, 17 Jun 2012 18:52:59 +0200 Subject: [PATCH 14/15] tests: support api.prefix. * tests/local.at (AT_BISON_OPTION_PUSHDEFS, AT_BISON_OPTION_POPDEFS): Define AT_API_PREFIX. (AT_YYERROR_DEFINE, AT_YYERROR_DECLARE_EXTERN, AT_YYLEX_DECLARE_EXTERN) (AT_YYLEX_DEFINE): Use it. * tests/input.at, tests/regression.at, tests/torture.at: Add AT_BISON_OPTION_PUSHDEFS/POPDEFS. --- tests/input.at | 13 ++++------- tests/local.at | 26 ++++++++++++---------- tests/regression.at | 53 +++++++++++++++++++++++++-------------------- tests/torture.at | 12 +++++++--- 4 files changed, 56 insertions(+), 48 deletions(-) diff --git a/tests/input.at b/tests/input.at index 88498556..2f667d0a 100644 --- a/tests/input.at +++ b/tests/input.at @@ -391,7 +391,7 @@ AT_CLEANUP AT_SETUP([Torturing the Scanner]) - +AT_BISON_OPTION_PUSHDEFS AT_DATA([input.y], []) AT_BISON_CHECK([input.y], [1], [], [[input.y:1.1: syntax error, unexpected end of file @@ -501,7 +501,7 @@ value_as_yystype (value val) res.ival = val; return res; } - +]AT_YYERROR_DEFINE[ static int yylex (void) { @@ -514,15 +514,9 @@ yylex (void) yylval = value_as_yystype (input[toknum]); return input[toknum++]; } - -static void -yyerror (const char *msg) -{ - fprintf (stderr, "%s\n", msg); -} ]]) -# Pacify Emacs'font-lock-mode: " +# Pacify Emacs' font-lock-mode: " AT_DATA([main.c], [[typedef int value; @@ -536,6 +530,7 @@ main (void) return yyparse (); } ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([-d -v -o input.c input.y]) AT_COMPILE([input.o], [-c input.c]) diff --git a/tests/local.at b/tests/local.at index e6227617..6d3ff18f 100644 --- a/tests/local.at +++ b/tests/local.at @@ -137,6 +137,10 @@ m4_pushdef([AT_NAME_PREFIX], [m4_bmatch([$3], [%name-prefix ".*"], [m4_bregexp([$3], [name-prefix "\([^""]*\)"], [\1])], [yy])]) +m4_pushdef([AT_API_PREFIX], +[m4_bmatch([$3], [%define api\.prefix ".*"], + [m4_bregexp([$3], [%define api\.prefix "\([^""]*\)"], [\1])], + [yy])]) # yyerror receives the location if %location & %pure & (%glr or %parse-param). m4_pushdef([AT_YYERROR_ARG_LOC_IF], [AT_GLR_OR_PARAM_IF([AT_PURE_AND_LOC_IF([$1], [$2])], @@ -202,6 +206,7 @@ m4_popdef([AT_LOC]) m4_popdef([AT_PURE_LEX_IF]) m4_popdef([AT_YYERROR_SEES_LOC_IF]) m4_popdef([AT_YYERROR_ARG_LOC_IF]) +m4_popdef([AT_API_PREFIX]) m4_popdef([AT_NAME_PREFIX]) m4_popdef([AT_GLR_OR_PARAM_IF]) m4_popdef([AT_PURE_AND_LOC_IF]) @@ -272,7 +277,7 @@ $2]) # AT_YYLEX_DEFINE(INPUT-STRING, [ACTION]) # --------------------------------------- m4_define([AT_YYLEX_DECLARE_EXTERN], -[int yylex (void);dnl +[int AT_API_PREFIX[]lex (void);dnl ]) m4_define([AT_YYLEX_DECLARE], @@ -282,7 +287,7 @@ m4_define([AT_YYLEX_DECLARE], m4_define([AT_YYLEX_DEFINE], [[#include /* abort */ static int -yylex (void) +]AT_API_PREFIX[lex (void) { static char const input[] = "$1"; static size_t toknum = 0; @@ -291,8 +296,8 @@ yylex (void) abort (); res = input[toknum++]; ]$2;[]AT_LOCATION_IF([[ - yylloc.first_line = yylloc.last_line = 1; - yylloc.first_column = yylloc.last_column = toknum;]])[ + ]AT_API_PREFIX[lloc.first_line = ]AT_API_PREFIX[lloc.last_line = 1; + ]AT_API_PREFIX[lloc.first_column = ]AT_API_PREFIX[lloc.last_column = toknum;]])[ return res; }]dnl ]) @@ -304,7 +309,7 @@ yylex (void) # Beware that must be called inside a AT_BISON_OPTION_PUSHDEFS/POPDEFS # pair. m4_define([AT_YYERROR_DECLARE_EXTERN], -[void yyerror (const char *msg);dnl +[void AT_API_PREFIX[]error (const char *msg);dnl ]) m4_define([AT_YYERROR_DECLARE], @@ -312,19 +317,16 @@ m4_define([AT_YYERROR_DECLARE], ]) m4_define([AT_YYERROR_DEFINE], -[AT_SKEL_JAVA_IF([[ -public void yyerror (String msg) +[AT_SKEL_JAVA_IF([[public void yyerror (String msg) { System.err.println (msg); -}]], [AT_SKEL_CC_IF([[ -void +}]], [AT_SKEL_CC_IF([[void yy::parser::error (const yy::location &, std::string const &msg) { std::cerr << msg << std::endl; -}]], [[ -#include +}]], [[#include static void -yyerror (char const *msg) +]AT_API_PREFIX[error (char const *msg) { fprintf (stderr, "%s\n", msg); }]])])dnl diff --git a/tests/regression.at b/tests/regression.at index e93b901e..fa93833c 100644 --- a/tests/regression.at +++ b/tests/regression.at @@ -24,6 +24,7 @@ AT_BANNER([[Regression tests.]]) AT_SETUP([Trivial grammars]) +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([input.y], [[%{ ]AT_YYERROR_DECLARE_EXTERN[ @@ -37,6 +38,7 @@ AT_DATA_GRAMMAR([input.y], program: 'x'; ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([-o input.c input.y]) AT_COMPILE([input.o], [-c input.c]) @@ -52,6 +54,7 @@ AT_CLEANUP AT_SETUP([YYSTYPE typedef]) +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([input.y], [[%{ ]AT_YYERROR_DECLARE_EXTERN[ @@ -65,6 +68,7 @@ typedef union { char const *val; } YYSTYPE; program: { $$ = ""; }; ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([-o input.c input.y]) AT_COMPILE([input.o], [-c input.c]) @@ -83,6 +87,7 @@ AT_SETUP([Early token definitions with --yacc]) # Found in GCJ: they expect the tokens to be defined before the user # prologue, so that they can use the token definitions in it. +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([input.y], [[%{ ]AT_YYERROR_DECLARE_EXTERN[ @@ -103,6 +108,7 @@ AT_DATA_GRAMMAR([input.y], exp: MY_TOKEN; %% ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([-y -o input.c input.y]) AT_COMPILE([input.o], [-c input.c]) @@ -121,6 +127,7 @@ AT_SETUP([Early token definitions without --yacc]) # Found in GCJ: they expect the tokens to be defined before the user # prologue, so that they can use the token definitions in it. +AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([input.y], [[%{ #include @@ -146,6 +153,7 @@ print_my_token (void) exp: MY_TOKEN; %% ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([-o input.c input.y]) AT_COMPILE([input.o], [-c input.c]) @@ -161,6 +169,7 @@ AT_CLEANUP AT_SETUP([Braces parsing]) +AT_BISON_OPTION_PUSHDEFS AT_DATA([input.y], [[/* Bison used to swallow the character after '}'. */ @@ -168,6 +177,7 @@ AT_DATA([input.y], exp: { tests = {{{{{{{{{{}}}}}}}}}}; }; %% ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([-v -o input.c input.y]) @@ -183,6 +193,7 @@ AT_CLEANUP AT_SETUP([Duplicate string]) +AT_BISON_OPTION_PUSHDEFS AT_DATA([input.y], [[/* 'Bison -v' used to dump core when two tokens are defined with the same string, as LE and GE below. */ @@ -195,6 +206,7 @@ AT_DATA([input.y], exp: '(' exp ')' | NUM ; %% ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([-v -o input.c input.y], 0, [], [[input.y:6.8-14: warning: symbol "<=" used more than once as a literal string @@ -211,6 +223,7 @@ AT_SETUP([Rule Line Numbers]) AT_KEYWORDS([report]) +AT_BISON_OPTION_PUSHDEFS AT_DATA([input.y], [[%% expr: @@ -240,6 +253,7 @@ expr: }; ]]) +AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([-o input.c -v input.y]) @@ -428,6 +442,7 @@ AT_CLEANUP AT_SETUP([Token definitions]) +AT_BISON_OPTION_PUSHDEFS # Bison managed, when fed with '%token 'f' "f"' to #define 'f'! AT_DATA_GRAMMAR([input.y], [%{ @@ -468,6 +483,7 @@ main (void) return yyparse (); } ]]) +AT_BISON_OPTION_POPDEFS # Checking the warning message guarantees that the trigraph "??!" isn't # unnecessarily escaped here even though it would need to be if encoded in a @@ -962,12 +978,12 @@ AT_CHECK_DANCER([%skeleton "lalr1.cc"]) # -------------------------------- m4_define([_AT_DATA_EXPECT2_Y], [AT_DATA_GRAMMAR([expect2.y], -[%{ -static int yylex (AT_LALR1_CC_IF([int *], [void])); +[[%{ +static int yylex (]AT_LALR1_CC_IF([int *], [void])); AT_LALR1_CC_IF([], -[#include +[[#include #include -]AT_YYERROR_DECLARE[]) +]AT_YYERROR_DECLARE])[ %} $1 %defines @@ -984,30 +1000,19 @@ e: e '+' t | t; t: A | B; %% -AT_LALR1_CC_IF( -[/* A C++ error reporting function. */ -void -yy::parser::error (const location&, const std::string& m) -{ - std::cerr << m << std::endl; -} - -int +]AT_YYERROR_DEFINE[ +]AT_LALR1_CC_IF( +[int yyparse () { yy::parser parser; return parser.parse (); } -], -[static void -yyerror (const char *s) -{ - fprintf (stderr, "%s\n", s); -}]) +])[ static int -yylex (AT_LALR1_CC_IF([int *lval], [void])) -[{ +yylex (]AT_LALR1_CC_IF([int *lval], [void])[) +{ static int const tokens[] = { 1000, '+', '+', -1 @@ -1017,19 +1022,19 @@ yylex (AT_LALR1_CC_IF([int *lval], [void])) if (! (toknum < sizeof tokens / sizeof *tokens)) abort (); return tokens[toknum++]; -}] +} int main (void) { return yyparse (); } -]) +]]) ])# _AT_DATA_EXPECT2_Y # AT_CHECK_EXPECT2(BISON-OPTIONS) -# ------------------------------ +# ------------------------------- # Generate the grammar, compile it, run it. m4_define([AT_CHECK_EXPECT2], [AT_SETUP([Expecting two tokens $1]) diff --git a/tests/torture.at b/tests/torture.at index 3fff08e6..313df345 100644 --- a/tests/torture.at +++ b/tests/torture.at @@ -42,7 +42,8 @@ esac]) # Create FILE-NAME, containing a self checking parser for a huge # triangular grammar. m4_define([AT_DATA_TRIANGULAR_GRAMMAR], -[AT_DATA([[gengram.pl]], +[AT_BISON_OPTION_PUSHDEFS +AT_DATA([[gengram.pl]], [[#! /usr/bin/perl -w use strict; @@ -127,6 +128,7 @@ main (void) } EOF ]]) +AT_BISON_OPTION_POPDEFS AT_CHECK([perl -w ./gengram.pl $2 || exit 77], 0, [stdout]) mv stdout $1 @@ -157,7 +159,8 @@ AT_CLEANUP # Create FILE-NAME, containing a self checking parser for a huge # horizontal grammar. m4_define([AT_DATA_HORIZONTAL_GRAMMAR], -[AT_DATA([[gengram.pl]], +[AT_BISON_OPTION_PUSHDEFS +AT_DATA([[gengram.pl]], [[#! /usr/bin/perl -w use strict; @@ -223,6 +226,7 @@ EOF AT_CHECK([perl -w ./gengram.pl $2 || exit 77], 0, [stdout]) mv stdout $1 +AT_BISON_OPTION_POPDEFS ]) @@ -263,7 +267,8 @@ AT_CLEANUP # Create FILE-NAME, containing a self checking parser for a grammar # requiring SIZE lookahead tokens. m4_define([AT_DATA_LOOKAHEAD_TOKENS_GRAMMAR], -[AT_DATA([[gengram.pl]], +[AT_BISON_OPTION_PUSHDEFS +AT_DATA([[gengram.pl]], [[#! /usr/bin/perl -w use strict; @@ -363,6 +368,7 @@ EOF AT_CHECK([perl -w ./gengram.pl $2 || exit 77], 0, [stdout]) mv stdout $1 +AT_BISON_OPTION_POPDEFS ]) From e29f0771d7a7a569f830bfe75216e1e0db3362e4 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Tue, 19 Jun 2012 17:01:35 +0200 Subject: [PATCH 15/15] maint: formatting changes. * NEWS: Fix indentation of code snippets. Untabify. --- NEWS | 116 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/NEWS b/NEWS index ae8b297c..9c5d67b7 100644 --- a/NEWS +++ b/NEWS @@ -21,22 +21,22 @@ GNU Bison NEWS The generated headers are now guarded, as is already the case for C++ parsers (lalr1.cc). For intance, with --defines=foo.h: - #ifndef YY_FOO_H - # define YY_FOO_H - ... - #endif /* !YY_FOO_H */ + #ifndef YY_FOO_H + # define YY_FOO_H + ... + #endif /* !YY_FOO_H */ *** New declarations The generated header now declares yydebug and yyparse. Both honor --name-prefix=bar_, and yield - int bar_parse (void); + int bar_parse (void); rather than - #define yyparse bar_parse - int yyparse (void); + #define yyparse bar_parse + int yyparse (void); in order to facilitate the inclusion of several parser headers inside a single compilation unit. @@ -78,10 +78,10 @@ GNU Bison NEWS The header files such as "parser.hh", "location.hh", etc. used a constant name for preprocessor guards, for instance: - #ifndef BISON_LOCATION_HH - # define BISON_LOCATION_HH - ... - #endif // !BISON_LOCATION_HH + #ifndef BISON_LOCATION_HH + # define BISON_LOCATION_HH + ... + #endif // !BISON_LOCATION_HH The inclusion guard is now computed from "PREFIX/FILE-NAME", where lower case characters are converted to upper case, and series of @@ -89,10 +89,10 @@ GNU Bison NEWS With "bison -o lang++/parser.cc", "location.hh" would now include: - #ifndef YY_LANG_LOCATION_HH - # define YY_LANG_LOCATION_HH - ... - #endif // !YY_LANG_LOCATION_HH + #ifndef YY_LANG_LOCATION_HH + # define YY_LANG_LOCATION_HH + ... + #endif // !YY_LANG_LOCATION_HH *** C++ locations: @@ -323,33 +323,33 @@ GNU Bison NEWS to use it. If, for instance, your location structure has "first" and "last" members, instead of - # define YYLLOC_DEFAULT(Current, Rhs, N) \ - do \ - if (N) \ - { \ - (Current).first = (Rhs)[1].location.first; \ - (Current).last = (Rhs)[N].location.last; \ - } \ - else \ - { \ - (Current).first = (Current).last = (Rhs)[0].location.last; \ - } \ - while (false) + # define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (N) \ + { \ + (Current).first = (Rhs)[1].location.first; \ + (Current).last = (Rhs)[N].location.last; \ + } \ + else \ + { \ + (Current).first = (Current).last = (Rhs)[0].location.last; \ + } \ + while (false) use: - # define YYLLOC_DEFAULT(Current, Rhs, N) \ - do \ - if (N) \ - { \ - (Current).first = YYRHSLOC (Rhs, 1).first; \ - (Current).last = YYRHSLOC (Rhs, N).last; \ - } \ - else \ - { \ - (Current).first = (Current).last = YYRHSLOC (Rhs, 0).last; \ - } \ - while (false) + # define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (N) \ + { \ + (Current).first = YYRHSLOC (Rhs, 1).first; \ + (Current).last = YYRHSLOC (Rhs, N).last; \ + } \ + else \ + { \ + (Current).first = (Current).last = YYRHSLOC (Rhs, 0).last; \ + } \ + while (false) ** YYLLOC_DEFAULT in C++: @@ -968,26 +968,26 @@ GNU Bison NEWS if the symbols have destructors. For instance: exp: exp "?" exp ":" exp { $1 ? $1 : $3; } - | exp "+" exp - ; + | exp "+" exp + ; will trigger a warning about $$ and $5 in the first rule, and $3 in the second ($1 is copied to $$ by the default rule). This example most likely contains three errors, and could be rewritten as: exp: exp "?" exp ":" exp - { $$ = $1 ? $3 : $5; free ($1 ? $5 : $3); free ($1); } - | exp "+" exp - { $$ = $1 ? $1 : $3; if ($1) free ($3); } - ; + { $$ = $1 ? $3 : $5; free ($1 ? $5 : $3); free ($1); } + | exp "+" exp + { $$ = $1 ? $1 : $3; if ($1) free ($3); } + ; However, if the original actions were really intended, memory leaks and all, the warnings can be suppressed by letting Bison believe the values are used, e.g.: exp: exp "?" exp ":" exp { $1 ? $1 : $3; (void) ($$, $5); } - | exp "+" exp { $$ = $1; (void) $3; } - ; + | exp "+" exp { $$ = $1; (void) $3; } + ; If there are mid-rule actions, the warning is issued if no action uses it. The following triggers no warning: $1 and $3 are used. @@ -1231,16 +1231,16 @@ GNU Bison NEWS In agreement with POSIX and with other Yaccs, leaving a default action is valid when $$ is untyped, and $1 typed: - untyped: ... typed; + untyped: ... typed; but the converse remains an error: - typed: ... untyped; + typed: ... untyped; ** Values of mid-rule actions The following code: - foo: { ... } { $$ = $1; } ... + foo: { ... } { $$ = $1; } ... was incorrectly rejected: $1 is defined in the second mid-rule action, and is equal to the $$ of the first mid-rule action. @@ -1322,9 +1322,9 @@ GNU Bison NEWS ** Incorrect "Token not used" On a grammar such as - %token useless useful - %% - exp: '0' %prec useful; + %token useless useful + %% + exp: '0' %prec useful; where a token was used to set the precedence of the last rule, bison reported both "useful" and "useless" as useless tokens. @@ -1343,9 +1343,9 @@ GNU Bison NEWS the user symbol is used in the reports, the graphs, and the verbose error messages instead of "$end", which remains being the default. For instance - %token MYEOF 0 + %token MYEOF 0 or - %token MYEOF 0 "end of file" + %token MYEOF 0 "end of file" ** Semantic parser This old option, which has been broken for ages, is removed. @@ -1381,9 +1381,9 @@ GNU Bison NEWS Previous versions don't complain when there is a type clash on the default action if the rule has a mid-rule action, such as in: - %type bar - %% - bar: '0' {} '0'; + %type bar + %% + bar: '0' {} '0'; This is fixed.