#include "derives.h"
#include "warshall.h"
+/* ITEMSETSIZE is the size of the array ITEMSET. */
short *itemset;
-short *itemsetend;
+int itemsetsize;
+
static unsigned *ruleset;
/* internal data. See comments before set_fderives and set_firsts. */
static void
print_closure (int n)
{
- short *isp;
-
+ int i;
fprintf (stderr, "n = %d\n", n);
- for (isp = itemset; isp < itemsetend; isp++)
- fprintf (stderr, " %d\n", *isp);
+ for (i = 0; i < itemsetsize; ++i)
+ fprintf (stderr, " %d\n", itemset[i]);
fprintf (stderr, "\n\n");
}
for (j = 0; j <= nrules; j++)
if (BITISSET (rp, j))
- fprintf (stderr, "\t\t%d (%s)\n", j, tags[j]);
+ {
+ short *rhsp;
+ fprintf (stderr, "\t\t%d:", j);
+ for (rhsp = ritem + rule_table[j].rhs; *rhsp > 0; ++rhsp)
+ fprintf (stderr, " %s", tags[*rhsp]);
+ fputc ('\n', stderr);
+ }
}
fprintf (stderr, "\n\n");
}
closure (short *core, int n)
{
int ruleno;
- unsigned word;
short *csp;
- unsigned *dsp;
- unsigned *rsp;
- short *csend;
- unsigned *rsend;
- int symbol;
int itemno;
+ int i;
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);
- while (rsp < rsend)
- *rsp++ = *dsp++;
+ for (i = 0; i < rulesetsize; ++i)
+ ruleset[i] = FDERIVES (start_symbol)[i];
}
else
{
- while (rsp < rsend)
- *rsp++ = 0;
+ for (i = 0; i < rulesetsize; ++i)
+ ruleset[i] = 0;
- csp = core;
- while (csp < csend)
+ for (i = 0; i < n; ++i)
{
- symbol = ritem[*csp++];
+ int symbol = ritem[core[i]];
if (ISVAR (symbol))
{
- dsp = FDERIVES (symbol);
- rsp = ruleset;
- while (rsp < rsend)
- *rsp++ |= *dsp++;
+ int j;
+ for (j = 0; j < rulesetsize; ++j)
+ ruleset[j] |= FDERIVES (symbol)[j];
}
}
}
ruleno = 0;
- itemsetend = itemset;
+ itemsetsize = 0;
csp = core;
- rsp = ruleset;
- while (rsp < rsend)
+ for (i = 0; i < rulesetsize; ++i)
{
- word = *rsp++;
+ int word = ruleset[i];
if (word == 0)
{
ruleno += BITS_PER_WORD;
if (word & (1 << b))
{
itemno = rule_table[ruleno].rhs;
- while (csp < csend && *csp < itemno)
- *itemsetend++ = *csp++;
- *itemsetend++ = itemno;
+ while (csp < (core + n) && *csp < itemno)
+ itemset[itemsetsize++] = *csp++;
+ itemset[itemsetsize++] = itemno;
}
ruleno++;
}
}
- while (csp < csend)
- *itemsetend++ = *csp++;
+ while (csp < (core + n))
+ itemset[itemsetsize++] = *csp++;
if (trace_flag)
print_closure (n);