(rule_table): New.
(rrhs, rlhs): Remove, part of state_t.
* src/print_graph.c, src/closure.c, src/conflicts.c, src/derives.c,
* src/lalr.c, src/nullable.c, src/output.c, src/print.c,
* src/reader.c, src/reduce.c: Adjust.
13 files changed:
+2001-11-19 Akim Demaille <akim@epita.fr>
+
+ * src/gram.h (rule_t): New.
+ (rule_table): New.
+ (rrhs, rlhs): Remove, part of state_t.
+ * src/print_graph.c, src/closure.c, src/conflicts.c, src/derives.c,
+ * src/lalr.c, src/nullable.c, src/output.c, src/print.c,
+ * src/reader.c, src/reduce.c: Adjust.
+
+
2001-11-19 Akim Demaille <akim@epita.fr>
* src/reader.c (symbols_output): New, extracted from...
2001-11-19 Akim Demaille <akim@epita.fr>
* src/reader.c (symbols_output): New, extracted from...
sp = derives[i];
while (*sp >= 0)
{
sp = derives[i];
while (*sp >= 0)
{
- symbol = ritem[rrhs[*sp++]];
+ symbol = ritem[rule_table[*sp++].rhs];
if (ISVAR (symbol))
{
symbol -= ntokens;
if (ISVAR (symbol))
{
symbol -= ntokens;
+ itemno = rule_table[ruleno].rhs;
while (csp < csend && *csp < itemno)
*itemsetend++ = *csp++;
*itemsetend++ = itemno;
while (csp < csend && *csp < itemno)
*itemsetend++ = *csp++;
*itemsetend++ = itemno;
{
if (mask & *fp3)
fprintf (out, _(" %-4s\t[reduce using rule %d (%s)]\n"),
{
if (mask & *fp3)
fprintf (out, _(" %-4s\t[reduce using rule %d (%s)]\n"),
- tags[i], default_rule, tags[rlhs[default_rule]]);
+ tags[i], default_rule,
+ tags[rule_table[default_rule].lhs]);
mask <<= 1;
if (mask == 0)
mask <<= 1;
if (mask == 0)
}
fprintf (out, _(" $default\treduce using rule %d (%s)\n\n"),
}
fprintf (out, _(" $default\treduce using rule %d (%s)\n\n"),
- default_rule, tags[rlhs[default_rule]]);
+ default_rule, tags[rule_table[default_rule].lhs]);
rule = LAruleno[j];
fprintf (out,
_(" %-4s\treduce using rule %d (%s)\n"),
rule = LAruleno[j];
fprintf (out,
_(" %-4s\treduce using rule %d (%s)\n"),
- tags[i], rule, tags[rlhs[rule]]);
+ tags[i], rule, tags[rule_table[rule].lhs]);
rule = LAruleno[default_LA];
fprintf (out,
_(" %-4s\treduce using rule %d (%s)\n"),
rule = LAruleno[default_LA];
fprintf (out,
_(" %-4s\treduce using rule %d (%s)\n"),
- tags[i], rule, tags[rlhs[rule]]);
+ tags[i], rule, tags[rule_table[rule].lhs]);
defaulted = 0;
}
rule = LAruleno[j];
fprintf (out,
_(" %-4s\t[reduce using rule %d (%s)]\n"),
defaulted = 0;
}
rule = LAruleno[j];
fprintf (out,
_(" %-4s\t[reduce using rule %d (%s)]\n"),
- tags[i], rule, tags[rlhs[rule]]);
+ tags[i], rule, tags[rule_table[rule].lhs]);
if (default_LA >= 0)
fprintf (out, _(" $default\treduce using rule %d (%s)\n"),
if (default_LA >= 0)
fprintf (out, _(" $default\treduce using rule %d (%s)\n"),
- default_rule, tags[rlhs[default_rule]]);
+ default_rule, tags[rule_table[default_rule].lhs]);
p = delts;
for (i = nrules; i > 0; i--)
{
p = delts;
for (i = nrules; i > 0; i--)
{
+ lhs = rule_table[i].lhs;
if (lhs >= 0)
{
p->next = dset[lhs];
if (lhs >= 0)
{
p->next = dset[lhs];
/* Allocate input grammar variables for bison,
/* Allocate input grammar variables for bison,
- Copyright 1984, 1986, 1989 Free Software Foundation, Inc.
+ Copyright 1984, 1986, 1989, 2001 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
This file is part of Bison, the GNU Compiler Compiler.
void dummy PARAMS((void));
void dummy PARAMS((void));
int nvars;
short *ritem = NULL;
int nvars;
short *ritem = NULL;
-short *rlhs = NULL;
-short *rrhs = NULL;
+rule_t *rule_table = NULL;
short *rprec = NULL;
short *rprecsym = NULL;
short *sprec = NULL;
short *rprec = NULL;
short *rprecsym = NULL;
short *sprec = NULL;
/* Data definitions for internal representation of bison's input,
/* Data definitions for internal representation of bison's input,
- Copyright 1984, 1986, 1989, 1992 Free Software Foundation, Inc.
+ Copyright 1984, 1986, 1989, 1992, 2001 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
This file is part of Bison, the GNU Compiler Compiler.
The rules receive rule numbers 1 to nrules in the order they are
written. Actions and guards are accessed via the rule number.
The rules receive rule numbers 1 to nrules in the order they are
written. Actions and guards are accessed via the rule number.
- The rules themselves are described by three arrays: rrhs, rlhs and
- ritem. rlhs[R] is the symbol number of the left hand side of rule
- R. The right hand side is stored as symbol numbers in a portion of
- ritem. rrhs[R] contains the index in ritem of the beginning of the
+ The rules themselves are described by several arrays: amongst which
+ RITEM, and RULE_TABLE.
+
+ RULE_TABLE is an array of struct rule_s, which members are:
+
+ RULE_TABLE[R].lhs -- the symbol number of the left hand side of
+ rule R. If -1, the rule has been thrown out by reduce.c and should
+ be ignored.
+
+ RULE_TABLE[R].rhs -- the index in RITEM of the beginning of the
- If rlhs[R] is -1, the rule has been thrown out by reduce.c and
- should be ignored.
+ The right hand side is stored as symbol numbers in a portion of
+ RITEM.
The length of the portion is one greater than the number of symbols
in the rule's right hand side. The last element in the portion
contains minus R, which identifies it as the end of a portion and
says which rule it is for.
The length of the portion is one greater than the number of symbols
in the rule's right hand side. The last element in the portion
contains minus R, which identifies it as the end of a portion and
says which rule it is for.
- The portions of ritem come in order of increasing rule number and
+ The portions of RITEM come in order of increasing rule number and
are followed by an element which is zero to mark the end. nitems
is the total length of ritem, not counting the final zero. Each
element of ritem is called an "item" and its index in ritem is an
are followed by an element which is zero to mark the end. nitems
is the total length of ritem, not counting the final zero. Each
element of ritem is called an "item" and its index in ritem is an
extern int nvars;
extern short *ritem;
extern int nvars;
extern short *ritem;
-extern short *rlhs;
-extern short *rrhs;
extern short *rprec;
extern short *rprecsym;
extern short *sprec;
extern short *rprec;
extern short *rprecsym;
extern short *sprec;
+typedef struct rule_s
+{
+ short lhs;
+ short rhs;
+} rule_t;
+
+extern struct rule_s *rule_table;
/* associativity values in elements of rassoc, sassoc. */
typedef enum
/* associativity values in elements of rassoc, sassoc. */
typedef enum
states[0] = state1;
stateno = state1;
states[0] = state1;
stateno = state1;
- for (rp = ritem + rrhs[*rulep]; *rp > 0; rp++)
+ for (rp = ritem + rule_table[*rulep].rhs; *rp > 0; rp++)
{
symbol2 = *rp;
sp = state_table[stateno].shift_table;
{
symbol2 = *rp;
sp = state_table[stateno].shift_table;
- symbol = rlhs[-(*r++)];
+ symbol = rule_table[-(*r++)].lhs;
if (symbol >= 0 && !nullable[symbol])
{
nullable[symbol] = 1;
if (symbol >= 0 && !nullable[symbol])
{
nullable[symbol] = 1;
p = p->next;
if (--rcount[ruleno] == 0)
{
p = p->next;
if (--rcount[ruleno] == 0)
{
+ symbol = rule_table[ruleno].lhs;
if (symbol >= 0 && !nullable[symbol])
{
nullable[symbol] = 1;
if (symbol >= 0 && !nullable[symbol])
{
nullable[symbol] = 1;
static void
output_gram (void)
{
static void
output_gram (void)
{
- output_table_data (&output_obstack, rrhs,
- 0, 1, nrules + 1);
+ {
+ int i;
+ short *values = XCALLOC (short, nrules + 1);
+ for (i = 0; i < nrules + 1; ++i)
+ values[i] = rule_table[i].rhs;
+ output_table_data (&output_obstack, values,
+ 0, 1, nrules + 1);
+ XFREE (values);
+ }
+
muscle_insert ("prhs", obstack_finish (&output_obstack));
{
muscle_insert ("prhs", obstack_finish (&output_obstack));
{
muscle_insert ("toknum", obstack_finish (&output_obstack));
/* Output YYR1. */
muscle_insert ("toknum", obstack_finish (&output_obstack));
/* Output YYR1. */
- output_table_data (&output_obstack, rlhs,
- 0, 1, nrules + 1);
- muscle_insert ("r1", obstack_finish (&output_obstack));
- XFREE (rlhs + 1);
+ {
+ short *values = XCALLOC (short, nrules + 1);
+ for (i = 0; i < nrules + 1; ++i)
+ values[i] = rule_table[i].lhs;
+ output_table_data (&output_obstack, values,
+ 0, 1, nrules + 1);
+ muscle_insert ("r1", obstack_finish (&output_obstack));
+ XFREE (values);
+ }
/* Output YYR2. */
short_tab = XMALLOC (short, nrules + 1);
for (i = 1; i < nrules; i++)
/* Output YYR2. */
short_tab = XMALLOC (short, nrules + 1);
for (i = 1; i < nrules; i++)
- short_tab[i] = rrhs[i + 1] - rrhs[i] - 1;
- short_tab[nrules] = nitems - rrhs[nrules] - 1;
+ short_tab[i] = rule_table[i + 1].rhs - rule_table[i].rhs - 1;
+ short_tab[nrules] = nitems - rule_table[nrules].rhs - 1;
output_table_data (&output_obstack, short_tab,
0, 1, nrules + 1);
muscle_insert ("r2", obstack_finish (&output_obstack));
XFREE (short_tab);
output_table_data (&output_obstack, short_tab,
0, 1, nrules + 1);
muscle_insert ("r2", obstack_finish (&output_obstack));
XFREE (short_tab);
+ XFREE (rule_table + 1);
}
/*------------------------------------------------------------------.
}
/*------------------------------------------------------------------.
- fprintf (out, " %s -> ", tags[rlhs[rule]]);
+ fprintf (out, " %s -> ", tags[rule_table[rule].lhs]);
- for (sp = ritem + rrhs[rule]; sp < sp1; sp++)
+ for (sp = ritem + rule_table[rule].rhs; sp < sp1; sp++)
{
fprintf (out, "%s ", tags[*sp]);
}
{
fprintf (out, "%s ", tags[*sp]);
}
if (state_table[state].consistent && redp)
{
rule = redp->rules[0];
if (state_table[state].consistent && redp)
{
rule = redp->rules[0];
+ symbol = rule_table[rule].lhs;
fprintf (out, _(" $default\treduce using rule %d (%s)\n\n"),
rule, tags[symbol]);
}
fprintf (out, _(" $default\treduce using rule %d (%s)\n\n"),
rule, tags[symbol]);
}
fprintf (out, "\n%s\n\n", _("Grammar"));
for (i = 1; i <= nrules; i++)
/* Don't print rules disabled in reduce_grammar_tables. */
fprintf (out, "\n%s\n\n", _("Grammar"));
for (i = 1; i <= nrules; i++)
/* Don't print rules disabled in reduce_grammar_tables. */
+ if (rule_table[i].lhs >= 0)
- fprintf (out, _("rule %-4d %s ->"), i, tags[rlhs[i]]);
- rule = &ritem[rrhs[i]];
+ fprintf (out, _("rule %-4d %s ->"), i, tags[rule_table[i].lhs]);
+ rule = &ritem[rule_table[i].rhs];
if (*rule > 0)
while (*rule > 0)
fprintf (out, " %s", tags[*rule++]);
if (*rule > 0)
while (*rule > 0)
fprintf (out, " %s", tags[*rule++]);
sprintf (buffer, " (%d)", i);
for (j = 1; j <= nrules; j++)
sprintf (buffer, " (%d)", i);
for (j = 1; j <= nrules; j++)
- for (rule = &ritem[rrhs[j]]; *rule > 0; rule++)
+ for (rule = &ritem[rule_table[j].rhs]; *rule > 0; rule++)
if (*rule == token_translations[i])
{
END_TEST (65);
if (*rule == token_translations[i])
{
END_TEST (65);
for (j = 1; j <= nrules; j++)
{
for (j = 1; j <= nrules; j++)
{
+ if (rule_table[j].lhs == i)
- for (rule = &ritem[rrhs[j]]; *rule > 0; rule++)
+ for (rule = &ritem[rule_table[j].rhs]; *rule > 0; rule++)
if (*rule == i)
{
right_count++;
if (*rule == i)
{
right_count++;
for (j = 1; j <= nrules; j++)
{
END_TEST (65);
for (j = 1; j <= nrules; j++)
{
END_TEST (65);
+ if (rule_table[j].lhs == i)
sprintf (buffer + strlen (buffer), " %d", j);
}
}
sprintf (buffer + strlen (buffer), " %d", j);
}
}
sprintf (buffer + strlen (buffer), _(" on right:"));
for (j = 1; j <= nrules; j++)
{
sprintf (buffer + strlen (buffer), _(" on right:"));
for (j = 1; j <= nrules; j++)
{
- for (rule = &ritem[rrhs[j]]; *rule > 0; rule++)
+ for (rule = &ritem[rule_table[j].rhs]; *rule > 0; rule++)
if (*rule == i)
{
END_TEST (65);
if (*rule == i)
{
END_TEST (65);
rule = -(*sp);
obstack_fgrow1 (node_obstack, "%d: ", rule);
rule = -(*sp);
obstack_fgrow1 (node_obstack, "%d: ", rule);
- obstack_fgrow1 (node_obstack, " %s -> ", quote (tags[rlhs[rule]]));
+ obstack_fgrow1 (node_obstack, " %s -> ",
+ quote (tags[rule_table[rule].lhs]));
- for (sp = ritem + rrhs[rule]; sp < sp1; sp++)
+ for (sp = ritem + rule_table[rule].rhs; sp < sp1; sp++)
obstack_fgrow1 (node_obstack, "%s ", quote (tags[*sp]));
obstack_1grow (node_obstack, '.');
obstack_fgrow1 (node_obstack, "%s ", quote (tags[*sp]));
obstack_1grow (node_obstack, '.');
if (state_table[state].consistent && redp)
{
rule = redp->rules[0];
if (state_table[state].consistent && redp)
{
rule = redp->rules[0];
+ symbol = rule_table[rule].lhs;
if (obstack_object_size (node_obstack) > node_output_size)
obstack_sgrow (node_obstack, "\\n");
obstack_fgrow2 (node_obstack, _("$default\treduce using rule %d (%s)"),
if (obstack_object_size (node_obstack) > node_output_size)
obstack_sgrow (node_obstack, "\\n");
obstack_fgrow2 (node_obstack, _("$default\treduce using rule %d (%s)"),
bucket *ruleprec;
ritem = XCALLOC (short, nitems + 1);
bucket *ruleprec;
ritem = XCALLOC (short, nitems + 1);
- rlhs = XCALLOC (short, nrules) - 1;
- rrhs = XCALLOC (short, nrules) - 1;
+ rule_table = XCALLOC (rule_t, nrules) - 1;
rprec = XCALLOC (short, nrules) - 1;
rprecsym = XCALLOC (short, nrules) - 1;
rassoc = XCALLOC (short, nrules) - 1;
rprec = XCALLOC (short, nrules) - 1;
rprecsym = XCALLOC (short, nrules) - 1;
rassoc = XCALLOC (short, nrules) - 1;
- rlhs[ruleno] = p->sym->value;
- rrhs[ruleno] = itemno;
+ rule_table[ruleno].lhs = p->sym->value;
+ rule_table[ruleno].rhs = itemno;
ruleprec = p->ruleprec;
p = p->next;
ruleprec = p->ruleprec;
p = p->next;
/* A production is useful if all of the nonterminals in its appear
in the set of useful nonterminals. */
/* A production is useful if all of the nonterminals in its appear
in the set of useful nonterminals. */
- for (r = &ritem[rrhs[i]]; *r > 0; r++)
+ for (r = &ritem[rule_table[i].rhs]; *r > 0; r++)
if (ISVAR (n = *r))
if (!BITISSET (N0, n - ntokens))
return FALSE;
if (ISVAR (n = *r))
if (!BITISSET (N0, n - ntokens))
return FALSE;
{
if (useful_production (i, N))
{
{
if (useful_production (i, N))
{
- SETBIT (Np, rlhs[i] - ntokens);
+ SETBIT (Np, rule_table[i].lhs - ntokens);
Vp[i] = V[i];
for (i = 1; i <= nrules; i++)
{
Vp[i] = V[i];
for (i = 1; i <= nrules; i++)
{
- if (!BITISSET (Pp, i) && BITISSET (P, i) && BITISSET (V, rlhs[i]))
+ if (!BITISSET (Pp, i) && BITISSET (P, i) && BITISSET (V, rule_table[i].lhs))
- for (r = &ritem[rrhs[i]]; *r >= 0; r++)
+ for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++)
{
if (ISTOKEN (t = *r) || BITISSET (N, t - ntokens))
{
{
if (ISTOKEN (t = *r) || BITISSET (N, t - ntokens))
{
+ rule_table[np].lhs = rule_table[pn].lhs;
rline[np] = rline[pn];
rprec[np] = rprec[pn];
rassoc[np] = rassoc[pn];
rline[np] = rline[pn];
rprec[np] = rprec[pn];
rassoc[np] = rassoc[pn];
- rrhs[np] = rrhs[pn];
- if (rrhs[np] != ni)
+ rule_table[np].rhs = rule_table[pn].rhs;
+ if (rule_table[np].rhs != ni)
- pi = rrhs[np];
- rrhs[np] = ni;
+ pi = rule_table[np].rhs;
+ rule_table[np].rhs = ni;
while (ritem[pi] >= 0)
ritem[ni++] = ritem[pi++];
ritem[ni++] = -np;
while (ritem[pi] >= 0)
ritem[ni++] = ritem[pi++];
ritem[ni++] = -np;
{
if (!BITISSET (P, pn))
{
{
if (!BITISSET (P, pn))
{
+ rule_table[pn].lhs = -1;
for (i = 1; i <= nrules; i++)
{
/* Ignore the rules disabled above. */
for (i = 1; i <= nrules; i++)
{
/* Ignore the rules disabled above. */
- if (rlhs[i] >= 0)
- rlhs[i] = nontermmap[rlhs[i]];
+ if (rule_table[i].lhs >= 0)
+ rule_table[i].lhs = nontermmap[rule_table[i].lhs];
if (ISVAR (rprecsym[i]))
/* Can this happen? */
rprecsym[i] = nontermmap[rprecsym[i]];
if (ISVAR (rprecsym[i]))
/* Can this happen? */
rprecsym[i] = nontermmap[rprecsym[i]];
if (!BITISSET (P, i))
{
fprintf (out, "#%-4d ", i);
if (!BITISSET (P, i))
{
fprintf (out, "#%-4d ", i);
- fprintf (out, "%s :\t", tags[rlhs[i]]);
- for (r = &ritem[rrhs[i]]; *r >= 0; r++)
+ fprintf (out, "%s :\t", tags[rule_table[i].lhs]);
+ for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++)
fprintf (out, " %s", tags[*r]);
fprintf (out, ";\n");
}
fprintf (out, " %s", tags[*r]);
fprintf (out, ";\n");
}
for (i = 1; i <= nrules; i++)
{
fprintf (out, "%-5d(%5d%5d)%5d : (@%-5d)",
for (i = 1; i <= nrules; i++)
{
fprintf (out, "%-5d(%5d%5d)%5d : (@%-5d)",
- i, rprec[i], rassoc[i], rlhs[i], rrhs[i]);
- for (r = &ritem[rrhs[i]]; *r > 0; r++)
+ i, rprec[i], rassoc[i], rule_table[i].lhs, rule_table[i].rhs);
+ for (r = &ritem[rule_table[i].rhs]; *r > 0; r++)
fprintf (out, "%5d", *r);
fprintf (out, " [%d]\n", -(*r));
}
fprintf (out, "%5d", *r);
fprintf (out, " [%d]\n", -(*r));
}
fprintf (out, _("Rules interpreted\n-----------------\n\n"));
for (i = 1; i <= nrules; i++)
{
fprintf (out, _("Rules interpreted\n-----------------\n\n"));
for (i = 1; i <= nrules; i++)
{
- fprintf (out, "%-5d %s :", i, tags[rlhs[i]]);
- for (r = &ritem[rrhs[i]]; *r > 0; r++)
+ fprintf (out, "%-5d %s :", i, tags[rule_table[i].lhs]);
+ for (r = &ritem[rule_table[i].rhs]; *r > 0; r++)
fprintf (out, " %s", tags[*r]);
fputc ('\n', out);
}
fprintf (out, " %s", tags[*r]);
fputc ('\n', out);
}