From 64b3612ab183b8f000d3d6b2c8eb957865081d37 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Wed, 26 Dec 2012 08:18:03 +0100 Subject: [PATCH] skeletons: no longer call yylex via a CPP macro The YYLEX existed only to support YYLEX_PARAM, which is now removed. This macro was a nuisance, since incorrect yylex calls where pointed the macro _use_, instead of its definition. * data/c.m4 (b4_lex_formals, b4_lex): New. * data/glr.c, data/yacc.c: Use it. * data/lalr1.cc (b4_lex): New. Use it. squash! skeletons: no longer call yylex via a CPP macro --- data/c.m4 | 17 +++++++++++++++++ data/glr.c | 20 +++----------------- data/lalr1.cc | 26 +++++++++++++++++--------- data/yacc.c | 16 ++-------------- 4 files changed, 39 insertions(+), 40 deletions(-) diff --git a/data/c.m4 b/data/c.m4 index 89ad4fd1..0b91ca0d 100644 --- a/data/c.m4 +++ b/data/c.m4 @@ -124,6 +124,23 @@ m4_define_default([b4_union_name], [b4_api_PREFIX[]STYPE]) ## Pure/impure interfaces. ## ## ------------------------ ## +# b4_lex_formals +# -------------- +# All the yylex formal arguments. +# b4_lex_param arrives quoted twice, but we want to keep only one level. +m4_define([b4_lex_formals], +[b4_pure_if([[[[YYSTYPE *yylvalp]], [[&yylval]]][]dnl +b4_locations_if([, [[YYLTYPE *yyllocp], [&yylloc]]])])dnl +m4_ifdef([b4_lex_param], [, ]b4_lex_param)]) + + +# b4_lex +# ------ +# Call yylex. +m4_define([b4_lex], +[b4_function_call([yylex], [int], b4_lex_formals)]) + + # b4_user_args # ------------ m4_define([b4_user_args], diff --git a/data/glr.c b/data/glr.c index fc59b6ba..97e070d6 100644 --- a/data/glr.c +++ b/data/glr.c @@ -55,15 +55,6 @@ m4_define([b4_user_formals], [m4_ifset([b4_parse_param], [, b4_formals(b4_parse_param)])]) -# b4_lex_formals -# -------------- -# All the yylex formal arguments. -m4_define([b4_lex_formals], -m4_dquote(b4_pure_if([[[[YYSTYPE *yylvalp]], [[&yylval]]][]dnl -b4_locations_if([, [[YYLTYPE *yyllocp], [&yylloc]]])])dnl -m4_ifdef([b4_lex_param], [, ]b4_lex_param))) - - # b4_yyerror_args # --------------- # Optional effective arguments passed to yyerror: user args plus yylloc, and @@ -406,11 +397,6 @@ dnl We probably ought to introduce a type for confl. ]])[ ]b4_yy_location_print_define[ -/* YYLEX -- calling `yylex' with the right arguments. */ -#ifndef YYLEX -# define YYLEX ]b4_function_call([yylex], [int], b4_lex_formals)[ -#endif - ]b4_pure_if( [ #undef yynerrs @@ -1926,7 +1912,7 @@ yyprocessOneStack (yyGLRStack* yystackp, size_t yyk, if (yychar == YYEMPTY) { YYDPRINTF ((stderr, "Reading a token: ")); - yychar = YYLEX; + yychar = ]b4_lex[; } if (yychar <= YYEOF) @@ -2161,7 +2147,7 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[) yytoken, &yylval]b4_locuser_args([&yylloc])[); } YYDPRINTF ((stderr, "Reading a token: ")); - yychar = YYLEX; + yychar = ]b4_lex[; if (yychar <= YYEOF) { yychar = yytoken = YYEOF; @@ -2315,7 +2301,7 @@ b4_dollar_popdef])[]dnl if (yychar == YYEMPTY) { YYDPRINTF ((stderr, "Reading a token: ")); - yychar = YYLEX; + yychar = ]b4_lex[; } if (yychar <= YYEOF) diff --git a/data/lalr1.cc b/data/lalr1.cc index 32654f1d..91f5c27d 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -114,6 +114,19 @@ b4_dollar_popdef[]dnl ])]) +# b4_lex +# ------ +# Call yylex. +m4_define([b4_lex], +[b4_token_ctor_if( +[b4_function_call([yylex], + [symbol_type], m4_ifdef([b4_lex_param], b4_lex_param))], +[b4_function_call([yylex], [int], + [b4_api_PREFIX[STYPE*], [&yyla.value]][]dnl +b4_locations_if([, [[location*], [&yyla.location]]])dnl +m4_ifdef([b4_lex_param], [, ]b4_lex_param))])]) + + m4_pushdef([b4_copyright_years], [2002-2012]) @@ -719,15 +732,10 @@ b4_dollar_popdef])[]dnl { YYCDEBUG << "Reading a token: "; try - { -]b4_token_ctor_if( -[ symbol_type yylookahead = b4_function_call([yylex], [symbol_type], - m4_ifdef([b4_lex_param], b4_lex_param)); - yyla.move(yylookahead);], -[ yyla.type = yytranslate_ (b4_function_call([yylex], [int], - [b4_api_PREFIX[STYPE*], [&yyla.value]][]dnl -b4_locations_if([, [[location*], [&yyla.location]]])dnl -m4_ifdef([b4_lex_param], [, ]b4_lex_param)));])[ + {]b4_token_ctor_if([[ + symbol_type yylookahead = ]b4_lex[; + yyla.move (yylookahead);]], [[ + yyla.type = yytranslate_ (]b4_lex[);]])[ } catch (const syntax_error& yyexc) { diff --git a/data/yacc.c b/data/yacc.c index f75f9d5a..22fc275a 100644 --- a/data/yacc.c +++ b/data/yacc.c @@ -100,15 +100,6 @@ m4_define([b4_yyerror_args], m4_ifset([b4_parse_param], [b4_args(b4_parse_param), ])]) -# b4_lex_param -# ------------ -# Accumulate in b4_lex_param all the yylex arguments. -# b4_lex_param arrives quoted twice, but we want to keep only one level. -m4_define([b4_lex_param], -m4_dquote(b4_pure_if([[[[YYSTYPE *yylval]], [[&yylval]]][]dnl -b4_locations_if([, [[YYLTYPE *yylloc], [&yylloc]]])m4_ifdef([b4_lex_param], [, ])])dnl -m4_ifdef([b4_lex_param], b4_lex_param))) - ## ------------ ## ## Data Types. ## @@ -686,9 +677,6 @@ while (0) ]])[ ]b4_yy_location_print_define[ -/* YYLEX -- calling `yylex' with the right arguments. */ -#define YYLEX ]b4_function_call([yylex], [int], b4_lex_param)[ - /* Enable debugging if requested. */ #if ]b4_api_PREFIX[DEBUG @@ -1332,7 +1320,7 @@ b4_function_define([[yyparse]], [[int]], b4_parse_param)[ } } do { - yychar = YYLEX; + yychar = ]b4_lex[; yystatus = yypush_parse (yyps_local]b4_pure_if([[, yychar, &yylval]b4_locations_if([[, &yylloc]])])m4_ifset([b4_parse_param], [, b4_args(b4_parse_param)])[); } while (yystatus == YYPUSH_MORE); @@ -1593,7 +1581,7 @@ yyread_pushed_token:]])[ yylval = *yypushed_val;]b4_locations_if([[ if (yypushed_loc) yylloc = *yypushed_loc;]])])], [[ - yychar = YYLEX;]])[ + yychar = ]b4_lex[;]])[ } if (yychar <= YYEOF) -- 2.45.2