bison-patches
[Top][All Lists]
Advanced

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

Re: doc: mfcalc: demonstrate %printer


From: Akim Demaille
Subject: Re: doc: mfcalc: demonstrate %printer
Date: Mon, 16 Apr 2012 17:29:28 +0200

Le 16 avr. 2012 à 17:27, Akim Demaille a écrit :

> From 93c150b666c3345bdd1527a5495a4787d8c3b5bf Mon Sep 17 00:00:00 2001
> From: Akim Demaille <address@hidden>
> Date: Sun, 8 Apr 2012 10:17:55 +0200
> Subject: [PATCH 2/3] doc: mfcalc: demonstrate %printer.
> 
> * doc/bison.texinfo (Printer Decl): New.
> Number mfcalc.y snippets so that they are output in
> the proper order.
> (The mfcalc Main): Use yydebug.
> (Debugging): Simplify the text.
> (Enabling Traces, Mfcalc Traces, The YYPRINT Macro): New.
> (Table of Symbols): Document YYPRINT and YYFPRINTF.

On top of this, I installed this in master, cherry-picked in
maint.  Some (cross-skeleton) tests are definitely missing.

From c50263271db482261b11f7452283c142a780a09d Mon Sep 17 00:00:00 2001
From: Akim Demaille <address@hidden>
Date: Mon, 16 Apr 2012 17:03:19 +0200
Subject: [PATCH 3/3] %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.
---
 data/c.m4                   |    3 ++-
 data/glr.cc                 |    6 ++++--
 data/lalr1.cc               |    4 +++-
 doc/bison.texinfo           |    6 +++---
 examples/mfcalc/mfcalc.test |    1 +
 5 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/data/c.m4 b/data/c.m4
index 14db807..e140ade 100644
--- a/data/c.m4
+++ b/data/c.m4
@@ -495,7 +495,8 @@ m4_define_default([b4_yy_symbol_print_generate],
 b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl
 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)
     return;]
 dnl glr.c does not feature yytoknum.
diff --git a/data/glr.cc b/data/glr.cc
index 67258ee..59533a2 100644
--- a/data/glr.cc
+++ b/data/glr.cc
@@ -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,
                            const semantic_type* yyvaluep, const location_type* 
yylocationp)
   {
-    /* Pacify ``unused variable'' warnings.  */
-    YYUSE (yyvaluep);
     YYUSE (yylocationp);
+    YYUSE (yyvaluep);
+    std::ostream& yyoutput = debug_stream ();
+    std::ostream& yyo = yyoutput;
+    YYUSE (yyo);
     switch (yytype)
       {
 ]b4_symbol_foreach([b4_symbol_printer])dnl
diff --git a/data/lalr1.cc b/data/lalr1.cc
index 99b8e9e..ef5e1ce 100644
--- a/data/lalr1.cc
+++ b/data/lalr1.cc
@@ -549,11 +549,11 @@ b4_percent_code_get[]dnl
   ]b4_parser_class_name[::yy_destroy_ (const char* yymsg,
                                        symbol_base_type<Exact>& yysym) const
   {
-    int yytype = yysym.type_get ();
     if (yymsg)
       YY_SYMBOL_PRINT (yymsg, yysym);
 
     // User destructor.
+    int yytype = yysym.type_get ();
     switch (yytype)
       {
 ]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,
                                      const symbol_base_type<Exact>& yysym) 
const
   {
+    std::ostream& yyoutput = yyo;
+    YYUSE (yyoutput);
     int yytype = yysym.type_get ();
     yyo << (yytype < yyntokens_ ? "token" : "nterm")
         << ' ' << yytname_[yytype] << " ("]b4_locations_if([
diff --git a/doc/bison.texinfo b/doc/bison.texinfo
index b0236af..434b6e6 100644
--- a/doc/bison.texinfo
+++ b/doc/bison.texinfo
@@ -3155,14 +3155,14 @@ type:
 %code requires @{ #include "type1.h" @}
 %union @{ type1 field1; @}
 %destructor @{ type1_free ($$); @} <field1>
-%printer @{ type1_print ($$); @} <field1>
+%printer @{ type1_print (yyoutput, $$); @} <field1>
 @end group
 
 @group
 %code requires @{ #include "type2.h" @}
 %union @{ type2 field2; @}
 %destructor @{ type2_free ($$); @} <field2>
-%printer @{ type2_print ($$); @} <field2>
+%printer @{ type2_print (yyoutput, $$); @} <field2>
 @end group
 @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.
 @comment file: calc++-parser.yy
 @example
-%printer @{ debug_stream () << $$; @} <*>;
+%printer @{ yyoutput << $$; @} <*>;
 @end example
 
 @noindent
diff --git a/examples/mfcalc/mfcalc.test b/examples/mfcalc/mfcalc.test
index f728f01..24c4b89 100755
--- a/examples/mfcalc/mfcalc.test
+++ b/examples/mfcalc/mfcalc.test
@@ -24,3 +24,4 @@ cat >input <<EOF
 (1+2) * 3
 EOF
 run 0 9
+run 0 9 -p
-- 
1.7.9.5






reply via email to

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