+2002-04-07 Akim Demaille <akim@epita.fr>
+
+ * 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 <eggert@twinsun.com>
* doc/bison.texinfo: Update copyright date.
{
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);
}
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);
}
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];
{
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);
}
/* 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.
typedef struct rule_s
{
short lhs;
- short rhs;
+ short *rhs;
short prec;
short precsym;
associativity assoc;
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;
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];
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;
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);
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));
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);
{
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));
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);
{
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++;
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);
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, '.');
{
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;
/* 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;
&& 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);
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;
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);
}
{
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);
}
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);
}
inaccessable_symbols ();
reduced = (bool) (nuseless_nonterminals + nuseless_productions > 0);
-
if (!reduced)
return;