From 7c6b64d02355fa26b3a256906327ab3edbbee8b7 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sat, 29 Dec 2001 14:16:16 +0000 Subject: [PATCH] * src/lalr.c (lookaheads_print): New. (lalr): Call it when --trace-flag. * tests/sets.at (Nullable): Adjust: when tracing, the lookaheads are dumped. --- ChangeLog | 8 ++++++++ src/lalr.c | 29 +++++++++++++++++++++++++++++ tests/sets.at | 6 ++++++ 3 files changed, 43 insertions(+) diff --git a/ChangeLog b/ChangeLog index e16dafb4..e335f058 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2001-12-29 Akim Demaille + + * src/lalr.c (lookaheads_print): New. + (lalr): Call it when --trace-flag. + * tests/sets.at (Nullable): Adjust: when tracing, the lookaheads + are dumped. + + 2001-12-29 Akim Demaille * src/derives.c (print_derives): Be sure to use `>= 0', not `> 0', diff --git a/src/lalr.c b/src/lalr.c index 660088cd..36a8607c 100644 --- a/src/lalr.c +++ b/src/lalr.c @@ -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 @@ initialize_lookaheads (void) } } + +/*---------------------------------------. +| 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 @@ lalr (void) build_relations (); compute_FOLLOWS (); compute_lookaheads (); + + if (trace_flag) + lookaheads_print (stderr); } diff --git a/tests/sets.at b/tests/sets.at index 61bfd623..f1c16dcf 100644 --- a/tests/sets.at +++ b/tests/sets.at @@ -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 -- 2.45.2