From 3d4daee37491bab92ce270b37b257aadcf709c3c Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sat, 29 Dec 2001 14:15:33 +0000 Subject: [PATCH] * 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. --- ChangeLog | 13 +++++++++++++ src/derives.c | 4 ++-- src/lalr.c | 2 +- src/nullable.c | 6 +++--- src/reduce.c | 16 +++++++++------- tests/sets.at | 8 ++++---- 6 files changed, 32 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index bb362090..e16dafb4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2001-12-29 Akim Demaille + + * 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 * src/LR0.c (generate_states): Use nritems, not nitems, nor using diff --git a/src/derives.c b/src/derives.c index ab7cc326..8ca038f8 100644 --- a/src/derives.c +++ b/src/derives.c @@ -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); } } diff --git a/src/lalr.c b/src/lalr.c index db9abfa3..660088cd 100644 --- a/src/lalr.c +++ b/src/lalr.c @@ -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; diff --git a/src/nullable.c b/src/nullable.c index bce291ca..0b6d614f 100644 --- a/src/nullable.c +++ b/src/nullable.c @@ -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]; diff --git a/src/reduce.c b/src/reduce.c index 2b633c2a..430e5b08 100644 --- a/src/reduce.c +++ b/src/reduce.c @@ -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); } diff --git a/tests/sets.at b/tests/sets.at index a0740790..61bfd623 100644 --- a/tests/sets.at +++ b/tests/sets.at @@ -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 -- 2.45.2