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