bison-patches
[Top][All Lists]
Advanced

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

14-state-print-lookadeads.patch


From: Akim Demaille
Subject: 14-state-print-lookadeads.patch
Date: Sat, 15 Jun 2002 20:19:52 +0200

Index: ChangeLog
from  Akim Demaille  <address@hidden>
        * src/state.h, src/state.c (state_rule_lookaheads_print): New.
        * src/print.c (print_core): Use it.
        
        
Index: src/print.c
--- src/print.c Sat, 15 Jun 2002 18:15:43 +0200 akim
+++ src/print.c Sat, 15 Jun 2002 18:45:08 +0200 akim
@@ -93,28 +93,7 @@
 
          /* Display the lookaheads?  */
          if (report_flag & report_lookaheads)
-           {
-             int j, k;
-             int nlookaheads = 0;
-             /* Look for lookaheads corresponding to this rule. */
-             for (j = 0; j < state->nlookaheads; ++j)
-               for (k = 0; k < ntokens; ++k)
-                 if (bitset_test (state->lookaheads[j], k)
-                     && state->lookaheads_rule[j]->number == rule)
-                   nlookaheads++;
-             if (nlookaheads)
-               {
-                 fprintf (out, "  [");
-                 for (j = 0; j < state->nlookaheads; ++j)
-                   for (k = 0; k < ntokens; ++k)
-                     if (bitset_test (state->lookaheads[j], k)
-                         && state->lookaheads_rule[j]->number == rule)
-                       fprintf (out, "%s%s",
-                                symbol_tag_get (symbols[k]),
-                                --nlookaheads ? ", " : "");
-                 fprintf (out, "]");
-               }
-           }
+           state_rule_lookaheads_print (state, &rules[rule], out);
 
          fprintf (out, _("   (rule %d)"), rule - 1);
          fputc ('\n', out);
Index: src/state.c
--- src/state.c Sun, 07 Apr 2002 21:22:52 +0200 akim
+++ src/state.c Sat, 15 Jun 2002 18:43:46 +0200 akim
@@ -81,3 +81,36 @@
   res->nreds = n;
   return res;
 }
+
+
+/*--------------------------------------------------------------.
+| Print on OUT all the lookaheads such that this STATE wants to |
+| reduce this RULE.                                             |
+`--------------------------------------------------------------*/
+
+void
+state_rule_lookaheads_print (state_t *state, rule_t *rule, FILE *out)
+{
+  int j, k;
+  int nlookaheads = 0;
+  /* Count the number of lookaheads corresponding to this rule.  */
+  for (j = 0; j < state->nlookaheads; ++j)
+    for (k = 0; k < ntokens; ++k)
+      if (bitset_test (state->lookaheads[j], k)
+         && state->lookaheads_rule[j]->number == rule->number)
+       nlookaheads++;
+
+  /* Print them if there are.  */
+  if (nlookaheads)
+    {
+      fprintf (out, "  [");
+      for (j = 0; j < state->nlookaheads; ++j)
+       for (k = 0; k < ntokens; ++k)
+         if (bitset_test (state->lookaheads[j], k)
+             && state->lookaheads_rule[j]->number == rule->number)
+           fprintf (out, "%s%s",
+                    symbol_tag_get (symbols[k]),
+                    --nlookaheads ? ", " : "");
+      fprintf (out, "]");
+    }
+}
Index: src/state.h
--- src/state.h Sat, 15 Jun 2002 18:39:00 +0200 akim
+++ src/state.h Sat, 15 Jun 2002 18:44:34 +0200 akim
@@ -199,4 +199,10 @@
   (state_t *) xcalloc ((unsigned) (sizeof (state_t)                    \
                                   + (Nitems - 1) * sizeof (item_number_t)), 1)
 
+/* Print on OUT all the lookaheads such that this STATE wants to
+   reduce this RULE.  */
+
+void state_rule_lookaheads_print PARAMS ((state_t *state, rule_t *rule,
+                                         FILE *out));
+
 #endif /* !STATE_H_ */



reply via email to

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