bison-patches
[Top][All Lists]
Advanced

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

FYI: Generalize the display of values and locations in reductions


From: Akim Demaille
Subject: FYI: Generalize the display of values and locations in reductions
Date: Wed, 16 Nov 2005 15:22:08 +0100
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux)

Index: ChangeLog
from  Akim Demaille  <address@hidden>

        Generalize the display of semantic values and locations in traces.
        * data/glr.c (yy_reduce_print): Fix indices (again).
        * data/c++.m4 (b4_rhs_value, b4_rhs_location): Don't expect
        literal integers.
        * data/lalr1.cc (yyreduce_print): Rename as...
        (yy_reduce_print): this.
        Display values and locations.
        * data/yacc.c (yy_reduce_print): Likewise.
        (YY_REDUCE_PRINT): Adjust to pass the required arguments.
        (yysymprint): Move higher to be visible from yy_reduce_print).
        (yyparse): Adjust.
        * tests/calc.at: Adjust the expected length of the traces.

Index: data/c++.m4
===================================================================
RCS file: /cvsroot/bison/bison/data/c++.m4,v
retrieving revision 1.2
diff -u -u -r1.2 c++.m4
--- data/c++.m4 29 Sep 2005 06:50:57 -0000 1.2
+++ data/c++.m4 16 Nov 2005 14:20:36 -0000
@@ -61,7 +61,7 @@
 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
 # symbols on RHS.
 m4_define([b4_rhs_value],
-[(address@hidden([$1 - $2])@}m4_ifval([$3], [.$3]))])
+[(address@hidden($1) - ($2)@}m4_ifval([$3], [.$3]))])
 
 # b4_lhs_location()
 # -----------------
@@ -75,7 +75,7 @@
 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
 # on RHS.
 m4_define([b4_rhs_location],
-[(address@hidden([$1 - $2])@})])
+[(address@hidden($1) - ($2)@})])
 
 
 # b4_parse_param_decl
Index: data/glr.c
===================================================================
RCS file: /cvsroot/bison/bison/data/glr.c,v
retrieving revision 1.139
diff -u -u -r1.139 glr.c
--- data/glr.c 14 Nov 2005 17:20:28 -0000 1.139
+++ data/glr.c 16 Nov 2005 14:20:36 -0000
@@ -1387,8 +1387,8 @@
     {
       fprintf (stderr, "   $%d = ", yyi + 1);
       yysymprint (stderr, yyrhs[yyprhs[yyrule] + yyi],
-                  &]b4_rhs_value(yynrhs, yyi - 1)[
-                  ]b4_location_if([, &]b4_rhs_location(yynrhs, yyi - 1))[]dnl
+                  &]b4_rhs_value(yynrhs, yyi + 1)[
+                  ]b4_location_if([, &]b4_rhs_location(yynrhs, yyi + 1))[]dnl
                  b4_user_args[);
       fprintf (stderr, "\n");
     }
