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
This commit is contained in:
Akim Demaille
2012-12-26 08:18:03 +01:00
parent 40bb6f78f8
commit 64b3612ab1
4 changed files with 39 additions and 40 deletions

View File

@@ -124,6 +124,23 @@ m4_define_default([b4_union_name], [b4_api_PREFIX[]STYPE])
## Pure/impure interfaces. ## ## 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 # b4_user_args
# ------------ # ------------
m4_define([b4_user_args], m4_define([b4_user_args],

View File

@@ -55,15 +55,6 @@ m4_define([b4_user_formals],
[m4_ifset([b4_parse_param], [, b4_formals(b4_parse_param)])]) [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 # b4_yyerror_args
# --------------- # ---------------
# Optional effective arguments passed to yyerror: user args plus yylloc, and # 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[ ]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( ]b4_pure_if(
[ [
#undef yynerrs #undef yynerrs
@@ -1926,7 +1912,7 @@ yyprocessOneStack (yyGLRStack* yystackp, size_t yyk,
if (yychar == YYEMPTY) if (yychar == YYEMPTY)
{ {
YYDPRINTF ((stderr, "Reading a token: ")); YYDPRINTF ((stderr, "Reading a token: "));
yychar = YYLEX; yychar = ]b4_lex[;
} }
if (yychar <= YYEOF) if (yychar <= YYEOF)
@@ -2161,7 +2147,7 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
yytoken, &yylval]b4_locuser_args([&yylloc])[); yytoken, &yylval]b4_locuser_args([&yylloc])[);
} }
YYDPRINTF ((stderr, "Reading a token: ")); YYDPRINTF ((stderr, "Reading a token: "));
yychar = YYLEX; yychar = ]b4_lex[;
if (yychar <= YYEOF) if (yychar <= YYEOF)
{ {
yychar = yytoken = YYEOF; yychar = yytoken = YYEOF;
@@ -2315,7 +2301,7 @@ b4_dollar_popdef])[]dnl
if (yychar == YYEMPTY) if (yychar == YYEMPTY)
{ {
YYDPRINTF ((stderr, "Reading a token: ")); YYDPRINTF ((stderr, "Reading a token: "));
yychar = YYLEX; yychar = ]b4_lex[;
} }
if (yychar <= YYEOF) if (yychar <= YYEOF)

View File

@@ -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], m4_pushdef([b4_copyright_years],
[2002-2012]) [2002-2012])
@@ -719,15 +732,10 @@ b4_dollar_popdef])[]dnl
{ {
YYCDEBUG << "Reading a token: "; YYCDEBUG << "Reading a token: ";
try try
{ {]b4_token_ctor_if([[
]b4_token_ctor_if( symbol_type yylookahead = ]b4_lex[;
[ symbol_type yylookahead = b4_function_call([yylex], [symbol_type], yyla.move (yylookahead);]], [[
m4_ifdef([b4_lex_param], b4_lex_param)); yyla.type = yytranslate_ (]b4_lex[);]])[
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)));])[
} }
catch (const syntax_error& yyexc) catch (const syntax_error& yyexc)
{ {

View File

@@ -100,15 +100,6 @@ m4_define([b4_yyerror_args],
m4_ifset([b4_parse_param], [b4_args(b4_parse_param), ])]) 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. ## ## Data Types. ##
@@ -686,9 +677,6 @@ while (0)
]])[ ]])[
]b4_yy_location_print_define[ ]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. */ /* Enable debugging if requested. */
#if ]b4_api_PREFIX[DEBUG #if ]b4_api_PREFIX[DEBUG
@@ -1332,7 +1320,7 @@ b4_function_define([[yyparse]], [[int]], b4_parse_param)[
} }
} }
do { do {
yychar = YYLEX; yychar = ]b4_lex[;
yystatus = yystatus =
yypush_parse (yyps_local]b4_pure_if([[, yychar, &yylval]b4_locations_if([[, &yylloc]])])m4_ifset([b4_parse_param], [, b4_args(b4_parse_param)])[); 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); } while (yystatus == YYPUSH_MORE);
@@ -1593,7 +1581,7 @@ yyread_pushed_token:]])[
yylval = *yypushed_val;]b4_locations_if([[ yylval = *yypushed_val;]b4_locations_if([[
if (yypushed_loc) if (yypushed_loc)
yylloc = *yypushed_loc;]])])], [[ yylloc = *yypushed_loc;]])])], [[
yychar = YYLEX;]])[ yychar = ]b4_lex[;]])[
} }
if (yychar <= YYEOF) if (yychar <= YYEOF)