mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
* 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.
This commit is contained in:
10
ChangeLog
10
ChangeLog
@@ -1,3 +1,13 @@
|
||||
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...
|
||||
|
||||
@@ -130,7 +130,7 @@ set_firsts (void)
|
||||
sp = derives[i];
|
||||
while (*sp >= 0)
|
||||
{
|
||||
symbol = ritem[rrhs[*sp++]];
|
||||
symbol = ritem[rule_table[*sp++].rhs];
|
||||
if (ISVAR (symbol))
|
||||
{
|
||||
symbol -= ntokens;
|
||||
@@ -287,7 +287,7 @@ closure (short *core, int n)
|
||||
{
|
||||
if (word & (1 << b))
|
||||
{
|
||||
itemno = rrhs[ruleno];
|
||||
itemno = rule_table[ruleno].rhs;
|
||||
while (csp < csend && *csp < itemno)
|
||||
*itemsetend++ = *csp++;
|
||||
*itemsetend++ = itemno;
|
||||
|
||||
@@ -587,7 +587,8 @@ print_reductions (FILE *out, int state)
|
||||
{
|
||||
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)
|
||||
@@ -598,7 +599,7 @@ print_reductions (FILE *out, int state)
|
||||
}
|
||||
|
||||
fprintf (out, _(" $default\treduce using rule %d (%s)\n\n"),
|
||||
default_rule, tags[rlhs[default_rule]]);
|
||||
default_rule, tags[rule_table[default_rule].lhs]);
|
||||
}
|
||||
else if (n - m >= 1)
|
||||
{
|
||||
@@ -687,7 +688,7 @@ print_reductions (FILE *out, int state)
|
||||
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]);
|
||||
}
|
||||
else
|
||||
defaulted = 1;
|
||||
@@ -701,13 +702,13 @@ print_reductions (FILE *out, int state)
|
||||
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"),
|
||||
tags[i], rule, tags[rlhs[rule]]);
|
||||
tags[i], rule, tags[rule_table[rule].lhs]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -727,7 +728,7 @@ print_reductions (FILE *out, int state)
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ set_derives (void)
|
||||
p = delts;
|
||||
for (i = nrules; i > 0; i--)
|
||||
{
|
||||
lhs = rlhs[i];
|
||||
lhs = rule_table[i].lhs;
|
||||
if (lhs >= 0)
|
||||
{
|
||||
p->next = dset[lhs];
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* 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.
|
||||
|
||||
@@ -20,6 +20,7 @@ Boston, MA 02111-1307, USA. */
|
||||
|
||||
|
||||
#include "system.h"
|
||||
#include "gram.h"
|
||||
|
||||
void dummy PARAMS((void));
|
||||
|
||||
@@ -32,8 +33,7 @@ int ntokens;
|
||||
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;
|
||||
|
||||
32
src/gram.h
32
src/gram.h
@@ -1,5 +1,5 @@
|
||||
/* 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.
|
||||
|
||||
@@ -38,21 +38,27 @@
|
||||
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
|
||||
portion for rule R.
|
||||
|
||||
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 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
|
||||
@@ -84,8 +90,7 @@ extern int ntokens;
|
||||
extern int nvars;
|
||||
|
||||
extern short *ritem;
|
||||
extern short *rlhs;
|
||||
extern short *rrhs;
|
||||
|
||||
extern short *rprec;
|
||||
extern short *rprecsym;
|
||||
extern short *sprec;
|
||||
@@ -95,6 +100,13 @@ extern short *rline; /* Source line number of each rule */
|
||||
|
||||
extern int start_symbol;
|
||||
|
||||
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
|
||||
|
||||
@@ -561,7 +561,7 @@ build_relations (void)
|
||||
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;
|
||||
|
||||
@@ -69,7 +69,7 @@ set_nullable (void)
|
||||
{
|
||||
if (*r < 0)
|
||||
{
|
||||
symbol = rlhs[-(*r++)];
|
||||
symbol = rule_table[-(*r++)].lhs;
|
||||
if (symbol >= 0 && !nullable[symbol])
|
||||
{
|
||||
nullable[symbol] = 1;
|
||||
@@ -111,7 +111,7 @@ set_nullable (void)
|
||||
p = p->next;
|
||||
if (--rcount[ruleno] == 0)
|
||||
{
|
||||
symbol = rlhs[ruleno];
|
||||
symbol = rule_table[ruleno].lhs;
|
||||
if (symbol >= 0 && !nullable[symbol])
|
||||
{
|
||||
nullable[symbol] = 1;
|
||||
|
||||
25
src/output.c
25
src/output.c
@@ -167,8 +167,16 @@ output_token_translations (void)
|
||||
static void
|
||||
output_gram (void)
|
||||
{
|
||||
output_table_data (&output_obstack, rrhs,
|
||||
{
|
||||
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));
|
||||
|
||||
{
|
||||
@@ -279,22 +287,27 @@ output_rule_data (void)
|
||||
muscle_insert ("toknum", obstack_finish (&output_obstack));
|
||||
|
||||
/* Output YYR1. */
|
||||
output_table_data (&output_obstack, rlhs,
|
||||
{
|
||||
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 (rlhs + 1);
|
||||
XFREE (values);
|
||||
}
|
||||
|
||||
/* 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);
|
||||
|
||||
XFREE (rrhs + 1);
|
||||
XFREE (rule_table + 1);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------.
|
||||
|
||||
22
src/print.c
22
src/print.c
@@ -68,9 +68,9 @@ print_core (FILE *out, int state)
|
||||
sp++;
|
||||
|
||||
rule = -(*sp);
|
||||
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]);
|
||||
}
|
||||
@@ -168,7 +168,7 @@ print_actions (FILE *out, int state)
|
||||
if (state_table[state].consistent && redp)
|
||||
{
|
||||
rule = redp->rules[0];
|
||||
symbol = rlhs[rule];
|
||||
symbol = rule_table[rule].lhs;
|
||||
fprintf (out, _(" $default\treduce using rule %d (%s)\n\n"),
|
||||
rule, tags[symbol]);
|
||||
}
|
||||
@@ -230,10 +230,10 @@ print_grammar (FILE *out)
|
||||
fprintf (out, "\n%s\n\n", _("Grammar"));
|
||||
for (i = 1; i <= nrules; i++)
|
||||
/* Don't print rules disabled in reduce_grammar_tables. */
|
||||
if (rlhs[i] >= 0)
|
||||
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++]);
|
||||
@@ -256,7 +256,7 @@ print_grammar (FILE *out)
|
||||
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);
|
||||
@@ -274,9 +274,9 @@ print_grammar (FILE *out)
|
||||
|
||||
for (j = 1; j <= nrules; j++)
|
||||
{
|
||||
if (rlhs[j] == i)
|
||||
if (rule_table[j].lhs == i)
|
||||
left_count++;
|
||||
for (rule = &ritem[rrhs[j]]; *rule > 0; rule++)
|
||||
for (rule = &ritem[rule_table[j].rhs]; *rule > 0; rule++)
|
||||
if (*rule == i)
|
||||
{
|
||||
right_count++;
|
||||
@@ -298,7 +298,7 @@ print_grammar (FILE *out)
|
||||
for (j = 1; j <= nrules; j++)
|
||||
{
|
||||
END_TEST (65);
|
||||
if (rlhs[j] == i)
|
||||
if (rule_table[j].lhs == i)
|
||||
sprintf (buffer + strlen (buffer), " %d", j);
|
||||
}
|
||||
}
|
||||
@@ -311,7 +311,7 @@ print_grammar (FILE *out)
|
||||
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);
|
||||
|
||||
@@ -76,9 +76,10 @@ print_core (int state, struct obstack *node_obstack)
|
||||
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, '.');
|
||||
@@ -181,7 +182,7 @@ print_actions (int state, const char *node_name, struct obstack *node_obstack)
|
||||
if (state_table[state].consistent && redp)
|
||||
{
|
||||
rule = redp->rules[0];
|
||||
symbol = rlhs[rule];
|
||||
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)"),
|
||||
|
||||
@@ -1922,8 +1922,7 @@ packgram (void)
|
||||
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;
|
||||
@@ -1934,8 +1933,8 @@ packgram (void)
|
||||
p = grammar;
|
||||
while (p)
|
||||
{
|
||||
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;
|
||||
|
||||
36
src/reduce.c
36
src/reduce.c
@@ -100,7 +100,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[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;
|
||||
@@ -149,7 +149,7 @@ useless_nonterminals (void)
|
||||
{
|
||||
if (useful_production (i, N))
|
||||
{
|
||||
SETBIT (Np, rlhs[i] - ntokens);
|
||||
SETBIT (Np, rule_table[i].lhs - ntokens);
|
||||
SETBIT (P, i);
|
||||
}
|
||||
}
|
||||
@@ -211,9 +211,9 @@ inaccessable_symbols (void)
|
||||
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))
|
||||
{
|
||||
@@ -279,15 +279,15 @@ reduce_grammar_tables (void)
|
||||
np++;
|
||||
if (pn != np)
|
||||
{
|
||||
rlhs[np] = rlhs[pn];
|
||||
rule_table[np].lhs = rule_table[pn].lhs;
|
||||
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;
|
||||
@@ -319,7 +319,7 @@ reduce_grammar_tables (void)
|
||||
{
|
||||
if (!BITISSET (P, pn))
|
||||
{
|
||||
rlhs[pn] = -1;
|
||||
rule_table[pn].lhs = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -368,8 +368,8 @@ reduce_grammar_tables (void)
|
||||
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]];
|
||||
@@ -434,8 +434,8 @@ reduce_output (FILE *out)
|
||||
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");
|
||||
}
|
||||
@@ -464,8 +464,8 @@ dump_grammar (FILE *out)
|
||||
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));
|
||||
}
|
||||
@@ -473,8 +473,8 @@ dump_grammar (FILE *out)
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user