mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
%printer: support both yyo and yyoutput.
lalr1.cc used to support yyo, but not yyoutput. Support both, but document only yyoutput (at least until there is some consensus on this). * data/c.m4 (yy_symbol_value_print): Also support yyo. * data/glr.cc (yy_symbol_value_print_): Support both yyo and yyoutput. * data/lalr1.cc: Also support yyoutput. * doc/bison.texinfo: Explicitly use yyoutput in the examples. * examples/mfcalc/mfcalc.test: Test the -p option.
This commit is contained in:
@@ -495,7 +495,8 @@ m4_define_default([b4_yy_symbol_print_generate],
|
|||||||
b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl
|
b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl
|
||||||
m4_ifset([b4_parse_param], [, b4_parse_param]))[
|
m4_ifset([b4_parse_param], [, b4_parse_param]))[
|
||||||
{
|
{
|
||||||
]b4_parse_param_use([yyoutput], [yylocationp])dnl
|
FILE *yyo = yyoutput;
|
||||||
|
]b4_parse_param_use([yyo], [yylocationp])dnl
|
||||||
[ if (!yyvaluep)
|
[ if (!yyvaluep)
|
||||||
return;]
|
return;]
|
||||||
dnl glr.c does not feature yytoknum.
|
dnl glr.c does not feature yytoknum.
|
||||||
|
|||||||
@@ -148,9 +148,11 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
|
|||||||
]b4_parser_class_name[::yy_symbol_value_print_ (int yytype,
|
]b4_parser_class_name[::yy_symbol_value_print_ (int yytype,
|
||||||
const semantic_type* yyvaluep, const location_type* yylocationp)
|
const semantic_type* yyvaluep, const location_type* yylocationp)
|
||||||
{
|
{
|
||||||
/* Pacify ``unused variable'' warnings. */
|
|
||||||
YYUSE (yyvaluep);
|
|
||||||
YYUSE (yylocationp);
|
YYUSE (yylocationp);
|
||||||
|
YYUSE (yyvaluep);
|
||||||
|
std::ostream& yyoutput = debug_stream ();
|
||||||
|
std::ostream& yyo = yyoutput;
|
||||||
|
YYUSE (yyo);
|
||||||
switch (yytype)
|
switch (yytype)
|
||||||
{
|
{
|
||||||
]b4_symbol_foreach([b4_symbol_printer])dnl
|
]b4_symbol_foreach([b4_symbol_printer])dnl
|
||||||
|
|||||||
@@ -549,11 +549,11 @@ b4_percent_code_get[]dnl
|
|||||||
]b4_parser_class_name[::yy_destroy_ (const char* yymsg,
|
]b4_parser_class_name[::yy_destroy_ (const char* yymsg,
|
||||||
symbol_base_type<Exact>& yysym) const
|
symbol_base_type<Exact>& yysym) const
|
||||||
{
|
{
|
||||||
int yytype = yysym.type_get ();
|
|
||||||
if (yymsg)
|
if (yymsg)
|
||||||
YY_SYMBOL_PRINT (yymsg, yysym);
|
YY_SYMBOL_PRINT (yymsg, yysym);
|
||||||
|
|
||||||
// User destructor.
|
// User destructor.
|
||||||
|
int yytype = yysym.type_get ();
|
||||||
switch (yytype)
|
switch (yytype)
|
||||||
{
|
{
|
||||||
]b4_symbol_foreach([b4_symbol_destructor])dnl
|
]b4_symbol_foreach([b4_symbol_destructor])dnl
|
||||||
@@ -571,6 +571,8 @@ b4_percent_code_get[]dnl
|
|||||||
]b4_parser_class_name[::yy_print_ (std::ostream& yyo,
|
]b4_parser_class_name[::yy_print_ (std::ostream& yyo,
|
||||||
const symbol_base_type<Exact>& yysym) const
|
const symbol_base_type<Exact>& yysym) const
|
||||||
{
|
{
|
||||||
|
std::ostream& yyoutput = yyo;
|
||||||
|
YYUSE (yyoutput);
|
||||||
int yytype = yysym.type_get ();
|
int yytype = yysym.type_get ();
|
||||||
yyo << (yytype < yyntokens_ ? "token" : "nterm")
|
yyo << (yytype < yyntokens_ ? "token" : "nterm")
|
||||||
<< ' ' << yytname_[yytype] << " ("]b4_locations_if([
|
<< ' ' << yytname_[yytype] << " ("]b4_locations_if([
|
||||||
|
|||||||
@@ -3155,14 +3155,14 @@ type:
|
|||||||
%code requires @{ #include "type1.h" @}
|
%code requires @{ #include "type1.h" @}
|
||||||
%union @{ type1 field1; @}
|
%union @{ type1 field1; @}
|
||||||
%destructor @{ type1_free ($$); @} <field1>
|
%destructor @{ type1_free ($$); @} <field1>
|
||||||
%printer @{ type1_print ($$); @} <field1>
|
%printer @{ type1_print (yyoutput, $$); @} <field1>
|
||||||
@end group
|
@end group
|
||||||
|
|
||||||
@group
|
@group
|
||||||
%code requires @{ #include "type2.h" @}
|
%code requires @{ #include "type2.h" @}
|
||||||
%union @{ type2 field2; @}
|
%union @{ type2 field2; @}
|
||||||
%destructor @{ type2_free ($$); @} <field2>
|
%destructor @{ type2_free ($$); @} <field2>
|
||||||
%printer @{ type2_print ($$); @} <field2>
|
%printer @{ type2_print (yyoutput, $$); @} <field2>
|
||||||
@end group
|
@end group
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
@@ -10244,7 +10244,7 @@ regular destructors. All the values are printed using their
|
|||||||
@c FIXME: Document %printer, and mention that it takes a braced-code operand.
|
@c FIXME: Document %printer, and mention that it takes a braced-code operand.
|
||||||
@comment file: calc++-parser.yy
|
@comment file: calc++-parser.yy
|
||||||
@example
|
@example
|
||||||
%printer @{ debug_stream () << $$; @} <*>;
|
%printer @{ yyoutput << $$; @} <*>;
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
@noindent
|
@noindent
|
||||||
|
|||||||
@@ -24,3 +24,4 @@ cat >input <<EOF
|
|||||||
(1+2) * 3
|
(1+2) * 3
|
||||||
EOF
|
EOF
|
||||||
run 0 9
|
run 0 9
|
||||||
|
run 0 9 -p
|
||||||
|
|||||||
Reference in New Issue
Block a user