+2002-07-03 Akim Demaille <akim@epita.fr>
+
+ * src/closure.c (print_fderives): Use rule_rhs_print.
+ * src/derives.c (print_derives): Use rule_rhs_print.
+ (rule_list_t): New, replaces `shorts'.
+ (set_derives): Add comments.
+ * tests/sets.at (Nullable, Firsts): Adjust.
+
2002-07-03 Akim Demaille <akim@epita.fr>
* src/output.c (prepare_actions): Free `tally' and `width'.
* src/scan-skel.l: here.
(<<EOF>>): Close yyout, and free its name.
-
+
2002-07-03 Akim Demaille <akim@epita.fr>
Fix some memory leaks, and fix a bug: state 0 was examined twice.
fprintf (stderr, "\t%s derives\n", symbols[i]->tag);
BITSET_FOR_EACH (iter, FDERIVES (i), r, 0)
{
- item_number_t *rhsp = NULL;
- fprintf (stderr, "\t\t%d:", r - 1);
- for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp)
- fprintf (stderr, " %s", symbols[*rhsp]->tag);
- fputc ('\n', stderr);
+ fprintf (stderr, "\t\t%3d ", r);
+ rule_rhs_print (&rules[r], stderr);
}
}
fprintf (stderr, "\n\n");
#include "gram.h"
#include "derives.h"
+/* Linked list of rule numbers. */
+typedef struct rule_list_s
+{
+ struct rule_list_s *next;
+ rule_number_t value;
+} rule_list_t;
+
rule_number_t **derives = NULL;
static void
fprintf (stderr, "\t%s derives\n", symbols[i]->tag);
for (rp = derives[i]; *rp > 0; rp++)
{
- item_number_t *rhsp;
- fprintf (stderr, "\t\t%d:", *rp);
- for (rhsp = rules[*rp].rhs; *rhsp >= 0; ++rhsp)
- fprintf (stderr, " %s", symbols[*rhsp]->tag);
- fprintf (stderr, " (rule %d)\n",
- rule_number_of_item_number (*rhsp) - 1);
+ fprintf (stderr, "\t\t%3d ", *rp - 1);
+ rule_rhs_print (&rules[*rp], stderr);
}
}
{
symbol_number_t i;
rule_number_t r;
- shorts *p;
rule_number_t *q;
- shorts **dset;
- shorts *delts;
- dset = XCALLOC (shorts *, nvars) - ntokens;
- delts = XCALLOC (shorts, nrules + 1);
+ /* DSET[NTERM] -- A linked list of the numbers of the rules whose
+ LHS is NTERM. */
+ rule_list_t **dset = XCALLOC (rule_list_t *, nvars) - ntokens;
+
+ /* DELTS[RULE] -- There are NRULES rule number to attach to nterms.
+ Instead of performing NRULES allocations for each, have an array
+ indexed by rule numbers. */
+ rule_list_t *delts = XCALLOC (rule_list_t, nrules + 1);
- p = delts;
for (r = nrules; r > 0; r--)
{
symbol_number_t lhs = rules[r].lhs->number;
+ rule_list_t *p = &delts[r];
+ /* A new LHS is found. */
p->next = dset[lhs];
p->value = r;
dset[lhs] = p;
- p++;
}
+ /* DSET contains what we need under the form of a linked list. Make
+ it a single array. */
+
derives = XCALLOC (rule_number_t *, nvars) - ntokens;
- q = XCALLOC (short, nvars + int_of_rule_number (nrules));
+ q = XCALLOC (rule_number_t, nvars + int_of_rule_number (nrules));
for (i = ntokens; i < nsyms; i++)
{
+ rule_list_t *p = dset[i];
derives[i] = q;
- p = dset[i];
while (p)
{
*q++ = p->value;
if (trace_flag)
print_derives ();
- XFREE (dset + ntokens);
- XFREE (delts);
+ free (dset + ntokens);
+ free (delts);
}
+
void
free_derives (void)
{
AT_CHECK([[cat sets]], [],
[[DERIVES
$axiom derives
- 1: e $ (rule 0)
+ 0 e $
e derives
- 2: 'e' (rule 1)
- 3: (rule 2)
+ 1 'e'
+ 2 /* empty */
NULLABLE
$axiom: no
e: yes
e
FDERIVES
$axiom derives
- 0: e $
- 1: 'e'
- 2:
+ 1 e $
+ 2 'e'
+ 3 /* empty */
e derives
- 1: 'e'
- 2:
+ 2 'e'
+ 3 /* empty */
]])
AT_CLEANUP
AT_CHECK([[cat sets]], [],
[[DERIVES
$axiom derives
- 1: exp $ (rule 0)
+ 0 exp $
exp derives
- 2: exp '<' exp (rule 1)
- 3: exp '>' exp (rule 2)
- 4: exp '+' exp (rule 3)
- 5: exp '-' exp (rule 4)
- 6: exp '^' exp (rule 5)
- 7: exp '=' exp (rule 6)
- 8: "exp" (rule 7)
+ 1 exp '<' exp
+ 2 exp '>' exp
+ 3 exp '+' exp
+ 4 exp '-' exp
+ 5 exp '^' exp
+ 6 exp '=' exp
+ 7 "exp"
NULLABLE
$axiom: no
exp: no
exp
FDERIVES
$axiom derives
- 0: exp $
- 1: exp '<' exp
- 2: exp '>' exp
- 3: exp '+' exp
- 4: exp '-' exp
- 5: exp '^' exp
- 6: exp '=' exp
- 7: "exp"
+ 1 exp $
+ 2 exp '<' exp
+ 3 exp '>' exp
+ 4 exp '+' exp
+ 5 exp '-' exp
+ 6 exp '^' exp
+ 7 exp '=' exp
+ 8 "exp"
exp derives
- 1: exp '<' exp
- 2: exp '>' exp
- 3: exp '+' exp
- 4: exp '-' exp
- 5: exp '^' exp
- 6: exp '=' exp
- 7: "exp"
+ 2 exp '<' exp
+ 3 exp '>' exp
+ 4 exp '+' exp
+ 5 exp '-' exp
+ 6 exp '^' exp
+ 7 exp '=' exp
+ 8 "exp"
]])
AT_CLEANUP