bison-patches
[Top][All Lists]
Advanced

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

[PATCH] Get rid of yyrhs and yyprhs in yacc.c.


From: Akim Demaille
Subject: [PATCH] Get rid of yyrhs and yyprhs in yacc.c.
Date: Sun, 23 Nov 2008 08:39:17 +0100

They were used to get the symbol types, given a rule number,  when
displaying the top of the stack before a reduction.  But the symbol type
is available from the state stack.  This has two be benefits: two tables
less in the parser (making it smaller), and a more consistent use of the
three stacks which will help to fuse them.

        * data/yacc.c (yyprhs, yyrhs): Remove.
        (YY_REDUCE_PRINT): Pass yyssp to yy_reduce_print.
        (yy_reduce_print): Take yyssp as argument.
        Use it, together with yystos, to get the symbol type.
        * tests/regression.at (Web2c Report): Remove these tables from the
        expected output.
---
 ChangeLog           |   16 ++++++++++++++++
 data/yacc.c         |   35 ++++++++++++-----------------------
 tests/regression.at |    9 ---------
 3 files changed, 28 insertions(+), 32 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c6a85e0..725b291 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
 2008-11-25  Akim Demaille  <address@hidden>
 
+       Get rid of yyrhs and yyprhs in yacc.c.
+       They were used to get the symbol types, given a rule number,  when
+       displaying the top of the stack before a reduction.  But the symbol type
+       is available from the state stack.  This has two be benefits: two tables
+       less in the parser (making it smaller), and a more consistent use of the
+       three stacks which will help to fuse them.
+       
+       * data/yacc.c (yyprhs, yyrhs): Remove.
+       (YY_REDUCE_PRINT): Pass yyssp to yy_reduce_print.
+       (yy_reduce_print): Take yyssp as argument.
+       Use it, together with yystos, to get the symbol type.
+       * tests/regression.at (Web2c Report): Remove these tables from the
+       expected output.
+
+2008-11-25  Akim Demaille  <address@hidden>
+
        b4_tables_map.
        The point is to factor the generation of the tables across skeletons.
        This is language dependant.
diff --git a/data/yacc.c b/data/yacc.c
index 872e63f..faec957 100644
--- a/data/yacc.c
+++ b/data/yacc.c
@@ -501,19 +501,6 @@ static const ]b4_int_type_for([b4_translate])[ 
yytranslate[] =
 };
 
 #if YYDEBUG
-/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
-   YYRHS.  */
-static const ]b4_int_type_for([b4_prhs])[ yyprhs[] =
-{
-  ]b4_prhs[
-};
-
-/* YYRHS -- A `-1'-separated list of the rules' RHS.  */
-static const ]b4_int_type_for([b4_rhs])[ yyrhs[] =
-{
-  ]b4_rhs[
-};
-
 /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
 static const ]b4_int_type_for([b4_rline])[ yyrline[] =
 {
@@ -748,24 +735,26 @@ do {                                                      
        \
 `------------------------------------------------*/
 
 ]b4_c_function_def([yy_reduce_print], [static void],
-                  [[YYSTYPE *yyvsp], [yyvsp]],
+                   [[yytype_int16 *yyssp], [yyssp]],
+                   [[YYSTYPE *yyvsp], [yyvsp]],
     b4_locations_if([[[YYLTYPE *yylsp], [yylsp]],
-                  ])[[int yyrule], [yyrule]]m4_ifset([b4_parse_param], [,
-                  b4_parse_param]))[
+                   ])[[int yyrule], [yyrule]]m4_ifset([b4_parse_param], [,
+                   b4_parse_param]))[
 {
+  unsigned long int yylno = yyrline[yyrule];
   int yynrhs = yyr2[yyrule];
   int yyi;
-  unsigned long int yylno = yyrline[yyrule];
   YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
-            yyrule - 1, yylno);
+             yyrule - 1, yylno);
   /* The symbols being reduced.  */
   for (yyi = 0; yyi < yynrhs; yyi++)
     {
       YYFPRINTF (stderr, "   $%d = ", yyi + 1);
-      yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
-                      &]b4_rhs_value(yynrhs, yyi + 1)[
-                      ]b4_locations_if([, &]b4_rhs_location(yynrhs, yyi + 
1))[]dnl
-                      b4_user_args[);
+      yy_symbol_print (stderr,
+                       yystos[yyssp[yyi + 1 - yynrhs]],
+                       &]b4_rhs_value(yynrhs, yyi + 1)[
+                       ]b4_locations_if([, &]b4_rhs_location(yynrhs, yyi + 
1))[]dnl
+                       b4_user_args[);
       YYFPRINTF (stderr, "\n");
     }
 }
@@ -773,7 +762,7 @@ do {                                                        
        \
 # define YY_REDUCE_PRINT(Rule)         \
 do {                                   \
   if (yydebug)                         \
-    yy_reduce_print (yyvsp, ]b4_locations_if([yylsp, ])[Rule]b4_user_args[); \
+    yy_reduce_print (yyssp, yyvsp, ]b4_locations_if([yylsp, 
])[Rule]b4_user_args[); \
 } while (YYID (0))
 
 /* Nonzero means print parse trace.  It is left uninitialized so that
diff --git a/tests/regression.at b/tests/regression.at
index 1845524..01bbb7a 100644
--- a/tests/regression.at
+++ b/tests/regression.at
@@ -754,15 +754,6 @@ AT_CHECK([[cat tables.c]], 0,
        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
        5,     6
 };
-static const yytype_uint8 yyprhs[] =
-{
-       0,     0,     3,     5,     6,     9,    14
-};
-static const yytype_int8 yyrhs[] =
-{
-       8,     0,    -1,     9,    -1,    -1,    10,    11,    -1,     3,
-       4,     5,     8,    -1,     6,     8,    -1
-};
 static const yytype_uint8 yyrline[] =
 {
        0,     2,     2,     3,     3,     4,     5
-- 
1.6.0.2.588.g3102





reply via email to

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