From 258cddbc3695f2095cbfbc9ff95309b28733f7d2 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 25 Jun 2012 16:52:30 +0200 Subject: [PATCH 1/4] c++: do not export YYTOKEN_TABLE and YYERROR_VERBOSE. * src/output.c (prepare_symbols): Do not define b4_token_table. (prepare): Define b4_token_table_flag. * data/bison.m4 (b4_token_table_if): New. Arm it when error-verbose. * data/glr.c, data/yacc.c (YYTOKEN_TABLE): Remove. Use m4. * data/lalr1.cc: Likewise. (YYERROR_VERBOSE): Remove. * NEWS, doc/bison.texi: Document this. --- NEWS | 26 +++++++++++++++++--------- data/bison.m4 | 22 +++++++++++++--------- data/glr.c | 7 +------ data/lalr1.cc | 30 +++++++----------------------- data/yacc.c | 7 +------ doc/bison.texi | 3 ++- src/output.c | 2 +- 7 files changed, 42 insertions(+), 55 deletions(-) diff --git a/NEWS b/NEWS index 10829f54..7eebe910 100644 --- a/NEWS +++ b/NEWS @@ -13,14 +13,16 @@ GNU Bison NEWS generated for C supprt ISO C90, and are tested with ISO C99 and ISO C11 compilers. -*** Deprecated features +*** Features deprecated since Bison 1.875 - The definitions of yystype and yyltype will be removed, as announced since - Bison 1.875. Use YYSTYPE and YYLTYPE only. + The definitions of yystype and yyltype will be removed; use YYSTYPE and + YYLTYPE. - YYPARSE_PARAM and YYLEX_PARAM, which were deprecated in favor of - %parse-param and %lex-param (introduced in Bison 1.875), will no longer be - supported. + YYPARSE_PARAM and YYLEX_PARAM, deprecated in favor of %parse-param and + %lex-param, will no longer be supported. + + Support for the preprocessor symbol YYERROR_VERBOSE will be removed, use + %error-verbose. *** The generated header will be included (yacc.c) @@ -30,9 +32,9 @@ GNU Bison NEWS because existing versions of ylwrap (e.g., Automake 1.12.1) do not support it. -** Headers (yacc.c, glr.c, glr.cc) +** Headers -*** Guards +*** 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: @@ -42,7 +44,7 @@ GNU Bison NEWS ... #endif /* !YY_FOO_H */ -*** New declarations +*** New declarations (yacc.c, glr.c) The generated header now declares yydebug and yyparse. Both honor --name-prefix=bar_, and yield @@ -57,6 +59,12 @@ GNU Bison NEWS in order to facilitate the inclusion of several parser headers inside a single compilation unit. +*** Exported symbols in C++ + + The symbols YYTOKEN_TABLE and YYERROR_VERBOSE, which were defined in the + header, are removed, as they prevent the possibility of including several + generated headers from a single compilation unit. + * Noteworthy changes in release 2.5.1 (2012-06-05) [stable] ** Future changes: diff --git a/data/bison.m4 b/data/bison.m4 index 6688c06b..a5c1ee73 100644 --- a/data/bison.m4 +++ b/data/bison.m4 @@ -233,9 +233,9 @@ m4_define([b4_define_flag_if], # _b4_define_flag_if($1, $2, FLAG) # -------------------------------- -# This macro works around the impossibility to define macros -# inside macros, because issuing `[$1]' is not possible in M4 :(. -# This sucks hard, GNU M4 should really provide M5 like $$1. +# Work around the impossibility to define macros inside macros, +# because issuing `[$1]' is not possible in M4. GNU M4 should provide +# $$1 a la M5/TeX. m4_define([_b4_define_flag_if], [m4_if([$1$2], $[1]$[2], [], [m4_fatal([$0: Invalid arguments: $@])])dnl @@ -246,12 +246,16 @@ m4_define([b4_$3_if], # b4_FLAG_if(IF-TRUE, IF-FALSE) # ----------------------------- # Expand IF-TRUE, if FLAG is true, IF-FALSE otherwise. -b4_define_flag_if([defines]) # Whether headers are requested. -b4_define_flag_if([error_verbose]) # Whether error are verbose. -b4_define_flag_if([glr]) # Whether a GLR parser is requested. -b4_define_flag_if([locations]) # Whether locations are tracked. -b4_define_flag_if([nondeterministic]) # Whether conflicts should be handled. -b4_define_flag_if([yacc]) # Whether POSIX Yacc is emulated. +b4_define_flag_if([defines]) # Whether headers are requested. +b4_define_flag_if([error_verbose]) # Whether error are verbose. +b4_define_flag_if([glr]) # Whether a GLR parser is requested. +b4_define_flag_if([locations]) # Whether locations are tracked. +b4_define_flag_if([nondeterministic]) # Whether conflicts should be handled. +b4_define_flag_if([token_table]) # Whether yytoken_table is demanded. +b4_define_flag_if([yacc]) # Whether POSIX Yacc is emulated. + +# yytoken_table is needed to support verbose errors. +b4_error_verbose_if([m4_define([b4_token_table_flag], [1])]) ## ------------------------- ## diff --git a/data/glr.c b/data/glr.c index 4d0a1bcb..699d7304 100644 --- a/data/glr.c +++ b/data/glr.c @@ -215,11 +215,6 @@ b4_percent_code_get([[top]])[ # define YYERROR_VERBOSE ]b4_error_verbose_flag[ #endif -/* Enabling the token table. */ -#ifndef YYTOKEN_TABLE -# define YYTOKEN_TABLE ]b4_token_table[ -#endif - /* Default (constant) value used for initialization for null right-hand sides. Unlike the standard yacc.c template, here we set the default value of $$ to a zeroed-out value. @@ -367,7 +362,7 @@ static const ]b4_int_type_for([b4_rline])[ yyrline[] = }; #endif -#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE +#if YYDEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[ /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = diff --git a/data/lalr1.cc b/data/lalr1.cc index 4f0b2688..e82e654f 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -62,19 +62,6 @@ b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++], # define YYDEBUG ]b4_debug_flag[ #endif -/* Enabling verbose error messages. */ -#ifdef YYERROR_VERBOSE -# undef YYERROR_VERBOSE -# define YYERROR_VERBOSE 1 -#else -# define YYERROR_VERBOSE ]b4_error_verbose_flag[ -#endif - -/* Enabling the token table. */ -#ifndef YYTOKEN_TABLE -# define YYTOKEN_TABLE ]b4_token_table[ -#endif - ]b4_namespace_open[ /// A Bison parser. @@ -211,17 +198,15 @@ b4_user_stype /// For a rule, its LHS. static const ]b4_int_type_for([b4_r1])[ yyr1_[]; /// For a rule, its RHS length. - static const ]b4_int_type_for([b4_r2])[ yyr2_[]; - -#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE - /// For a symbol, its name in clear. - static const char* const yytname_[]; -#endif]b4_error_verbose_if([ + static const ]b4_int_type_for([b4_r2])[ yyr2_[]; ]b4_error_verbose_if([ /// Convert the symbol name \a n to a form suitable for a diagnostic. static std::string yytnamerr_ (const char *n);])[ -#if YYDEBUG +]b4_token_table_if([], [[#if YYDEBUG]])[ + /// For a symbol, its name in clear. + static const char* const yytname_[]; +]b4_token_table_if([[#if YYDEBUG]])[ /// A type to store symbol numbers and -1. typedef ]b4_int_type_for([b4_rhs])[ rhs_number_type; /// A `-1'-separated list of the rules' RHS. @@ -1051,7 +1036,7 @@ b4_error_verbose_if([int yystate, int yytoken], ]b4_r2[ }; -#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE +]b4_token_table_if([], [[#if YYDEBUG]])[ /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at \a yyntokens_, nonterminals. */ const char* @@ -1059,9 +1044,8 @@ b4_error_verbose_if([int yystate, int yytoken], { ]b4_tname[ }; -#endif -#if YYDEBUG +]b4_token_table_if([[#if YYDEBUG]])[ /* YYRHS -- A `-1'-separated list of the rules' RHS. */ const ]b4_parser_class_name[::rhs_number_type ]b4_parser_class_name[::yyrhs_[] = diff --git a/data/yacc.c b/data/yacc.c index 57f3dace..7cf088b2 100644 --- a/data/yacc.c +++ b/data/yacc.c @@ -336,11 +336,6 @@ m4_if(b4_prefix, [yy], [], # define YYERROR_VERBOSE ]b4_error_verbose_flag[ #endif -/* Enabling the token table. */ -#ifndef YYTOKEN_TABLE -# define YYTOKEN_TABLE ]b4_token_table[ -#endif - /* In a future release of Bison, this section will be replaced by #include "@basename(]b4_spec_defines_file[@)". */ ]b4_shared_declarations[ @@ -607,7 +602,7 @@ static const ]b4_int_type_for([b4_rline])[ yyrline[] = }; #endif -#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE +#if YYDEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[ /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = diff --git a/doc/bison.texi b/doc/bison.texi index 4f2e1c62..b1631665 100644 --- a/doc/bison.texi +++ b/doc/bison.texi @@ -11216,7 +11216,8 @@ Reporting Function @code{yyerror}}. An obsolete macro that you define with @code{#define} in the prologue to request verbose, specific error message strings when @code{yyerror} is called. It doesn't matter what definition you -use for @code{YYERROR_VERBOSE}, just whether you define it. Using +use for @code{YYERROR_VERBOSE}, just whether you define it. +Supported by the C skeletons only; using @code{%error-verbose} is preferred. @xref{Error Reporting}. @end deffn diff --git a/src/output.c b/src/output.c index e0d6ed3a..29e9ba84 100644 --- a/src/output.c +++ b/src/output.c @@ -142,7 +142,6 @@ escaped_output (FILE *out, char const *string) static void prepare_symbols (void) { - MUSCLE_INSERT_BOOL ("token_table", token_table_flag); MUSCLE_INSERT_INT ("tokens_number", ntokens); MUSCLE_INSERT_INT ("nterms_number", nvars); MUSCLE_INSERT_INT ("undef_token_number", undeftoken->number); @@ -624,6 +623,7 @@ prepare (void) MUSCLE_INSERT_BOOL ("nondeterministic_flag", nondeterministic_parser); MUSCLE_INSERT_BOOL ("synclines_flag", !no_lines_flag); MUSCLE_INSERT_BOOL ("tag_seen_flag", tag_seen); + MUSCLE_INSERT_BOOL ("token_table_flag", token_table_flag); MUSCLE_INSERT_BOOL ("use_push_for_pull_flag", use_push_for_pull_flag); MUSCLE_INSERT_BOOL ("yacc_flag", yacc_flag); From 694af10cb7670fcbe198685d13d5db7f87a9b083 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 25 Jun 2012 16:55:11 +0200 Subject: [PATCH 2/4] skeletons: no longer define YYLSP_NEEDED. * data/c.m4, data/glr.cc: here. * NEWS, TODO: Adjust. --- NEWS | 5 +++++ TODO | 6 ------ data/c.m4 | 3 --- data/glr.cc | 3 --- 4 files changed, 5 insertions(+), 12 deletions(-) diff --git a/NEWS b/NEWS index 7eebe910..33fac145 100644 --- a/NEWS +++ b/NEWS @@ -65,6 +65,11 @@ GNU Bison NEWS header, are removed, as they prevent the possibility of including several generated headers from a single compilation unit. +*** YYLSP_NEEDED + + For the same reasons, the undocumented and unused macro YYLSP_NEEDED is no + longer defined. + * Noteworthy changes in release 2.5.1 (2012-06-05) [stable] ** Future changes: diff --git a/TODO b/TODO index 21ef4b91..4f628a20 100644 --- a/TODO +++ b/TODO @@ -126,12 +126,6 @@ The code bw glr.c and yacc.c is really alike, we can certainly factor some parts. -* Yacc.c: CPP Macros - -Do some people use YYPURE, YYLSP_NEEDED like we do in the test suite? -They should not: it is not documented. But if they need to, let's -find something clean (not like YYLSP_NEEDED...). - * Report ** Figures diff --git a/data/c.m4 b/data/c.m4 index 8c6c4979..1f266a47 100644 --- a/data/c.m4 +++ b/data/c.m4 @@ -77,9 +77,6 @@ m4_define([b4_identification], /* Pull parsers. */ #define YYPULL ]b4_pull_flag])[ - -/* Using locations. */ -#define YYLSP_NEEDED ]b4_locations_flag[ ]]) diff --git a/data/glr.cc b/data/glr.cc index 0bc1f9fa..8e46be3d 100644 --- a/data/glr.cc +++ b/data/glr.cc @@ -239,9 +239,6 @@ b4_copyright([Skeleton interface for Bison GLR parsers in C++], ]b4_percent_define_ifdef([[location_type]], [], [[#include "location.hh"]])[ -/* Using locations. */ -#define YYLSP_NEEDED ]b4_locations_flag[ - /* Enabling traces. */ #ifndef YYDEBUG # define YYDEBUG ]b4_debug_flag[ From 95361618dee181507d53f47de2dd50c667b84007 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Thu, 28 Jun 2012 14:20:17 +0200 Subject: [PATCH 3/4] tests: AT_YYERROR_DEFINE: prepare for list of ints. * tests/local.at (AT_YYERROR_DEFINE): Don't add quotes, check their presence to detect char/int types. * tests/actions.at, tests/conflicts.at, tests/glr-regression.at, * tests/push.at, tests/regression.at: Adjust. --- tests/actions.at | 18 +++++++++--------- tests/conflicts.at | 2 +- tests/glr-regression.at | 16 ++++++++-------- tests/local.at | 11 ++++++++--- tests/push.at | 2 +- tests/regression.at | 6 +++--- 6 files changed, 30 insertions(+), 25 deletions(-) diff --git a/tests/actions.at b/tests/actions.at index 3f47928a..417e0188 100644 --- a/tests/actions.at +++ b/tests/actions.at @@ -51,7 +51,7 @@ exp: { putchar ('0'); } ; %% ]AT_YYERROR_DEFINE[ -]AT_YYLEX_DEFINE(123456789)[ +]AT_YYLEX_DEFINE(["123456789"])[ int main (void) { @@ -116,7 +116,7 @@ sum_of_the_five_previous_values: %% ]AT_YYERROR_DEFINE[ -]AT_YYLEX_DEFINE([])[ +]AT_YYLEX_DEFINE[ int main (void) { @@ -151,7 +151,7 @@ sum: { printf ("%d\n", $0.val + $-1.val + $-2.val); } ; %% ]AT_YYERROR_DEFINE[ -]AT_YYLEX_DEFINE()[ +]AT_YYLEX_DEFINE[ int main (void) { @@ -636,7 +636,7 @@ start: 'a' 'b' 'c' 'd' 'e' { $$ = 'S'; USE(($1, $2, $3, $4, $5)); } ; %% ]AT_YYERROR_DEFINE[ -]AT_YYLEX_DEFINE([abcd], [[yylval = res]])[ +]AT_YYLEX_DEFINE(["abcd"], [[yylval = res]])[ int main (void) @@ -748,7 +748,7 @@ start: %% ]AT_YYERROR_DEFINE[ -]AT_YYLEX_DEFINE([abcdef])[ +]AT_YYLEX_DEFINE(["abcdef"])[ int main (void) @@ -966,7 +966,7 @@ start: %% ]AT_YYERROR_DEFINE[ -]AT_YYLEX_DEFINE([abd], [yylval = res])[ +]AT_YYLEX_DEFINE(["abd"], [yylval = res])[ int main (void) { @@ -1066,7 +1066,7 @@ start: { USE($$); } ; %% ]AT_YYERROR_DEFINE[ -]AT_YYLEX_DEFINE([])[ +]AT_YYLEX_DEFINE[ int main (void) { @@ -1121,7 +1121,7 @@ start: %% ]AT_YYERROR_DEFINE[ -]AT_YYLEX_DEFINE([])[ +]AT_YYLEX_DEFINE[ int main (void) { @@ -1381,7 +1381,7 @@ accept: /*empty*/ { %% ]AT_YYERROR_DEFINE[ -]AT_YYLEX_DEFINE([a])[ +]AT_YYLEX_DEFINE(["a"])[ int main (void) { diff --git a/tests/conflicts.at b/tests/conflicts.at index cafa3338..a46acc5a 100644 --- a/tests/conflicts.at +++ b/tests/conflicts.at @@ -491,7 +491,7 @@ reduce-nonassoc: %prec 'a'; %% ]AT_YYERROR_DEFINE[ -]AT_YYLEX_DEFINE([aaa])[ +]AT_YYLEX_DEFINE(["aaa"])[ int main (void) diff --git a/tests/glr-regression.at b/tests/glr-regression.at index 91dedb89..f0641779 100644 --- a/tests/glr-regression.at +++ b/tests/glr-regression.at @@ -383,7 +383,7 @@ B: 'a' { $$ = make_value ("B", "'a'"); } ; %% ]AT_YYERROR_DEFINE[ -]AT_YYLEX_DEFINE([a])[ +]AT_YYLEX_DEFINE(["a"])[ int main (void) @@ -466,7 +466,7 @@ start: ; %% -]AT_YYLEX_DEFINE(a)[ +]AT_YYLEX_DEFINE(["a"])[ ]AT_YYERROR_DEFINE[ int main (void) @@ -519,7 +519,7 @@ start: 'a' | 'a' ; %% ]AT_YYERROR_DEFINE[ -]AT_YYLEX_DEFINE(a)[ +]AT_YYLEX_DEFINE(["a"])[ int main (void) { @@ -834,7 +834,7 @@ start: %% ]AT_YYERROR_DEFINE[ -]AT_YYLEX_DEFINE()[ +]AT_YYLEX_DEFINE[ int main (void) @@ -889,7 +889,7 @@ start: %% ]AT_YYERROR_DEFINE[ -]AT_YYLEX_DEFINE([a])[ +]AT_YYLEX_DEFINE(["a"])[ int main (void) @@ -1449,7 +1449,7 @@ ambiguity2: ; %% ]AT_YYERROR_DEFINE[ -]AT_YYLEX_DEFINE()[ +]AT_YYLEX_DEFINE[ int main (void) @@ -1663,7 +1663,7 @@ sym3: %merge { $$ = 0; } ; %% ]AT_YYERROR_DEFINE[ -]AT_YYLEX_DEFINE()[ +]AT_YYLEX_DEFINE[ int main (void) { @@ -1709,7 +1709,7 @@ start: b: 'b'; d: /* nada. */; %% -]AT_YYLEX_DEFINE([abc])[ +]AT_YYLEX_DEFINE(["abc"])[ ]AT_YYERROR_DEFINE[ int main (void) diff --git a/tests/local.at b/tests/local.at index 5a5bbdd0..1baf6616 100644 --- a/tests/local.at +++ b/tests/local.at @@ -291,8 +291,11 @@ $2]) # AT_YYLEX_PROTOTYPE # AT_YYLEX_DECLARE_EXTERN # AT_YYLEX_DECLARE -# AT_YYLEX_DEFINE(INPUT-STRING, [ACTION]) -# --------------------------------------- +# AT_YYLEX_DEFINE([INPUT], [ACTION]) +# ---------------------------------- +# INPUT can be empty, or in double quotes, or a list (in braces). +# ACTION may compute yylval for instance, using "res" as token type, +# and "toknum" as the number of calls to yylex (starting at 0). m4_define([AT_YYLEX_PROTOTYPE], [int AT_NAME_PREFIX[]lex (]AT_YYLEX_FORMALS[)[]dnl ]) @@ -310,7 +313,9 @@ m4_define([AT_YYLEX_DEFINE], static ]AT_YYLEX_PROTOTYPE[ { - static char const input[] = "$1"; + ]m4_bmatch([$1], [^\(".*"\)?$], + [[static char const input[] = ]m4_default([$1], [""])], + [[static int const input[] = ]$1])[; static size_t toknum = 0; int res; ]AT_USE_LEX_ARGS[; diff --git a/tests/push.at b/tests/push.at index 057807dd..d2c09263 100644 --- a/tests/push.at +++ b/tests/push.at @@ -101,7 +101,7 @@ start: ; %% ]AT_YYERROR_DEFINE[ -]m4_if([$1], [[both]], [AT_YYLEX_DEFINE([])])[ +]m4_if([$1], [[both]], [AT_YYLEX_DEFINE])[ int main (void) diff --git a/tests/regression.at b/tests/regression.at index ac7d55ee..a5e0c14d 100644 --- a/tests/regression.at +++ b/tests/regression.at @@ -1312,7 +1312,7 @@ syntax_error: /* 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])[ +]AT_YYLEX_DEFINE(["abc"])[ int main (void) { @@ -1419,7 +1419,7 @@ syntax_error2: ]AT_YYERROR_DEFINE[ /* Induce two syntax error messages (which requires full error recovery by shifting 3 tokens). */ -]AT_YYLEX_DEFINE([abc])[ +]AT_YYLEX_DEFINE(["abc"])[ int main (void) { @@ -1569,7 +1569,7 @@ A: /*empty*/ | 'a' ; %% ]AT_YYERROR_DEFINE[ -]AT_YYLEX_DEFINE([$1])[ +]AT_YYLEX_DEFINE(["$1"])[ int main (void) { From 087dcd78685097983821e5d540f9ff3385931833 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Thu, 28 Jun 2012 14:54:45 +0200 Subject: [PATCH 4/4] tests: use the generalized default yylex. * tests/actions.at, tests/glr-regression.at, tests/regression.at: here. --- tests/actions.at | 12 ++------- tests/glr-regression.at | 39 ++++++--------------------- tests/regression.at | 58 +++++++++-------------------------------- 3 files changed, 22 insertions(+), 87 deletions(-) diff --git a/tests/actions.at b/tests/actions.at index 417e0188..e8e8cd97 100644 --- a/tests/actions.at +++ b/tests/actions.at @@ -1417,7 +1417,7 @@ AT_DATA_GRAMMAR([input.y], # include ]AT_YYERROR_DECLARE[ - static int yylex (YYSTYPE *yylval); + ]AT_YYLEX_DECLARE[ } %% input: @@ -1432,15 +1432,7 @@ exp: %% ]AT_YYERROR_DEFINE[ -static int -yylex (YYSTYPE *yylval) -{ - static char const input[] = "bcd"; - static size_t toknum; - assert (toknum < sizeof input); - *yylval = (toknum + 1) * 10; - return input[toknum++]; -} +]AT_YYLEX_DEFINE(["bcd"], [*lvalp = (toknum + 1) * 10])[ int main (void) diff --git a/tests/glr-regression.at b/tests/glr-regression.at index f0641779..07c9fe25 100644 --- a/tests/glr-regression.at +++ b/tests/glr-regression.at @@ -998,16 +998,9 @@ merge (YYSTYPE s1, YYSTYPE s2) } ]AT_YYERROR_DEFINE[ -static int -yylex (void) -{ - static int const input[] = { PARENT_RHS_AFTER, 0 }; - static size_t toknum; - assert (toknum < sizeof input / sizeof *input); - if (input[toknum] == PARENT_RHS_AFTER) - parent_rhs_after_value = 1; - return input[toknum++]; -} +]AT_YYLEX_DEFINE([{ PARENT_RHS_AFTER, 0 }], + [if (res == PARENT_RHS_AFTER) + parent_rhs_after_value = 1;])[ int main (void) @@ -1117,17 +1110,8 @@ change_lookahead: %% ]AT_YYERROR_DEFINE[ -static int -yylex (void) -{ - static char const input[] = "ab"; - static size_t toknum; - assert (toknum < sizeof input); - yylloc.first_line = yylloc.last_line = 1; - yylloc.first_column = yylloc.last_column = toknum + 1; - yylval.value = input[toknum] + 'A' - 'a'; - return input[toknum++]; -} +]AT_YYLEX_DEFINE(["ab"], + [yylval.value = res + 'A' - 'a'])[ static void print_lookahead (char const *reduction) @@ -1507,16 +1491,9 @@ alt2: ; %% ]AT_YYERROR_DEFINE[ -static int -yylex (void) -{ - static char const input[] = "ab"; - static size_t toknum; - assert (toknum < sizeof input); - if (input[toknum] == 'b') - lookahead_value = 1; - return input[toknum++]; -} +]AT_YYLEX_DEFINE(["ab"], + [if (res == 'b') + lookahead_value = 1])[ int main (void) diff --git a/tests/regression.at b/tests/regression.at index a5e0c14d..c2795f66 100644 --- a/tests/regression.at +++ b/tests/regression.at @@ -463,15 +463,7 @@ AT_DATA_GRAMMAR([input.y], exp: "a" "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"; %% ]AT_YYERROR_DEFINE[ - -int -yylex (void) -{ - static int called; - if (called++) - abort (); - return SPECIAL; -} +]AT_YYLEX_DEFINE([{ SPECIAL }])[ int main (void) @@ -846,13 +838,11 @@ AT_CLEANUP # so that possible bound checking compilers could check all the skeletons. m4_define([_AT_DATA_DANCER_Y], [AT_DATA_GRAMMAR([dancer.y], -[%{ -static int yylex (AT_LALR1_CC_IF([int *], [void])); -AT_LALR1_CC_IF([], -[#include -#include -]AT_YYERROR_DECLARE[]) -%} +[[%code provides +{ + ]AT_YYERROR_DECLARE[ + ]AT_YYLEX_DECLARE[ +} $1 %token ARROW INVALID NUMBER STRING DATA %defines @@ -897,7 +887,8 @@ member: STRING | INVALID ; %% -AT_YYERROR_DEFINE[ +]AT_YYERROR_DEFINE[ +]AT_YYLEX_DEFINE([":"])[ ]AT_LALR1_CC_IF( [int yyparse () @@ -908,28 +899,14 @@ yyparse () #endif return parser.parse (); } -]) - -#include -static int -yylex (AT_LALR1_CC_IF([int *lval], [void])) -[{ - static int const tokens[] = - { - ':', -1 - }; - static size_t toknum; - ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[ - assert (toknum < sizeof tokens / sizeof *tokens); - return tokens[toknum++]; -}] +])[ int main (void) { return yyparse (); } -]) +]]) ])# _AT_DATA_DANCER_Y @@ -1071,13 +1048,8 @@ start: %printer { fprintf (yyoutput, "PRINTER"); } 'a'; %% - ]AT_YYERROR_DEFINE[ -static int -yylex (void) -{ - return 'a'; -} +]AT_YYLEX_DEFINE(["a"])[ int main (void) @@ -1210,13 +1182,7 @@ sr_conflict: %% ]AT_YYERROR_DEFINE[ -int -yylex (void) -{ - static int const input[] = { 1, 2, 3, 0 }; - static int const *inputp = input; - return *inputp++; -} +]AT_YYLEX_DEFINE([{ 1, 2, 3, 0 }])[ int main (void)