mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-10 12:53:03 +00:00
skel: better aliasing of identifiers
* data/glr.c, data/yacc.c: Avoid emitting useless defines. * data/glr.cc: Restore prefixes for epilogue.
This commit is contained in:
12
NEWS
12
NEWS
@@ -198,6 +198,18 @@ GNU Bison NEWS
|
|||||||
used by the scanner, or rejecting invalid combinations from a
|
used by the scanner, or rejecting invalid combinations from a
|
||||||
factory invoked by the user actions).
|
factory invoked by the user actions).
|
||||||
|
|
||||||
|
*** The epilogue is no longer affected by internal #defines
|
||||||
|
|
||||||
|
The glr.c skeleton uses defines such as #define yylval (yystackp->yyval) in
|
||||||
|
generated code. These weren't properly undefined before the inclusion of
|
||||||
|
the user epilogue, so functions such as the following were butchered by the
|
||||||
|
preprocessor expansion:
|
||||||
|
|
||||||
|
int yylex (yy::parser::semantic_type *yylval);
|
||||||
|
|
||||||
|
This is has been fixed: yylval, ynerrs, yychar, and yylloc are now valid
|
||||||
|
identifiers for user-provided variables.
|
||||||
|
|
||||||
** Renamed %define variables
|
** Renamed %define variables
|
||||||
|
|
||||||
The following variables have been renamed for consistency. Backward
|
The following variables have been renamed for consistency. Backward
|
||||||
|
|||||||
22
data/glr.c
22
data/glr.c
@@ -196,11 +196,12 @@ b4_percent_code_get([[top]])[
|
|||||||
#define yyparse ]b4_prefix[parse
|
#define yyparse ]b4_prefix[parse
|
||||||
#define yylex ]b4_prefix[lex
|
#define yylex ]b4_prefix[lex
|
||||||
#define yyerror ]b4_prefix[error
|
#define yyerror ]b4_prefix[error
|
||||||
|
#define yydebug ]b4_prefix[debug
|
||||||
|
]]b4_pure_if([], [[
|
||||||
#define yylval ]b4_prefix[lval
|
#define yylval ]b4_prefix[lval
|
||||||
#define yychar ]b4_prefix[char
|
#define yychar ]b4_prefix[char
|
||||||
#define yydebug ]b4_prefix[debug
|
|
||||||
#define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
|
#define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
|
||||||
#define yylloc ]b4_prefix[lloc]])])[
|
#define yylloc ]b4_prefix[lloc]])]))[
|
||||||
|
|
||||||
/* First part of user declarations. */
|
/* First part of user declarations. */
|
||||||
]b4_user_pre_prologue[
|
]b4_user_pre_prologue[
|
||||||
@@ -2543,6 +2544,23 @@ yypdumpstack (yyGLRStack* yystackp)
|
|||||||
YYFPRINTF (stderr, "\n");
|
YYFPRINTF (stderr, "\n");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#undef yylval
|
||||||
|
#undef yychar
|
||||||
|
#undef yynerrs]b4_locations_if([
|
||||||
|
#undef yylloc])
|
||||||
|
|
||||||
|
m4_if(b4_prefix, [yy], [],
|
||||||
|
[[/* Substitute the variable and function names. */
|
||||||
|
#define yyparse ]b4_prefix[parse
|
||||||
|
#define yylex ]b4_prefix[lex
|
||||||
|
#define yyerror ]b4_prefix[error
|
||||||
|
#define yylval ]b4_prefix[lval
|
||||||
|
#define yychar ]b4_prefix[char
|
||||||
|
#define yydebug ]b4_prefix[debug
|
||||||
|
#define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
|
||||||
|
#define yylloc ]b4_prefix[lloc]])])[
|
||||||
|
|
||||||
]b4_epilogue[]dnl
|
]b4_epilogue[]dnl
|
||||||
b4_output_end()
|
b4_output_end()
|
||||||
|
|
||||||
|
|||||||
18
data/glr.cc
18
data/glr.cc
@@ -118,10 +118,28 @@ m4_defn([b4_initial_action])]))])[
|
|||||||
[[const char* msg], [msg]])])
|
[[const char* msg], [msg]])])
|
||||||
|
|
||||||
|
|
||||||
|
#undef yynerrs
|
||||||
|
#undef yychar
|
||||||
|
#undef yylval]b4_locations_if([
|
||||||
|
#undef yylloc])
|
||||||
|
|
||||||
|
m4_if(b4_prefix, [yy], [],
|
||||||
|
[[/* Substitute the variable and function names. */
|
||||||
|
#define yyparse ]b4_prefix[parse
|
||||||
|
#define yylex ]b4_prefix[lex
|
||||||
|
#define yyerror ]b4_prefix[error
|
||||||
|
#define yydebug ]b4_prefix[debug
|
||||||
|
]]b4_pure_if([], [[
|
||||||
|
#define yylval ]b4_prefix[lval
|
||||||
|
#define yychar ]b4_prefix[char
|
||||||
|
#define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
|
||||||
|
#define yylloc ]b4_prefix[lloc]])]))
|
||||||
|
|
||||||
# Hijack the epilogue to define implementations (yyerror, parser member
|
# Hijack the epilogue to define implementations (yyerror, parser member
|
||||||
# functions etc.).
|
# functions etc.).
|
||||||
m4_append([b4_epilogue],
|
m4_append([b4_epilogue],
|
||||||
[b4_syncline([@oline@], [@ofile@])[
|
[b4_syncline([@oline@], [@ofile@])[
|
||||||
|
|
||||||
/*------------------.
|
/*------------------.
|
||||||
| Report an error. |
|
| Report an error. |
|
||||||
`------------------*/
|
`------------------*/
|
||||||
|
|||||||
@@ -346,11 +346,12 @@ m4_if(b4_api_prefix, [yy], [],
|
|||||||
#define yypstate ]b4_prefix[pstate]])[
|
#define yypstate ]b4_prefix[pstate]])[
|
||||||
#define yylex ]b4_prefix[lex
|
#define yylex ]b4_prefix[lex
|
||||||
#define yyerror ]b4_prefix[error
|
#define yyerror ]b4_prefix[error
|
||||||
#define yylval ]b4_prefix[lval
|
|
||||||
#define yychar ]b4_prefix[char
|
|
||||||
#define yydebug ]b4_prefix[debug
|
#define yydebug ]b4_prefix[debug
|
||||||
#define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
|
#define yynerrs ]b4_prefix[nerrs
|
||||||
#define yylloc ]b4_prefix[lloc]])])[
|
]]b4_pure_if([], [[
|
||||||
|
#define yylval ]b4_prefix[lval
|
||||||
|
#define yychar ]b4_prefix[char]b4_locations_if([[
|
||||||
|
#define yylloc ]b4_prefix[lloc]])]))[
|
||||||
|
|
||||||
/* Copy the first part of user declarations. */
|
/* Copy the first part of user declarations. */
|
||||||
]b4_user_pre_prologue[
|
]b4_user_pre_prologue[
|
||||||
|
|||||||
43
tests/c++.at
43
tests/c++.at
@@ -752,3 +752,46 @@ AT_PARSER_CHECK([[./input aaaaR]], [[0]])
|
|||||||
AT_BISON_OPTION_POPDEFS
|
AT_BISON_OPTION_POPDEFS
|
||||||
|
|
||||||
AT_CLEANUP
|
AT_CLEANUP
|
||||||
|
|
||||||
|
## ------------------------------------ ##
|
||||||
|
## C++ GLR parser identifier shadowing ##
|
||||||
|
## ------------------------------------ ##
|
||||||
|
|
||||||
|
AT_SETUP([[C++ GLR parser identifier shadowing]])
|
||||||
|
|
||||||
|
AT_DATA_GRAMMAR([input.yy], [
|
||||||
|
%skeleton "glr.cc"
|
||||||
|
|
||||||
|
%union
|
||||||
|
{
|
||||||
|
int ival;
|
||||||
|
}
|
||||||
|
|
||||||
|
%token <ival> ZERO;
|
||||||
|
|
||||||
|
%code
|
||||||
|
{
|
||||||
|
int yylex (yy::parser::semantic_type *yylval);
|
||||||
|
}
|
||||||
|
|
||||||
|
%%
|
||||||
|
exp: ZERO
|
||||||
|
|
||||||
|
%%
|
||||||
|
|
||||||
|
int yylex (yy::parser::semantic_type *yylval)
|
||||||
|
{
|
||||||
|
return yy::parser::token::ZERO;
|
||||||
|
}
|
||||||
|
|
||||||
|
void yy::parser::error (std::string const& msg)
|
||||||
|
{}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{}
|
||||||
|
])
|
||||||
|
|
||||||
|
AT_BISON_CHECK([[-o input.cc input.yy]])
|
||||||
|
AT_COMPILE_CXX([[input]])
|
||||||
|
|
||||||
|
AT_CLEANUP
|
||||||
|
|||||||
Reference in New Issue
Block a user