From: Akim Demaille Date: Sun, 7 Apr 2002 15:29:36 +0000 (+0000) Subject: * src/closure.c, src/derives.c, src/gram.h, src/lalr.c, X-Git-Tag: BISON-1_49a~87 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/99013900121bb2de1197f5d0768749f9e50ccb8a * src/closure.c, src/derives.c, src/gram.h, src/lalr.c, * src/nullable.c, src/output.c, src/print.c, src/print_graph.c, * src/reader.c, src/reduce.c: Let rule_t.rhs point directly to the RHS, instead of being an index in RITEMS. --- diff --git a/ChangeLog b/ChangeLog index 6ae6f0ba..713c5fc7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2002-04-07 Akim Demaille + + * src/closure.c, src/derives.c, src/gram.h, src/lalr.c, + * src/nullable.c, src/output.c, src/print.c, src/print_graph.c, + * src/reader.c, src/reduce.c: Let rule_t.rhs point directly to the + RHS, instead of being an index in RITEMS. + 2002-04-04 Paul Eggert * doc/bison.texinfo: Update copyright date. diff --git a/src/closure.c b/src/closure.c index 06c50364..df240fbe 100644 --- a/src/closure.c +++ b/src/closure.c @@ -96,7 +96,7 @@ print_fderives (void) { short *rhsp; fprintf (stderr, "\t\t%d:", j - 1); - for (rhsp = &ritem[rules[j].rhs]; *rhsp >= 0; ++rhsp) + for (rhsp = rules[j].rhs; *rhsp >= 0; ++rhsp) fprintf (stderr, " %s", symbols[*rhsp]->tag); fputc ('\n', stderr); } @@ -173,7 +173,7 @@ set_firsts (void) for (i = ntokens; i < nsyms; i++) for (j = 0; derives[i][j] >= 0; ++j) { - int symbol = ritem[rules[derives[i][j]].rhs]; + int symbol = rules[derives[i][j]].rhs[0]; if (ISVAR (symbol)) bitset_set (FIRSTS (i), symbol - ntokens); } @@ -262,7 +262,7 @@ closure (short *core, int n) for (ruleno = 0; ruleno < nrules + 1; ++ruleno) if (bitset_test (ruleset, ruleno)) { - int itemno = rules[ruleno].rhs; + int itemno = rules[ruleno].rhs - ritem; while (c < n && core[c] < itemno) { itemset[nitemset] = core[c]; diff --git a/src/derives.c b/src/derives.c index 795bc08e..39c50280 100644 --- a/src/derives.c +++ b/src/derives.c @@ -44,7 +44,7 @@ print_derives (void) { short *rhsp; fprintf (stderr, "\t\t%d:", *sp); - for (rhsp = &ritem[rules[*sp].rhs]; *rhsp >= 0; ++rhsp) + for (rhsp = rules[*sp].rhs; *rhsp >= 0; ++rhsp) fprintf (stderr, " %s", symbols[*rhsp]->tag); fprintf (stderr, " (rule %d)\n", -*rhsp - 1); } diff --git a/src/gram.h b/src/gram.h index 75f4653e..61631640 100644 --- a/src/gram.h +++ b/src/gram.h @@ -1,5 +1,6 @@ /* Data definitions for internal representation of bison's input, - Copyright 1984, 1986, 1989, 1992, 2001 Free Software Foundation, Inc. + Copyright 1984, 1986, 1989, 1992, 2001, 2002 + Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -124,7 +125,7 @@ typedef enum typedef struct rule_s { short lhs; - short rhs; + short *rhs; short prec; short precsym; associativity assoc; diff --git a/src/lalr.c b/src/lalr.c index bd739dbf..192e46e2 100644 --- a/src/lalr.c +++ b/src/lalr.c @@ -417,7 +417,7 @@ build_relations (void) state_t *state = states[from_state[i]]; states1[0] = state->number; - for (rp = &ritem[rules[*rulep].rhs]; *rp >= 0; rp++) + for (rp = rules[*rulep].rhs; *rp >= 0; rp++) { shifts *sp = state->shifts; int j; diff --git a/src/nullable.c b/src/nullable.c index f8c9b32e..abeefdde 100644 --- a/src/nullable.c +++ b/src/nullable.c @@ -71,19 +71,19 @@ set_nullable (void) for (ruleno = 1; ruleno < nrules + 1; ++ruleno) if (rules[ruleno].useful) { - if (ritem[rules[ruleno].rhs] >= 0) + if (rules[ruleno].rhs[0] >= 0) { /* This rule has a non empty RHS. */ short *r; int any_tokens = 0; - for (r = &ritem[rules[ruleno].rhs]; *r >= 0; ++r) + for (r = rules[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[rules[ruleno].rhs]; *r >= 0; ++r) + for (r = rules[ruleno].rhs; *r >= 0; ++r) { rcount[ruleno]++; p->next = rsets[*r]; @@ -95,7 +95,7 @@ set_nullable (void) else { /* This rule has an empty RHS. */ - assert (ritem[rules[ruleno].rhs] == -ruleno); + assert (rules[ruleno].rhs[0] == -ruleno); if (rules[ruleno].useful && !nullable[rules[ruleno].lhs]) { nullable[rules[ruleno].lhs] = 1; diff --git a/src/output.c b/src/output.c index 573eb0ca..2194dda7 100644 --- a/src/output.c +++ b/src/output.c @@ -193,7 +193,7 @@ output_gram (void) int i; short *values = XCALLOC (short, nrules + 1); for (i = 0; i < nrules + 1; ++i) - values[i] = rules[i].rhs; + values[i] = rules[i].rhs - ritem; output_table_data (&format_obstack, values, 0, 1, nrules + 1); XFREE (values); @@ -311,7 +311,7 @@ output_rule_data (void) short_tab = XMALLOC (short, nrules + 1); for (i = 1; i < nrules; i++) short_tab[i] = rules[i + 1].rhs - rules[i].rhs - 1; - short_tab[nrules] = nritems - rules[nrules].rhs - 1; + short_tab[nrules] = nritems - (rules[nrules].rhs - ritem) - 1; output_table_data (&format_obstack, short_tab, 0, 1, nrules + 1); muscle_insert ("r2", obstack_finish (&format_obstack)); diff --git a/src/print.c b/src/print.c index 7ea46bec..e4b0104a 100644 --- a/src/print.c +++ b/src/print.c @@ -96,7 +96,7 @@ print_core (FILE *out, state_t *state) rule = -(*sp); fprintf (out, " %s -> ", escape (symbols[rules[rule].lhs]->tag)); - for (sp = ritem + rules[rule].rhs; sp < sp1; sp++) + for (sp = rules[rule].rhs; sp < sp1; sp++) fprintf (out, "%s ", escape (symbols[*sp]->tag)); fputc ('.', out); @@ -371,7 +371,7 @@ print_grammar (FILE *out) { fprintf (out, _(" %3d %3d %s ->"), i - 1, rules[i].line, escape (symbols[rules[i].lhs]->tag)); - rule = &ritem[rules[i].rhs]; + rule = rules[i].rhs; if (*rule >= 0) while (*rule >= 0) fprintf (out, " %s", escape (symbols[*rule++]->tag)); @@ -394,7 +394,7 @@ print_grammar (FILE *out) sprintf (buffer, " (%d)", i); for (j = 1; j <= nrules; j++) - for (rule = &ritem[rules[j].rhs]; *rule >= 0; rule++) + for (rule = rules[j].rhs; *rule >= 0; rule++) if (*rule == token_translations[i]) { END_TEST (65); @@ -415,7 +415,7 @@ print_grammar (FILE *out) { if (rules[j].lhs == i) left_count++; - for (rule = &ritem[rules[j].rhs]; *rule >= 0; rule++) + for (rule = rules[j].rhs; *rule >= 0; rule++) if (*rule == i) { right_count++; @@ -450,7 +450,7 @@ print_grammar (FILE *out) sprintf (buffer + strlen (buffer), _(" on right:")); for (j = 1; j <= nrules; j++) { - for (rule = &ritem[rules[j].rhs]; *rule >= 0; rule++) + for (rule = rules[j].rhs; *rule >= 0; rule++) if (*rule == i) { END_TEST (65); diff --git a/src/print_graph.c b/src/print_graph.c index 116a98c2..252a2f60 100644 --- a/src/print_graph.c +++ b/src/print_graph.c @@ -80,7 +80,7 @@ print_core (state_t *state, struct obstack *node_obstack) obstack_fgrow1 (node_obstack, " %s -> ", escape (symbols[rules[rule].lhs]->tag)); - for (sp = ritem + rules[rule].rhs; sp < sp1; sp++) + for (sp = rules[rule].rhs; sp < sp1; sp++) obstack_fgrow1 (node_obstack, "%s ", escape (symbols[*sp]->tag)); obstack_1grow (node_obstack, '.'); diff --git a/src/reader.c b/src/reader.c index 5af4df15..a1b24652 100644 --- a/src/reader.c +++ b/src/reader.c @@ -1688,7 +1688,7 @@ packgram (void) { bucket *ruleprec = p->ruleprec; rules[ruleno].lhs = p->sym->value; - rules[ruleno].rhs = itemno; + rules[ruleno].rhs = ritem + itemno; rules[ruleno].line = p->line; rules[ruleno].useful = TRUE; rules[ruleno].action = p->action; diff --git a/src/reduce.c b/src/reduce.c index bef2ae90..109f69a5 100644 --- a/src/reduce.c +++ b/src/reduce.c @@ -72,7 +72,7 @@ useful_production (int i, bitset N0) /* A production is useful if all of the nonterminals in its appear in the set of useful nonterminals. */ - for (r = &ritem[rules[i].rhs]; *r >= 0; r++) + for (r = rules[i].rhs; *r >= 0; r++) if (ISVAR (n = *r) && !bitset_test (N0, n - ntokens)) return FALSE; return TRUE; @@ -180,7 +180,7 @@ inaccessable_symbols (void) && bitset_test (P, i) && bitset_test (V, rules[i].lhs)) { - for (r = &ritem[rules[i].rhs]; *r >= 0; r++) + for (r = rules[i].rhs; *r >= 0; r++) if (ISTOKEN (t = *r) || bitset_test (N, t - ntokens)) bitset_set (Vp, t); bitset_set (Pp, i); @@ -252,10 +252,10 @@ reduce_grammar_tables (void) rules[np].prec = rules[pn].prec; rules[np].assoc = rules[pn].assoc; rules[np].rhs = rules[pn].rhs; - if (rules[np].rhs != ni) + if (rules[np].rhs - ritem != ni) { - pi = rules[np].rhs; - rules[np].rhs = ni; + pi = rules[np].rhs - ritem; + rules[np].rhs = ritem + ni; while (ritem[pi] >= 0) ritem[ni++] = ritem[pi++]; ritem[ni++] = -np; @@ -384,7 +384,7 @@ reduce_output (FILE *out) rule r; fprintf (out, "#%-4d ", i - 1); fprintf (out, "%s:", symbols[rules[i].lhs]->tag); - for (r = &ritem[rules[i].rhs]; *r >= 0; r++) + for (r = rules[i].rhs; *r >= 0; r++) fprintf (out, " %s", symbols[*r]->tag); fputs (";\n", out); } @@ -415,15 +415,15 @@ dump_grammar (FILE *out) { int rhs_count = 0; /* Find the last RHS index in ritems. */ - for (r = &ritem[rules[i].rhs]; *r >= 0; ++r) + for (r = rules[i].rhs; *r >= 0; ++r) ++rhs_count; fprintf (out, "%3d (%2d, %2d, %2d, %2d-%2d) %2d ->", i - 1, rules[i].prec, rules[i].assoc, rules[i].useful, - rules[i].rhs, rules[i].rhs + rhs_count - 1, + rules[i].rhs - ritem, rules[i].rhs - ritem + rhs_count - 1, rules[i].lhs); /* Dumped the RHS. */ - for (r = &ritem[rules[i].rhs]; *r >= 0; r++) + for (r = rules[i].rhs; *r >= 0; r++) fprintf (out, "%3d", *r); fprintf (out, " [%d]\n", -(*r) - 1); } @@ -432,7 +432,7 @@ dump_grammar (FILE *out) for (i = 1; i <= nrules; i++) { fprintf (out, "%-5d %s :", i, symbols[rules[i].lhs]->tag); - for (r = &ritem[rules[i].rhs]; *r >= 0; r++) + for (r = rules[i].rhs; *r >= 0; r++) fprintf (out, " %s", symbols[*r]->tag); fputc ('\n', out); } @@ -490,7 +490,6 @@ reduce_grammar (void) inaccessable_symbols (); reduced = (bool) (nuseless_nonterminals + nuseless_productions > 0); - if (!reduced) return;