Index: data/lalr1.cc
===================================================================
RCS file: /cvsroot/bison/bison/data/lalr1.cc,v
retrieving revision 1.111
diff -u -u -r1.111 lalr1.cc
--- data/lalr1.cc 12 Nov 2005 14:13:03 -0000 1.111
+++ data/lalr1.cc 16 Nov 2005 14:20:36 -0000
@@ -232,7 +232,7 @@
     /// For each scanner token number, its symbol number.
     static const ]b4_int_type_for([b4_toknum])[ yytoken_number_[];
     /// Report on the debug stream that the rule \a r is going to be reduced.
-    virtual void yyreduce_print_ (int r);
+    virtual void yy_reduce_print_ (int r);
     /// Print the state stack on the debug stream.
     virtual void yystack_print_ ();
 #endif
@@ -328,7 +328,7 @@
 do {                                                   \
   if (yydebug_)                                                \
     {                                                  \
-      *yycdebug_ << (Title) << ' ';                    \
+      *yycdebug_ << Title << ' ';                      \
       yysymprint_ ((Type), (Value), (Location));       \
       *yycdebug_ << std::endl;                         \
     }                                                  \
@@ -337,7 +337,7 @@
 # define YY_REDUCE_PRINT(Rule)         \
 do {                                   \
   if (yydebug_)                                \
-    yyreduce_print_ (Rule);            \
+    yy_reduce_print_ (Rule);           \
 } while (false)
 
 # define YY_STACK_PRINT()              \
@@ -655,9 +655,9 @@
         ]b4_actions[
         default: break;
       }
-
-  ]/* Line __line__ of lalr1.cc.  */
-  b4_syncline(address@hidden@], address@hidden@])[
+    YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], &yyval, &yyloc);
+    /* Line __line__ of lalr1.cc.  */
+]b4_syncline(address@hidden@], address@hidden@])[
 
     yypop_ (yylen);
 
@@ -981,16 +981,19 @@
 
   // Report on the debug stream that the rule \a yyrule is going to be reduced.
   void
-  ]b4_parser_class_name[::yyreduce_print_ (int yyrule)
+  ]b4_parser_class_name[::yy_reduce_print_ (int yyrule)
   {
     unsigned int yylno = yyrline_[yyrule];
+    int yynrhs = yyr2_[yyrule];
     /* Print the symbols being reduced, and their result.  */
     *yycdebug_ << "Reducing stack by rule " << yyrule - 1
                << " (line " << yylno << "), ";
-    for (]b4_int_type_for([b4_prhs])[ i = yyprhs_[yyrule];
-         0 <= yyrhs_[i]; ++i)
-      *yycdebug_ << yytname_[yyrhs_[i]] << ' ';
-    *yycdebug_ << "-> " << yytname_[yyr1_[yyrule]] << std::endl;
+    /* The symbols being reduced.  */
+    for (int yyi = 0; yyi < yynrhs; yyi++)
+      YY_SYMBOL_PRINT ("   $" << yyi + 1 << " =",
+                       yyrhs_[yyprhs_[yyrule] + yyi],
+                       &]b4_rhs_value(yynrhs, yyi + 1)[,
+                       &]b4_rhs_location(yynrhs, yyi + 1)[);
   }
 #endif // YYDEBUG
 
Index: data/yacc.c
===================================================================
RCS file: /cvsroot/bison/bison/data/yacc.c,v
retrieving revision 1.116
diff -u -u -r1.116 yacc.c
--- data/yacc.c 21 Oct 2005 11:36:22 -0000 1.116
+++ data/yacc.c 16 Nov 2005 14:20:36 -0000
@@ -102,7 +102,7 @@
 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
 # symbols on RHS.
 m4_define([b4_rhs_value],
-[(address@hidden([$2 - $1])@}m4_ifval([$3], [.$3]))])
+[(address@hidden($2) - ($1)@}m4_ifval([$3], [.$3]))])
 
 
 
@@ -122,7 +122,7 @@
 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
 # on RHS.
 m4_define([b4_rhs_location],
-[(address@hidden([$2 - $1])@})])
+[(address@hidden($2) - ($1)@})])
 
 
 
@@ -639,6 +639,8 @@
     }                                                                    \
 } while (/*CONSTCOND*/ 0)
 
+]b4_yysymprint_generate([b4_c_function_def])[
+
 /*------------------------------------------------------------------.
 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
 | TOP (included).                                                   |
@@ -666,22 +668,32 @@
 `------------------------------------------------*/
 
 ]b4_c_function_def([yy_reduce_print], [static void],
-                   [[int yyrule], [yyrule]])[
+                   [[YYSTYPE *yyvsp], [yyvsvp]],
+   b4_location_if([[[YYLTYPE *yylsp], [yyvlvp]],])
+                   [[int yyrule],     [yyrule]]
+                   b4_parse_param)[
 {
+  int yynrhs = yyr2[yyrule];
   int yyi;
   unsigned long int yylno = yyrline[yyrule];
-  YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu), ",
+  YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
              yyrule - 1, yylno);
-  /* Print the symbols being reduced, and their result.  */
-  for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
-    YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]);
-  YYFPRINTF (stderr, "-> %s\n", yytname[yyr1[yyrule]]);
+  /* The symbols being reduced.  */
+  for (yyi = 0; yyi < yynrhs; yyi++)
+    {
+      fprintf (stderr, "   $%d = ", yyi + 1);
+      yysymprint (stderr, yyrhs[yyprhs[yyrule] + yyi],
+                  &]b4_rhs_value(yynrhs, yyi + 1)[
+                  ]b4_location_if([, &]b4_rhs_location(yynrhs, yyi + 1))[]dnl
+                 b4_user_args[);
+      fprintf (stderr, "\n");
+    }
 }
 
