* 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.
This commit is contained in:
Akim Demaille
2001-11-19 09:25:36 +00:00
parent 3b2925a060
commit 64fabbb49f
5 changed files with 61 additions and 44 deletions

View File

@@ -1,3 +1,10 @@
2001-11-19 Akim Demaille <akim@epita.fr>
* 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 <akim@epita.fr> 2001-11-19 Akim Demaille <akim@epita.fr>
* src/getargs.c (statistics_flag): Replace with... * src/getargs.c (statistics_flag): Replace with...

View File

@@ -24,6 +24,7 @@
#include "system.h" #include "system.h"
#include "getargs.h" #include "getargs.h"
#include "reader.h"
#include "gram.h" #include "gram.h"
#include "state.h" #include "state.h"
#include "complain.h" #include "complain.h"
@@ -61,8 +62,6 @@ static core **state_table = NULL;
static void static void
allocate_itemsets (void) allocate_itemsets (void)
{ {
short *itemp = NULL;
int symbol;
int i; int i;
int count; int count;
short *symbol_count = NULL; short *symbol_count = NULL;
@@ -70,17 +69,12 @@ allocate_itemsets (void)
count = 0; count = 0;
symbol_count = XCALLOC (short, nsyms); symbol_count = XCALLOC (short, nsyms);
itemp = ritem; for (i = 0; ritem[i]; ++i)
symbol = *itemp++; if (ritem[i] > 0)
while (symbol) {
{ count++;
if (symbol > 0) symbol_count[ritem[i]]++;
{ }
count++;
symbol_count[symbol]++;
}
symbol = *itemp++;
}
/* See comments before new_itemsets. All the vectors of items /* See comments before new_itemsets. All the vectors of items
live inside KERNEL_ITEMS. The number of active items after live inside KERNEL_ITEMS. The number of active items after
@@ -149,7 +143,8 @@ new_itemsets (void)
int shiftcount; int shiftcount;
if (trace_flag) 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++) for (i = 0; i < nsyms; i++)
kernel_end[i] = NULL; kernel_end[i] = NULL;
@@ -192,8 +187,8 @@ new_state (int symbol)
core *p; core *p;
if (trace_flag) if (trace_flag)
fprintf (stderr, "Entering new_state, state = %d, symbol = %d\n", fprintf (stderr, "Entering new_state, state = %d, symbol = %d (%s)\n",
nstates, symbol); this_state->number, symbol, tags[symbol]);
if (nstates >= MAXSHORT) if (nstates >= MAXSHORT)
fatal (_("too many states (max %d)"), MAXSHORT); fatal (_("too many states (max %d)"), MAXSHORT);
@@ -232,8 +227,8 @@ get_state (int symbol)
int n = kernel_end[symbol] - kernel_base[symbol]; int n = kernel_end[symbol] - kernel_base[symbol];
if (trace_flag) if (trace_flag)
fprintf (stderr, "Entering get_state, state = %d, symbol = %d\n", fprintf (stderr, "Entering get_state, state = %d, symbol = %d (%s)\n",
nstates, symbol); this_state->number, symbol, tags[symbol]);
/* Add up the target state's active item numbers to get a hash key. /* 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); state_table[key] = sp = new_state (symbol);
} }
if (trace_flag)
fprintf (stderr, "Exiting get_state => %d\n", sp->number);
return sp->number; return sp->number;
} }
@@ -294,8 +292,8 @@ append_states (void)
int symbol; int symbol;
if (trace_flag) 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 */ /* first sort shift_symbol into increasing order */

View File

@@ -34,6 +34,9 @@ static unsigned *ruleset;
static unsigned *fderives; static unsigned *fderives;
static unsigned *firsts; 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 */ /* number of words required to hold a bit for each rule */
static int rulesetsize; static int rulesetsize;
@@ -50,9 +53,10 @@ print_closure (int n)
{ {
short *isp; short *isp;
fprintf (stderr, "\n\nn = %d\n\n", n); fprintf (stderr, "n = %d\n", n);
for (isp = itemset; isp < itemsetend; isp++) for (isp = itemset; isp < itemsetend; isp++)
fprintf (stderr, " %d\n", *isp); fprintf (stderr, " %d\n", *isp);
fprintf (stderr, "\n\n");
} }
@@ -63,18 +67,19 @@ print_firsts (void)
int j; int j;
unsigned *rowp; unsigned *rowp;
fprintf (stderr, "\n\n\nFIRSTS\n\n"); fprintf (stderr, "FIRSTS\n");
for (i = ntokens; i < nsyms; i++) 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++) for (j = 0; j < nvars; j++)
if (BITISSET (rowp, 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; int j;
unsigned *rp; unsigned *rp;
fprintf (stderr, "\n\n\nFDERIVES\n"); fprintf (stderr, "FDERIVES\n");
for (i = ntokens; i < nsyms; i++) for (i = ntokens; i < nsyms; i++)
{ {
fprintf (stderr, "\n\n%s derives\n\n", tags[i]); fprintf (stderr, "\t%s derives\n", tags[i]);
rp = fderives + i * rulesetsize; rp = FDERIVES (i);
for (j = 0; j <= nrules; j++) for (j = 0; j <= nrules; j++)
if (BITISSET (rp, 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 (); set_firsts ();
rrow = fderives + ntokens * rulesetsize; rrow = FDERIVES (ntokens);
for (i = ntokens; i < nsyms; i++) for (i = ntokens; i < nsyms; i++)
{ {
vrow = firsts + ((i - ntokens) * varsetsize); vrow = FIRSTS (i - ntokens);
cword = *vrow++; cword = *vrow++;
b = 0; b = 0;
for (j = ntokens; j < nsyms; j++) for (j = ntokens; j < nsyms; j++)
@@ -185,9 +191,7 @@ set_fderives (void)
{ {
rp = derives[j]; rp = derives[j];
while ((ruleno = *rp++) > 0) while ((ruleno = *rp++) > 0)
{ SETBIT (rrow, ruleno);
SETBIT (rrow, ruleno);
}
} }
b++; b++;
@@ -235,13 +239,22 @@ closure (short *core, int n)
int symbol; int symbol;
int itemno; 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; rsp = ruleset;
rsend = ruleset + rulesetsize; rsend = ruleset + rulesetsize;
csend = core + n; csend = core + n;
if (n == 0) if (n == 0)
{ {
dsp = fderives + start_symbol * rulesetsize; dsp = FDERIVES (start_symbol);
while (rsp < rsend) while (rsp < rsend)
*rsp++ = *dsp++; *rsp++ = *dsp++;
} }
@@ -256,7 +269,7 @@ closure (short *core, int n)
symbol = ritem[*csp++]; symbol = ritem[*csp++];
if (ISVAR (symbol)) if (ISVAR (symbol))
{ {
dsp = fderives + symbol * rulesetsize; dsp = FDERIVES (symbol);
rsp = ruleset; rsp = ruleset;
while (rsp < rsend) while (rsp < rsend)
*rsp++ |= *dsp++; *rsp++ |= *dsp++;

View File

@@ -40,17 +40,16 @@ print_derives (void)
int i; int i;
short *sp; short *sp;
fputs ("\n\n\nDERIVES\n\n", stderr); fputs ("DERIVES\n", stderr);
for (i = ntokens; i < nsyms; i++) 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++) for (sp = derives[i]; *sp > 0; sp++)
fprintf (stderr, " %d", *sp); fprintf (stderr, "\t\t%d (%s)\n", *sp, tags[*sp]);
putc ('\n', stderr);
} }
putc ('\n', stderr); fputs ("\n\n", stderr);
} }

View File

@@ -24,6 +24,7 @@
do so. */ do so. */
#include "system.h" #include "system.h"
#include "getargs.h"
#include "types.h" #include "types.h"
#include "gram.h" #include "gram.h"
#include "nullable.h" #include "nullable.h"
@@ -47,9 +48,8 @@ set_nullable (void)
char any_tokens; char any_tokens;
short *r1; short *r1;
#ifdef TRACE if (trace_flag)
fprintf (stderr, "Entering set_nullable\n"); fprintf (stderr, "Entering set_nullable\n");
#endif
nullable = XCALLOC (char, nvars) - ntokens; nullable = XCALLOC (char, nvars) - ntokens;