bison-patches
[Top][All Lists]
Advanced

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

FYI: Parser: reduce_print_


From: Akim Demaille
Subject: FYI: Parser: reduce_print_
Date: Mon, 25 Aug 2003 10:31:09 +0200
User-agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.3 (gnu/linux)

Index: ChangeLog
from  Akim Demaille  <address@hidden>

        * data/lalr1.cc (Parser::reduce_print_): New.
        Use it.

Index: data/lalr1.cc
===================================================================
RCS file: /cvsroot/bison/bison/data/lalr1.cc,v
retrieving revision 1.37
diff -u -u -r1.37 lalr1.cc
--- data/lalr1.cc 25 Aug 2003 08:06:17 -0000 1.37
+++ data/lalr1.cc 25 Aug 2003 08:28:32 -0000
@@ -263,6 +263,7 @@
     static const ]b4_int_type_for([b4_rline])[ rline_[];
     static const ]b4_int_type_for([b4_stos])[ stos_[];
     static const ]b4_int_type_for([b4_toknum])[ token_number_[];
+    virtual void reduce_print_ (int yyrule);
 #endif
 
     /* Even more tables.  */
@@ -322,8 +323,14 @@
 /* Enable debugging if requested.  */
 #if YYDEBUG
 # define YYCDEBUG    if (debug_) cdebug_
+# define YY_REDUCE_PRINT(Rule)         \
+do {                                   \
+  if (debug_)                          \
+    reduce_print_ (Rule);              \
+} while (0)
 #else /* !YYDEBUG */
 # define YYCDEBUG    if (0) cdebug_
+# define YY_REDUCE_PRINT(Rule)
 #endif /* !YYDEBUG */
 
 #define YYACCEPT       goto yyacceptlab
@@ -472,28 +479,12 @@
       yyloc = location_stack_[0];
     }
 
-#if YYDEBUG
-  if (debug_)
-    {
-      // Short files will use "unsigned char" for line numbers,
-      // in which case they will be output as character litterals
-      // by "<<".
-      unsigned yylno = rline_[n_];
-      YYCDEBUG << "Reducing via rule " << n_ - 1
-               << " (line " << yylno << "), ";
-      for (]b4_int_type_for([b4_prhs])[ i = prhs_[n_];
-          0 <= rhs_[i]; ++i)
-       YYCDEBUG << name_[rhs_[i]] << ' ';
-      YYCDEBUG << "-> " << name_[r1_[n_]] << std::endl;
-    }
-#endif
-
   if (len_)
     {
       Slice< LocationType, LocationStack > slice (location_stack_, len_);
       YYLLOC_DEFAULT (yyloc, slice, len_);
     }
-
+  YY_REDUCE_PRINT (n_);
   switch (n_)
     {
       ]b4_actions[
@@ -715,6 +706,7 @@
 #endif
 }
 
+
 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
    STATE-NUM.  */
 const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) 
yy::b4_parser_class_name::pact_ninf_ = b4_pact_ninf[;
@@ -828,7 +820,22 @@
 {
   ]b4_rline[
 };
-#endif
+
+/** Report that the YYRULE is going to be reduced.  */
+
+void
+yy::]b4_parser_class_name[::reduce_print_ (int yyrule)
+{
+  int yyi;
+  unsigned int yylno = rline_[yyrule];
+  /* Print the symbols being reduced, and their result.  */
+  cdebug_ << "Reducing via rule " << n_ - 1 << " (line " << yylno << "), ";
+  for (]b4_int_type_for([b4_prhs])[ i = prhs_[n_];
+       0 <= rhs_[i]; ++i)
+    cdebug_ << name_[rhs_[i]] << ' ';
+  cdebug_ << "-> " << name_[r1_[n_]] << std::endl;
+}
+#endif // YYDEBUG
 
 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
 yy::]b4_parser_class_name[::TokenNumberType
Index: data/yacc.c
===================================================================
RCS file: /cvsroot/bison/bison/data/yacc.c,v
retrieving revision 1.60
diff -u -u -r1.60 yacc.c
--- data/yacc.c 25 Jul 2003 07:11:42 -0000 1.60
+++ data/yacc.c 25 Aug 2003 08:28:32 -0000
@@ -556,7 +556,7 @@
 
 /*------------------------------------------------------------------.
 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
-| TOP (cinluded).                                                   |
+| TOP (included).                                                   |
 `------------------------------------------------------------------*/
 
 ]b4_c_function_def([yy_stack_print], [static void],




reply via email to

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