* 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.
This commit is contained in:
Akim Demaille
2001-12-29 14:15:33 +00:00
parent 9e7f6bbd59
commit 3d4daee374
6 changed files with 32 additions and 17 deletions

View File

@@ -1,3 +1,16 @@
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

View File

@@ -43,9 +43,9 @@ print_derives (void)
{
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);
}
}

View File

@@ -418,7 +418,7 @@ build_relations (void)
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;

View File

@@ -71,19 +71,19 @@ set_nullable (void)
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];

View File

@@ -107,7 +107,7 @@ useful_production (int i, BSet N0)
/* 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;
@@ -304,13 +304,15 @@ reduce_grammar_tables (void)
}
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. */
@@ -466,24 +468,24 @@ dump_grammar (FILE *out)
{
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);
}

View File

@@ -49,15 +49,15 @@ AT_CHECK([[sed 's/[ ]*$//' stderr]], [],
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