mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
%printer: promote yyo rather than yyoutput
* doc/bison.texi: Promote yyo rather than yyoutput. * data/c.m4, data/glr.cc, tests/types.at, tests/calc.at, tests/regression.at: Adjust.
This commit is contained in:
32
data/c.m4
32
data/c.m4
@@ -506,54 +506,54 @@ m4_ifset([b4_parse_param], [, b4_parse_param]))[
|
||||
# Define the "yy_symbol_print" function.
|
||||
m4_define_default([b4_yy_symbol_print_define],
|
||||
[[
|
||||
/*----------------------------------------.
|
||||
| Print this symbol's value on YYOUTPUT. |
|
||||
`----------------------------------------*/
|
||||
/*-----------------------------------.
|
||||
| Print this symbol's value on YYO. |
|
||||
`-----------------------------------*/
|
||||
|
||||
]b4_function_define([yy_symbol_value_print],
|
||||
[static void],
|
||||
[[FILE *yyoutput], [yyoutput]],
|
||||
[[FILE *yyo], [yyo]],
|
||||
[[int yytype], [yytype]],
|
||||
[[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl
|
||||
b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl
|
||||
m4_ifset([b4_parse_param], [, b4_parse_param]))[
|
||||
{
|
||||
FILE *yyo = yyoutput;
|
||||
]b4_parse_param_use([yyo], [yylocationp])dnl
|
||||
FILE *yyoutput = yyo;
|
||||
]b4_parse_param_use([yyoutput], [yylocationp])dnl
|
||||
[ if (!yyvaluep)
|
||||
return;]
|
||||
dnl glr.c does not feature yytoknum.
|
||||
m4_if(b4_skeleton, ["yacc.c"],
|
||||
[[# ifdef YYPRINT
|
||||
if (yytype < YYNTOKENS)
|
||||
YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
|
||||
YYPRINT (yyo, yytoknum[yytype], *yyvaluep);
|
||||
# endif
|
||||
]])dnl
|
||||
b4_symbol_actions([printer])[
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------------.
|
||||
| Print this symbol on YYOUTPUT. |
|
||||
`--------------------------------*/
|
||||
/*---------------------------.
|
||||
| Print this symbol on YYO. |
|
||||
`---------------------------*/
|
||||
|
||||
]b4_function_define([yy_symbol_print],
|
||||
[static void],
|
||||
[[FILE *yyoutput], [yyoutput]],
|
||||
[[FILE *yyo], [yyo]],
|
||||
[[int yytype], [yytype]],
|
||||
[[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl
|
||||
b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl
|
||||
m4_ifset([b4_parse_param], [, b4_parse_param]))[
|
||||
{
|
||||
YYFPRINTF (yyoutput, "%s %s (",
|
||||
YYFPRINTF (yyo, "%s %s (",
|
||||
yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
|
||||
|
||||
]b4_locations_if([ YY_LOCATION_PRINT (yyoutput, *yylocationp);
|
||||
YYFPRINTF (yyoutput, ": ");
|
||||
]b4_locations_if([ YY_LOCATION_PRINT (yyo, *yylocationp);
|
||||
YYFPRINTF (yyo, ": ");
|
||||
])dnl
|
||||
[ yy_symbol_value_print (yyoutput, yytype, yyvaluep]dnl
|
||||
[ yy_symbol_value_print (yyo, yytype, yyvaluep]dnl
|
||||
b4_locations_if([, yylocationp])[]b4_user_args[);
|
||||
YYFPRINTF (yyoutput, ")");
|
||||
YYFPRINTF (yyo, ")");
|
||||
}]dnl
|
||||
])
|
||||
|
||||
|
||||
@@ -184,9 +184,9 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
|
||||
{]b4_locations_if([[
|
||||
YYUSE (yylocationp);]])[
|
||||
YYUSE (yyvaluep);
|
||||
std::ostream& yyoutput = debug_stream ();
|
||||
std::ostream& yyo = yyoutput;
|
||||
YYUSE (yyo);
|
||||
std::ostream& yyo = debug_stream ();
|
||||
std::ostream& yyoutput = yyo;
|
||||
YYUSE (yyoutput);
|
||||
]b4_symbol_actions([printer])[
|
||||
}
|
||||
|
||||
|
||||
@@ -3193,14 +3193,14 @@ type:
|
||||
%code requires @{ #include "type1.h" @}
|
||||
%union @{ type1 field1; @}
|
||||
%destructor @{ type1_free ($$); @} <field1>
|
||||
%printer @{ type1_print (yyoutput, $$); @} <field1>
|
||||
%printer @{ type1_print (yyo, $$); @} <field1>
|
||||
@end group
|
||||
|
||||
@group
|
||||
%code requires @{ #include "type2.h" @}
|
||||
%union @{ type2 field2; @}
|
||||
%destructor @{ type2_free ($$); @} <field2>
|
||||
%printer @{ type2_print (yyoutput, $$); @} <field2>
|
||||
%printer @{ type2_print (yyo, $$); @} <field2>
|
||||
@end group
|
||||
@end example
|
||||
|
||||
@@ -5166,11 +5166,12 @@ Decl, , Freeing Discarded Symbols}).
|
||||
|
||||
@deffn {Directive} %printer @{ @var{code} @} @var{symbols}
|
||||
@findex %printer
|
||||
@vindex yyo
|
||||
@vindex yyoutput
|
||||
@c This is the same text as for %destructor.
|
||||
Invoke the braced @var{code} whenever the parser displays one of the
|
||||
@var{symbols}. Within @var{code}, @code{yyoutput} denotes the output stream
|
||||
(a @code{FILE*} in C, and an @code{std::ostream&} in C++), @code{$$} (or
|
||||
@var{symbols}. Within @var{code}, @code{yyo} denotes the output stream (a
|
||||
@code{FILE*} in C, and an @code{std::ostream&} in C++), @code{$$} (or
|
||||
@code{$<@var{tag}>$}) designates the semantic value associated with the
|
||||
symbol, and @code{@@$} its location. The additional parser parameters are
|
||||
also available (@pxref{Parser Function, , The Parser Function
|
||||
@@ -5195,10 +5196,10 @@ For example:
|
||||
%type <character> chr
|
||||
%token TAGLESS
|
||||
|
||||
%printer @{ fprintf (yyoutput, "'%c'", $$); @} <character>
|
||||
%printer @{ fprintf (yyoutput, "&%p", $$); @} <*>
|
||||
%printer @{ fprintf (yyoutput, "\"%s\"", $$); @} STRING1 string1
|
||||
%printer @{ fprintf (yyoutput, "<>"); @} <>
|
||||
%printer @{ fprintf (yyo, "'%c'", $$); @} <character>
|
||||
%printer @{ fprintf (yyo, "&%p", $$); @} <*>
|
||||
%printer @{ fprintf (yyo, "\"%s\"", $$); @} STRING1 string1
|
||||
%printer @{ fprintf (yyo, "<>"); @} <>
|
||||
@end example
|
||||
|
||||
@noindent
|
||||
@@ -9861,9 +9862,9 @@ prologue:
|
||||
%define parse.trace
|
||||
|
||||
/* Formatting semantic values. */
|
||||
%printer @{ fprintf (yyoutput, "%s", $$->name); @} VAR;
|
||||
%printer @{ fprintf (yyoutput, "%s()", $$->name); @} FNCT;
|
||||
%printer @{ fprintf (yyoutput, "%g", $$); @} <double>;
|
||||
%printer @{ fprintf (yyo, "%s", $$->name); @} VAR;
|
||||
%printer @{ fprintf (yyo, "%s()", $$->name); @} FNCT;
|
||||
%printer @{ fprintf (yyo, "%g", $$); @} <double>;
|
||||
@end example
|
||||
|
||||
The @code{%define} directive instructs Bison to generate run-time trace
|
||||
@@ -11541,7 +11542,7 @@ regular destructors. All the values are printed using their
|
||||
|
||||
@comment file: calc++/parser.yy
|
||||
@example
|
||||
%printer @{ yyoutput << $$; @} <*>;
|
||||
%printer @{ yyo << $$; @} <*>;
|
||||
@end example
|
||||
|
||||
@noindent
|
||||
|
||||
@@ -247,8 +247,8 @@ AT_SKEL_CC_IF(
|
||||
{
|
||||
semantic_value ival;
|
||||
};
|
||||
%printer { ]AT_SKEL_CC_IF([[yyoutput << $$]],
|
||||
[[fprintf (yyoutput, "%d", $$)]])[; } <ival>;
|
||||
%printer { ]AT_SKEL_CC_IF([[yyo << $$]],
|
||||
[[fprintf (yyo, "%d", $$)]])[; } <ival>;
|
||||
|
||||
%code provides
|
||||
{
|
||||
|
||||
@@ -1012,7 +1012,7 @@ start:
|
||||
;
|
||||
|
||||
%destructor { fprintf (stderr, "DESTRUCTOR\n"); } 'a';
|
||||
%printer { fprintf (yyoutput, "PRINTER"); } 'a';
|
||||
%printer { fprintf (yyo, "PRINTER"); } 'a';
|
||||
|
||||
%%
|
||||
]AT_YYERROR_DEFINE[
|
||||
|
||||
@@ -175,7 +175,7 @@ m4_foreach([b4_skel], [[yacc.c], [glr.c], [lalr1.cc], [glr.cc]],
|
||||
};
|
||||
}
|
||||
%token <up->ival> '1' '2'
|
||||
%printer { ]AT_SKEL_CC_IF([[yyoutput << $$]],
|
||||
%printer { ]AT_SKEL_CC_IF([[yyo << $$]],
|
||||
[[fprintf (yyo, "%d", $$)]])[; } <up->ival>
|
||||
],
|
||||
['1' '2'
|
||||
@@ -231,9 +231,9 @@ m4_foreach([b4_skel], [[yacc.c], [glr.c], [lalr1.cc], [glr.cc]],
|
||||
%define api.value.type union],
|
||||
[%token <int> ONE 101;
|
||||
%token <float> TWO 102 THREE 103;
|
||||
%printer { ]AT_SKEL_CC_IF([[yyoutput << $$]],
|
||||
%printer { ]AT_SKEL_CC_IF([[yyo << $$]],
|
||||
[[fprintf (yyo, "%d", $$)]])[; } <int>
|
||||
%printer { ]AT_SKEL_CC_IF([[yyoutput << $$]],
|
||||
%printer { ]AT_SKEL_CC_IF([[yyo << $$]],
|
||||
[[fprintf (yyo, "%f", $$)]])[; } <float>
|
||||
],
|
||||
[ONE TWO THREE { printf ("%d %2.1f %2.1f\n", $1, $2, $3); }],
|
||||
@@ -255,9 +255,9 @@ m4_foreach([b4_skel], [[yacc.c], [glr.c], [lalr1.cc], [glr.cc]],
|
||||
['1' '2' { std::cout << $1 << ", " << $2 << '\n'; }],
|
||||
["12"],
|
||||
[if (res == '1')
|
||||
AT_VAL.build(10);
|
||||
AT_VAL.build (10);
|
||||
else if (res == '2')
|
||||
AT_VAL.build<std::string>("two");],
|
||||
AT_VAL.build<std::string> ("two");],
|
||||
[10, two])])
|
||||
])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user