when walking through ritem, even via rule->rhs.
* src/reduce.c (dump_grammar, useful_production, reduce_output)
(useful_production, useless_nonterminals): Likewise.
(reduce_grammar_tables): Likewise, plus update nritems.
* src/nullable.c (set_nullable): Likewise.
* src/lalr.c (build_relations): Likewise.
* tests/sets.at (Nullable): Adjust.
Fortunately, now, the $axiom is no longer nullable.
+2001-12-29 Akim Demaille <akim@epita.fr>
+
+ * src/derives.c (print_derives): Be sure to use `>= 0', not `> 0',
+ when walking through ritem, even via rule->rhs.
+ * src/reduce.c (dump_grammar, useful_production, reduce_output)
+ (useful_production, useless_nonterminals): Likewise.
+ (reduce_grammar_tables): Likewise, plus update nritems.
+ * src/nullable.c (set_nullable): Likewise.
+ * src/lalr.c (build_relations): Likewise.
+ * tests/sets.at (Nullable): Adjust.
+ Fortunately, now, the $axiom is no longer nullable.
+
+
2001-12-29 Akim Demaille <akim@epita.fr>
* src/LR0.c (generate_states): Use nritems, not nitems, nor using
{
short *rhsp;
fprintf (stderr, "\t\t%d:", *sp);
- for (rhsp = ritem + rule_table[*sp].rhs; *rhsp > 0; ++rhsp)
+ for (rhsp = ritem + rule_table[*sp].rhs; *rhsp >= 0; ++rhsp)
fprintf (stderr, " %s", tags[*rhsp]);
- fprintf (stderr, " (rule %d)\n", -*rhsp);
+ fprintf (stderr, " (rule %d)\n", -*rhsp - 1);
}
}
state_t *state = state_table[from_state[i]];
states[0] = state->number;
- for (rp = ritem + rule_table[*rulep].rhs; *rp > 0; rp++)
+ for (rp = &ritem[rule_table[*rulep].rhs]; *rp >= 0; rp++)
{
shifts *sp = state->shifts;
int j;
for (ruleno = 1; ruleno < nrules + 1; ++ruleno)
if (rule_table[ruleno].useful)
{
- if (ritem[rule_table[ruleno].rhs] > 0)
+ if (ritem[rule_table[ruleno].rhs] >= 0)
{
/* This rule has a non empty RHS. */
short *r;
int any_tokens = 0;
- for (r = ritem + rule_table[ruleno].rhs; *r > 0; ++r)
+ for (r = &ritem[rule_table[ruleno].rhs]; *r >= 0; ++r)
if (ISTOKEN (*r))
any_tokens = 1;
/* This rule has only nonterminals: schedule it for the second
pass. */
if (!any_tokens)
- for (r = ritem + rule_table[ruleno].rhs; *r > 0; ++r)
+ for (r = &ritem[rule_table[ruleno].rhs]; *r >= 0; ++r)
{
rcount[ruleno]++;
p->next = rsets[*r];
/* A production is useful if all of the nonterminals in its appear
in the set of useful nonterminals. */
- for (r = &ritem[rule_table[i].rhs]; *r > 0; r++)
+ for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++)
if (ISVAR (n = *r))
if (!BITISSET (N0, n - ntokens))
return FALSE;
}
else
{
- while (ritem[ni++] >= 0);
+ while (ritem[ni++] >= 0)
+ /* Nothing. */;
}
}
ritem[ni] = 0;
nrules -= nuseless_productions;
nitems = ni;
+ nritems = ni;
/* Is it worth it to reduce the amount of memory for the
grammar? Probably not. */
{
int rhs_count = 0;
/* Find the last RHS index in ritems. */
- for (r = &ritem[rule_table[i].rhs]; *r > 0; ++r)
+ for (r = &ritem[rule_table[i].rhs]; *r >= 0; ++r)
++rhs_count;
fprintf (out, "%3d (%2d, %2d, %2d, %2d-%2d) %2d ->",
- i,
+ i - 1,
rule_table[i].prec, rule_table[i].assoc, rule_table[i].useful,
rule_table[i].rhs, rule_table[i].rhs + rhs_count - 1,
rule_table[i].lhs);
/* Dumped the RHS. */
- for (r = &ritem[rule_table[i].rhs]; *r > 0; r++)
+ for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++)
fprintf (out, "%3d", *r);
- fprintf (out, " [%d]\n", -(*r));
+ fprintf (out, " [%d]\n", -(*r) - 1);
}
fprintf (out, "\n\n");
fprintf (out, "Rules interpreted\n-----------------\n\n");
for (i = 1; i <= nrules; i++)
{
fprintf (out, "%-5d %s :", i, tags[rule_table[i].lhs]);
- for (r = &ritem[rule_table[i].rhs]; *r > 0; r++)
+ for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++)
fprintf (out, " %s", tags[*r]);
fputc ('\n', out);
}
DERIVES
$axiom derives
- 1: e (rule 0)
+ 1: e $ (rule 0)
e derives
- 2: 'e' (rule 2)
- 3: (rule 3)
+ 2: 'e' (rule 1)
+ 3: (rule 2)
Entering set_nullable
NULLABLE
- $axiom: yes
+ $axiom: no
e: yes