-# define YY_REDUCE_PRINT(Rule)         \
-do {                                   \
-  if (yydebug)                         \
-    yy_reduce_print (Rule);            \
+# define YY_REDUCE_PRINT(Args)                                 \
+do {                                                           \
+  if (yydebug)                                                 \
+    yy_reduce_print (yyvsp, ]b4_location_if([yylsp, ])[Args);  \
 } while (/*CONSTCOND*/ 0)
 
 /* Nonzero means print parse trace.  It is left uninitialized so that
@@ -691,7 +703,7 @@
 # define YYDPRINTF(Args)
 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
 # define YY_STACK_PRINT(Bottom, Top)
-# define YY_REDUCE_PRINT(Rule)
+# define YY_REDUCE_PRINT(Args)
 #endif /* !YYDEBUG */
 
 
@@ -922,10 +934,7 @@
 #endif /* YYERROR_VERBOSE */
 
 
-#if YYDEBUG
-]b4_yysymprint_generate([b4_c_function_def])[
-#endif /* ! YYDEBUG */
-]b4_yydestruct_generate([b4_c_function_def])
+]b4_yydestruct_generate([b4_c_function_def])[
 
 
 /* Prevent warnings from -Wmissing-prototypes.  */
@@ -937,11 +946,11 @@
 int yyparse ();
 # endif
 #else /* ! YYPARSE_PARAM */
-b4_c_function_decl([yyparse], [int], b4_parse_param)
+]b4_c_function_decl([yyparse], [int], b4_parse_param)[
 #endif /* ! YYPARSE_PARAM */
 
 
-m4_divert_push([KILL])# ======================== M4 code.
+]m4_divert_push([KILL])# ======================== M4 code.
 # b4_declare_parser_variables
 # ---------------------------
 # Declare the variables that are global, or local to YYPARSE if
@@ -1252,17 +1261,18 @@
 ]b4_location_if(
 [[  /* Default location. */
   YYLLOC_DEFAULT (yyloc, yylsp - yylen, yylen);]])[
-  YY_REDUCE_PRINT (yyn);
+  YY_REDUCE_PRINT ((yyn]b4_user_args[));
   switch (yyn)
-    ]{
-      b4_actions
+    {
+      ]b4_actions[
       default: break;
     }
+  YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
 
 /* Line __line__ of yacc.c.  */
-b4_syncline(address@hidden@], address@hidden@])
+]b4_syncline(address@hidden@], address@hidden@])[
 
-[  yyvsp -= yylen;
+  yyvsp -= yylen;
   yyssp -= yylen;
 ]b4_location_if([  yylsp -= yylen;])[
 
Index: tests/calc.at
===================================================================
RCS file: /cvsroot/bison/bison/tests/calc.at,v
retrieving revision 1.81
diff -u -u -r1.81 calc.at
--- tests/calc.at 11 Nov 2005 10:36:24 -0000 1.81
+++ tests/calc.at 16 Nov 2005 14:20:36 -0000
@@ -465,21 +465,21 @@
 
 2^2^3 = 256
 (2^2)^3 = 64],
-               [571])
+               [842])
 
 # Some syntax errors.
-_AT_CHECK_CALC_ERROR([$1], [1], [0 0], [13],
+_AT_CHECK_CALC_ERROR([$1], [1], [0 0], [15],
                      [1.2: syntax error, unexpected number])
-_AT_CHECK_CALC_ERROR([$1], [1], [1//2], [18],
+_AT_CHECK_CALC_ERROR([$1], [1], [1//2], [20],
                      [1.2: syntax error, unexpected '/', expecting number or 
'-' or '(' or '!'])
 _AT_CHECK_CALC_ERROR([$1], [1], [error], [5],
                      [1.0: syntax error, unexpected $undefined])
-_AT_CHECK_CALC_ERROR([$1], [1], [1 = 2 = 3], [26],
+_AT_CHECK_CALC_ERROR([$1], [1], [1 = 2 = 3], [30],
                      [1.6: syntax error, unexpected '='])
 _AT_CHECK_CALC_ERROR([$1], [1],
                      [
 +1],
-                     [16],
+                     [20],
                      [2.0: syntax error, unexpected '+'])
 # Exercise error messages with EOF: work on an empty file.
 _AT_CHECK_CALC_ERROR([$1], [1], [/dev/null], [4],
@@ -503,7 +503,7 @@
 #
 _AT_CHECK_CALC_ERROR([$1], [0],
                      [() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1],
-                     [189],
+                     [250],
 [1.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
 1.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
 1.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
@@ -512,10 +512,10 @@
 
 # The same, but this time exercising explicitly triggered syntax errors.
 # POSIX says the look-ahead causing the error should not be discarded.
-_AT_CHECK_CALC_ERROR([$1], [0], [(!) + (0 0) = 1], [76],
+_AT_CHECK_CALC_ERROR([$1], [0], [(!) + (0 0) = 1], [102],
 [1.9: syntax error, unexpected number
 calc: error: 2222 != 1])
-_AT_CHECK_CALC_ERROR([$1], [0], [(- *) + (0 0) = 1], [86],
+_AT_CHECK_CALC_ERROR([$1], [0], [(- *) + (0 0) = 1], [113],
 [1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
 1.11: syntax error, unexpected number
 calc: error: 2222 != 1])





reply via email to

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