bison-patches
[Top][All Lists]
Advanced

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

04-fyi-trace-lookaheads.patch


From: Akim Demaille
Subject: 04-fyi-trace-lookaheads.patch
Date: Sat, 29 Dec 2001 15:13:32 +0100

Index: ChangeLog
from  Akim Demaille  <address@hidden>
        * src/lalr.c (lookaheads_print): New.
        (lalr): Call it when --trace-flag.
        * tests/sets.at (Nullable): Adjust: when tracing, the lookaheads
        are dumped.
        
        
Index: src/lalr.c
--- src/lalr.c Fri, 28 Dec 2001 14:55:09 +0100 akim
+++ src/lalr.c Fri, 28 Dec 2001 14:58:19 +0100 akim
@@ -24,6 +24,7 @@
    tokens they accept.  */
 
 #include "system.h"
+#include "reader.h"
 #include "types.h"
 #include "LR0.h"
 #include "gram.h"
@@ -546,6 +547,31 @@
     }
 }
 
+
+/*---------------------------------------.
+| Output the lookaheads for each state.  |
+`---------------------------------------*/
+
+static void
+lookaheads_print (FILE *out)
+{
+  int i, j, k;
+  fprintf (out, "Lookaheads: BEGIN\n");
+  for (i = 0; i < nstates; ++i)
+    {
+      fprintf (out, "State %d: %d lookaheads\n",
+              i, state_table[i]->nlookaheads);
+
+      for (j = 0; j < state_table[i]->nlookaheads; ++j)
+       for (k = 0; k < ntokens; ++k)
+         if (BITISSET (LA (state_table[i]->lookaheadsp + j), j))
+           fprintf (out, "   on %d (%s) -> rule %d\n",
+                    k, tags[k],
+                    -LAruleno[state_table[i]->lookaheadsp + j] - 1);
+    }
+  fprintf (out, "Lookaheads: END\n");
+}
+
 void
 lalr (void)
 {
@@ -558,4 +584,7 @@
   build_relations ();
   compute_FOLLOWS ();
   compute_lookaheads ();
+
+  if (trace_flag)
+    lookaheads_print (stderr);
 }
Index: tests/sets.at
--- tests/sets.at Fri, 28 Dec 2001 14:55:09 +0100 akim
+++ tests/sets.at Fri, 28 Dec 2001 14:59:23 +0100 akim
@@ -157,6 +157,12 @@ transpose: input
 transpose: output
   0:
 
+Lookaheads: BEGIN
+State 0: 0 lookaheads
+State 1: 0 lookaheads
+State 2: 0 lookaheads
+State 3: 0 lookaheads
+Lookaheads: END
 ]])
 
 AT_CLEANUP



reply via email to

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