From c87d4863f6de617e0ed35dc566c59d5b4a072101 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 19 Nov 2001 10:38:12 +0000 Subject: [PATCH] * src/closure.c, src/derives.c, src/nullable.c: Adjust various trace messages. * src/LR0.c: Likewise. (allocate_itemsets): Use arrays instead of pointers to clarify. --- ChangeLog | 7 +++++++ src/LR0.c | 38 ++++++++++++++++++-------------------- src/closure.c | 45 +++++++++++++++++++++++++++++---------------- src/derives.c | 9 ++++----- src/nullable.c | 2 +- 5 files changed, 59 insertions(+), 42 deletions(-) diff --git a/ChangeLog b/ChangeLog index cd1080aa..936909ce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2001-11-19 Akim Demaille + + * src/closure.c, src/derives.c, src/nullable.c: Adjust various + trace messages. + * src/LR0.c: Likewise. + (allocate_itemsets): Use arrays instead of pointers to clarify. + 2001-11-19 Akim Demaille * src/getargs.c (statistics_flag): Replace with... diff --git a/src/LR0.c b/src/LR0.c index 3760a988..b67bd78b 100644 --- a/src/LR0.c +++ b/src/LR0.c @@ -24,6 +24,7 @@ #include "system.h" #include "getargs.h" +#include "reader.h" #include "gram.h" #include "state.h" #include "complain.h" @@ -61,8 +62,6 @@ static core **state_table = NULL; static void allocate_itemsets (void) { - short *itemp = NULL; - int symbol; int i; int count; short *symbol_count = NULL; @@ -70,17 +69,12 @@ allocate_itemsets (void) count = 0; symbol_count = XCALLOC (short, nsyms); - itemp = ritem; - symbol = *itemp++; - while (symbol) - { - if (symbol > 0) - { - count++; - symbol_count[symbol]++; - } - symbol = *itemp++; - } + for (i = 0; ritem[i]; ++i) + if (ritem[i] > 0) + { + count++; + symbol_count[ritem[i]]++; + } /* See comments before new_itemsets. All the vectors of items live inside KERNEL_ITEMS. The number of active items after @@ -149,7 +143,8 @@ new_itemsets (void) int shiftcount; if (trace_flag) - fprintf (stderr, "Entering new_itemsets, state = %d\n", nstates); + fprintf (stderr, "Entering new_itemsets, state = %d\n", + this_state->number); for (i = 0; i < nsyms; i++) kernel_end[i] = NULL; @@ -192,8 +187,8 @@ new_state (int symbol) core *p; if (trace_flag) - fprintf (stderr, "Entering new_state, state = %d, symbol = %d\n", - nstates, symbol); + fprintf (stderr, "Entering new_state, state = %d, symbol = %d (%s)\n", + this_state->number, symbol, tags[symbol]); if (nstates >= MAXSHORT) fatal (_("too many states (max %d)"), MAXSHORT); @@ -232,8 +227,8 @@ get_state (int symbol) int n = kernel_end[symbol] - kernel_base[symbol]; if (trace_flag) - fprintf (stderr, "Entering get_state, state = %d, symbol = %d\n", - nstates, symbol); + fprintf (stderr, "Entering get_state, state = %d, symbol = %d (%s)\n", + this_state->number, symbol, tags[symbol]); /* Add up the target state's active item numbers to get a hash key. */ @@ -276,6 +271,9 @@ get_state (int symbol) state_table[key] = sp = new_state (symbol); } + if (trace_flag) + fprintf (stderr, "Exiting get_state => %d\n", sp->number); + return sp->number; } @@ -294,8 +292,8 @@ append_states (void) int symbol; if (trace_flag) - fprintf (stderr, "Entering append_states\n"); - + fprintf (stderr, "Entering append_states, state = %d\n", + this_state->number); /* first sort shift_symbol into increasing order */ diff --git a/src/closure.c b/src/closure.c index b06d808f..d4637a61 100644 --- a/src/closure.c +++ b/src/closure.c @@ -34,6 +34,9 @@ static unsigned *ruleset; static unsigned *fderives; static unsigned *firsts; +#define FDERIVES(Symbol) (fderives + (Symbol) * rulesetsize) +#define FIRSTS(Symbol) (firsts + (Symbol) * varsetsize) + /* number of words required to hold a bit for each rule */ static int rulesetsize; @@ -50,9 +53,10 @@ print_closure (int n) { short *isp; - fprintf (stderr, "\n\nn = %d\n\n", n); + fprintf (stderr, "n = %d\n", n); for (isp = itemset; isp < itemsetend; isp++) fprintf (stderr, " %d\n", *isp); + fprintf (stderr, "\n\n"); } @@ -63,18 +67,19 @@ print_firsts (void) int j; unsigned *rowp; - fprintf (stderr, "\n\n\nFIRSTS\n\n"); + fprintf (stderr, "FIRSTS\n"); for (i = ntokens; i < nsyms; i++) { - fprintf (stderr, "\n\n%s firsts\n\n", tags[i]); + fprintf (stderr, "\t%s firsts\n", tags[i]); - rowp = firsts + ((i - ntokens) * varsetsize); + rowp = FIRSTS (i - ntokens); for (j = 0; j < nvars; j++) if (BITISSET (rowp, j)) - fprintf (stderr, " %s\n", tags[j + ntokens]); + fprintf (stderr, "\t\t%d (%s)\n", j + ntokens, tags[j + ntokens]); } + fprintf (stderr, "\n\n"); } @@ -85,17 +90,18 @@ print_fderives (void) int j; unsigned *rp; - fprintf (stderr, "\n\n\nFDERIVES\n"); + fprintf (stderr, "FDERIVES\n"); for (i = ntokens; i < nsyms; i++) { - fprintf (stderr, "\n\n%s derives\n\n", tags[i]); - rp = fderives + i * rulesetsize; + fprintf (stderr, "\t%s derives\n", tags[i]); + rp = FDERIVES (i); for (j = 0; j <= nrules; j++) if (BITISSET (rp, j)) - fprintf (stderr, " %d\n", j); + fprintf (stderr, "\t\t%d (%s)\n", j, tags[j]); } + fprintf (stderr, "\n\n"); } /*-------------------------------------------------------------------. @@ -172,11 +178,11 @@ set_fderives (void) set_firsts (); - rrow = fderives + ntokens * rulesetsize; + rrow = FDERIVES (ntokens); for (i = ntokens; i < nsyms; i++) { - vrow = firsts + ((i - ntokens) * varsetsize); + vrow = FIRSTS (i - ntokens); cword = *vrow++; b = 0; for (j = ntokens; j < nsyms; j++) @@ -185,9 +191,7 @@ set_fderives (void) { rp = derives[j]; while ((ruleno = *rp++) > 0) - { - SETBIT (rrow, ruleno); - } + SETBIT (rrow, ruleno); } b++; @@ -235,13 +239,22 @@ closure (short *core, int n) int symbol; int itemno; + if (trace_flag) + { + int i; + fprintf (stderr, "Entering closure (items = {"); + for (i = 0; i < n; ++i) + fprintf (stderr, " %d ", core[i]); + fprintf (stderr, "}, nitems = %d)\n", n); + } + rsp = ruleset; rsend = ruleset + rulesetsize; csend = core + n; if (n == 0) { - dsp = fderives + start_symbol * rulesetsize; + dsp = FDERIVES (start_symbol); while (rsp < rsend) *rsp++ = *dsp++; } @@ -256,7 +269,7 @@ closure (short *core, int n) symbol = ritem[*csp++]; if (ISVAR (symbol)) { - dsp = fderives + symbol * rulesetsize; + dsp = FDERIVES (symbol); rsp = ruleset; while (rsp < rsend) *rsp++ |= *dsp++; diff --git a/src/derives.c b/src/derives.c index 7b862d82..3a34a30f 100644 --- a/src/derives.c +++ b/src/derives.c @@ -40,17 +40,16 @@ print_derives (void) int i; short *sp; - fputs ("\n\n\nDERIVES\n\n", stderr); + fputs ("DERIVES\n", stderr); for (i = ntokens; i < nsyms; i++) { - fprintf (stderr, "%s derives", tags[i]); + fprintf (stderr, "\t%s derives\n", tags[i]); for (sp = derives[i]; *sp > 0; sp++) - fprintf (stderr, " %d", *sp); - putc ('\n', stderr); + fprintf (stderr, "\t\t%d (%s)\n", *sp, tags[*sp]); } - putc ('\n', stderr); + fputs ("\n\n", stderr); } diff --git a/src/nullable.c b/src/nullable.c index eedc5a33..ec614595 100644 --- a/src/nullable.c +++ b/src/nullable.c @@ -49,7 +49,7 @@ set_nullable (void) short *r1; if (trace_flag) - fprintf (stderr, "Entering set_nullable"); + fprintf (stderr, "Entering set_nullable\n"); nullable = XCALLOC (char, nvars) - ntokens; -- 2.45.2