* src/gram.h (rprec, rprecsym, rassoc): Remove, now part of...

(rule_t): this.
* src/conflicts.c, src/reader.c, src/reduce.c: Adjust.
This commit is contained in:
Akim Demaille
2001-11-19 09:12:49 +00:00
parent ff1581dddb
commit 9291f914de
5 changed files with 43 additions and 32 deletions

View File

@@ -1,3 +1,9 @@
2001-11-19 Akim Demaille <akim@epita.fr>
* src/gram.h (rprec, rprecsym, rassoc): Remove, now part of...
(rule_t): this.
* src/conflicts.c, src/reader.c, src/reduce.c: Adjust.
2001-11-19 Akim Demaille <akim@epita.fr>
* src/gram.h (rule_t): New.

View File

@@ -94,7 +94,7 @@ resolve_sr_conflict (int state, int lookaheadnum)
short *errtokens = errp->errs;
/* find the rule to reduce by to get precedence of reduction */
redprec = rprec[LAruleno[lookaheadnum]];
redprec = rule_table[LAruleno[lookaheadnum]].prec;
mask = 1;
fp1 = LA (lookaheadnum);
@@ -217,7 +217,7 @@ set_conflicts (int state)
check for shift-reduce conflict, and try to resolve using
precedence */
for (i = state_table[state].lookaheads; i < k; i++)
if (rprec[LAruleno[i]])
if (rule_table[LAruleno[i]].prec)
{
fp1 = LA (i);
fp2 = fp1;

View File

@@ -50,6 +50,13 @@
RULE_TABLE[R].rhs -- the index in RITEM of the beginning of the
portion for rule R.
RULE_TABLE[R].prec -- the precedence level of R.
RULE_TABLE[R].precsym -- the symbol-number of the symbol in %prec
for R (if any).
RULE_TABLE[R].assoc -- the associativity of the rule.
The right hand side is stored as symbol numbers in a portion of
RITEM.
@@ -67,10 +74,7 @@
Item numbers are used in the finite state machine to represent
places that parsing can get to.
Precedence levels are recorded in the vectors sprec and rprec.
sprec records the precedence level of each symbol, rprec the
precedence level of each rule. rprecsym is the symbol-number of
the symbol in %prec for this rule (if any).
SPREC records the precedence level of each symbol.
Precedence levels are assigned in increasing order starting with 1
so that numerically higher precedence values mean tighter binding
@@ -91,23 +95,12 @@ extern int nvars;
extern short *ritem;
extern short *rprec;
extern short *rprecsym;
extern short *sprec;
extern short *rassoc;
extern short *sassoc;
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
{
@@ -117,6 +110,17 @@ typedef enum
} associativity;
typedef struct rule_s
{
short lhs;
short rhs;
short prec;
short precsym;
short assoc;
} rule_t;
extern struct rule_s *rule_table;
/* token translation table: indexed by a token number as returned by
the user's yylex routine, it yields the internal token number used
by the parser and throughout bison. */

View File

@@ -1875,9 +1875,6 @@ packgram (void)
ritem = XCALLOC (short, nitems + 1);
rule_table = XCALLOC (rule_t, nrules) - 1;
rprec = XCALLOC (short, nrules) - 1;
rprecsym = XCALLOC (short, nrules) - 1;
rassoc = XCALLOC (short, nrules) - 1;
itemno = 0;
ruleno = 1;
@@ -1897,8 +1894,8 @@ packgram (void)
of the last token in it. */
if (p->sym->class == token_sym)
{
rprec[ruleno] = p->sym->prec;
rassoc[ruleno] = p->sym->assoc;
rule_table[ruleno].prec = p->sym->prec;
rule_table[ruleno].assoc = p->sym->assoc;
}
if (p)
p = p->next;
@@ -1908,9 +1905,9 @@ packgram (void)
the specified symbol's precedence replaces the default. */
if (ruleprec)
{
rprec[ruleno] = ruleprec->prec;
rassoc[ruleno] = ruleprec->assoc;
rprecsym[ruleno] = ruleprec->value;
rule_table[ruleno].prec = ruleprec->prec;
rule_table[ruleno].assoc = ruleprec->assoc;
rule_table[ruleno].precsym = ruleprec->value;
}
ritem[itemno++] = -ruleno;

View File

@@ -255,8 +255,8 @@ end_iteration:
/* A token that was used in %prec should not be warned about. */
for (i = 1; i < nrules; i++)
if (rprecsym[i] != 0)
SETBIT (V1, rprecsym[i]);
if (rule_table[i].precsym != 0)
SETBIT (V1, rule_table[i].precsym);
}
static void
@@ -281,8 +281,8 @@ reduce_grammar_tables (void)
{
rule_table[np].lhs = rule_table[pn].lhs;
rline[np] = rline[pn];
rprec[np] = rprec[pn];
rassoc[np] = rassoc[pn];
rule_table[np].prec = rule_table[pn].prec;
rule_table[np].assoc = rule_table[pn].assoc;
rule_table[np].rhs = rule_table[pn].rhs;
if (rule_table[np].rhs != ni)
{
@@ -370,9 +370,9 @@ reduce_grammar_tables (void)
/* Ignore the rules disabled above. */
if (rule_table[i].lhs >= 0)
rule_table[i].lhs = nontermmap[rule_table[i].lhs];
if (ISVAR (rprecsym[i]))
if (ISVAR (rule_table[i].precsym))
/* Can this happen? */
rprecsym[i] = nontermmap[rprecsym[i]];
rule_table[i].precsym = nontermmap[rule_table[i].precsym];
}
for (r = ritem; *r; r++)
@@ -464,7 +464,11 @@ dump_grammar (FILE *out)
for (i = 1; i <= nrules; i++)
{
fprintf (out, "%-5d(%5d%5d)%5d : (@%-5d)",
i, rprec[i], rassoc[i], rule_table[i].lhs, rule_table[i].rhs);
i,
rule_table[i].prec,
rule_table[i].assoc,
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));