bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

%printer: promote yyo rather than yyoutput


From: Akim Demaille
Subject: %printer: promote yyo rather than yyoutput
Date: Sat, 20 Oct 2018 19:05:34 +0200

In practice, it does make things nicer to read.  It’s been a long
time since we supported both.  Let’s shift the emphasis from
yyoutput to yyo.

I have left a few occurrences of yyoutput in the test suite.

commit e7b709ab0b00244f87f53e60bc2d0ad6b32f0c23
Author: Akim Demaille <address@hidden>
Date:   Sat Oct 20 10:36:09 2018 +0200

    %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.

diff --git a/data/c.m4 b/data/c.m4
index 9fb48ed8..b8d09621 100644
--- a/data/c.m4
+++ b/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
 ])
 
diff --git a/data/glr.cc b/data/glr.cc
index 27ae7be0..f6632c9b 100644
--- a/data/glr.cc
+++ b/data/glr.cc
@@ -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])[
   }
 
diff --git a/doc/bison.texi b/doc/bison.texi
index 61666c44..eda5eb65 100644
--- a/doc/bison.texi
+++ b/doc/bison.texi
@@ -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
address@hidden yyo
 @vindex yyoutput
 @c This is the same text as for %destructor.
 Invoke the braced @var{code} whenever the parser displays one of the
address@hidden  Within @var{code}, @code{yyoutput} denotes the output stream
-(a @code{FILE*} in C, and an @code{std::ostream&} in C++), @code{$$} (or
address@hidden  Within @var{code}, @code{yyo} denotes the output stream (a
address@hidden 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
diff --git a/tests/calc.at b/tests/calc.at
index f05514cc..36b1e368 100644
--- a/tests/calc.at
+++ b/tests/calc.at
@@ -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
 {
diff --git a/tests/regression.at b/tests/regression.at
index accd294f..7a5bb2dd 100644
--- a/tests/regression.at
+++ b/tests/regression.at
@@ -1012,7 +1012,7 @@ start:
   ;
 
 %destructor { fprintf (stderr, "DESTRUCTOR\n"); } 'a';
-%printer { fprintf (yyoutput, "PRINTER"); } 'a';
+%printer { fprintf (yyo, "PRINTER"); } 'a';
 
 %%
 ]AT_YYERROR_DEFINE[
diff --git a/tests/types.at b/tests/types.at
index c95d93e4..27553726 100644
--- a/tests/types.at
+++ b/tests/types.at
@@ -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])])
 ])
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]