* src/gram.h (rule_s): prec and precsym are now pointers

to the bucket giving the priority/associativity.
Member `associativity' removed: useless.
* src/reduce.c, src/conflicts.c: Adjust.
This commit is contained in:
Akim Demaille
2002-04-07 17:42:31 +00:00
parent 8b3df748a3
commit 03b31c0ce8
6 changed files with 37 additions and 33 deletions

View File

@@ -1,3 +1,10 @@
2002-04-07 Akim Demaille <akim@epita.fr>
* src/gram.h (rule_s): prec and precsym are now pointers
to the bucket giving the priority/associativity.
Member `associativity' removed: useless.
* src/reduce.c, src/conflicts.c: Adjust.
2002-04-07 Akim Demaille <akim@epita.fr>
* src/lalr.c, src/LR0.c, src/closure.c, src/gram.c, src/reduce.c:

View File

@@ -1,5 +1,6 @@
/* Find and resolve or report look-ahead conflicts for bison,
Copyright 1984, 1989, 1992, 2000, 2001, 2002 Free Software Foundation, Inc.
Copyright (C) 1984, 1989, 1992, 2000, 2001, 2002
Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
@@ -97,7 +98,7 @@ resolve_sr_conflict (state_t *state, int lookahead)
{
int i;
/* find the rule to reduce by to get precedence of reduction */
int redprec = LArule[lookahead]->prec;
int redprec = LArule[lookahead]->prec->prec;
errs *errp = errs_new (ntokens + 1);
errp->nerrs = 0;
@@ -175,6 +176,7 @@ set_conflicts (state_t *state)
precedence */
for (i = 0; i < state->nlookaheads; ++i)
if (LArule[state->lookaheadsp + i]->prec
&& LArule[state->lookaheadsp + i]->prec->prec
&& !bitset_disjoint_p (LA[state->lookaheadsp + i], lookaheadset))
{
resolve_sr_conflict (state, state->lookaheadsp + i);

View File

@@ -54,23 +54,24 @@
RULES is an array of struct rule_s, which members are:
RULES[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.
RULES[R].lhs -- the symbol of the left hand side of rule R.
RULES[R].rhs -- the index in RITEM of the beginning of the portion
for rule R.
RULES[R].prec -- the precedence level of R.
RULES[R].prec -- the symbol providing the precedence level of R.
RULES[R].precsym -- the symbol-number of the symbol in %prec for R
(if any).
RULES[R].precsym -- the symbol attached (via %prec) to give its
precedence to R. Of course, if set, it is equal to `prec', but we
need to distinguish one from the other when reducing: a symbol used
in a %prec is not useless.
RULES[R].assoc -- the associativity of R.
RULES[R].line -- the line where R was defined.
RULES[R].useful -- TRUE iff the rule is used.
RULES[R].useful -- TRUE iff the rule is used (i.e., FALSE if thrown
away by reduce).
The right hand side is stored as symbol numbers in a portion of
RITEM.
@@ -126,9 +127,13 @@ typedef struct rule_s
bucket *lhs;
short *rhs;
short prec;
short precsym;
associativity assoc;
/* This symbol provides both the associativity, and the precedence. */
bucket *prec;
/* This symbol was attached to the rule via %prec. */
bucket *precsym;
short line;
bool useful;

View File

@@ -1705,10 +1705,7 @@ packgram (void)
/* A rule gets by default the precedence and associativity
of the last token in it. */
if (p->sym->class == token_sym)
{
rules[ruleno].prec = p->sym->prec;
rules[ruleno].assoc = p->sym->assoc;
}
rules[ruleno].prec = p->sym;
if (p)
p = p->next;
}
@@ -1717,11 +1714,9 @@ packgram (void)
the specified symbol's precedence replaces the default. */
if (ruleprec)
{
rules[ruleno].prec = ruleprec->prec;
rules[ruleno].assoc = ruleprec->assoc;
rules[ruleno].precsym = ruleprec->number;
rules[ruleno].precsym = ruleprec;
rules[ruleno].prec = ruleprec;
}
ritem[itemno++] = -ruleno;
ruleno++;

View File

@@ -218,7 +218,7 @@ inaccessable_symbols (void)
/* A token that was used in %prec should not be warned about. */
for (i = 1; i < nrules + 1; i++)
if (rules[i].precsym != 0)
bitset_set (V1, rules[i].precsym);
bitset_set (V1, rules[i].precsym->number);
}
@@ -310,15 +310,6 @@ nonterminals_reduce (void)
free (symbols_sorted + ntokens);
}
/* Replace all symbol numbers in valid data structures. */
for (i = 1; i < nrules + 1; i++)
{
if (ISVAR (rules[i].precsym))
/* Can this happen? */
rules[i].precsym = nontermmap[rules[i].precsym];
}
for (i = 0; i < nritems; ++i)
if (ISVAR (ritem[i]))
ritem[i] = nontermmap[ritem[i]];
@@ -412,8 +403,11 @@ dump_grammar (FILE *out)
++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 - ritem, rules[i].rhs - ritem + rhs_count - 1,
rules[i].prec->prec,
rules[i].prec->assoc,
rules[i].useful,
rules[i].rhs - ritem,
rules[i].rhs - ritem + rhs_count - 1,
rules[i].lhs->number);
/* Dumped the RHS. */
for (r = rules[i].rhs; *r >= 0; r++)

View File

@@ -1,5 +1,6 @@
/* Definitions for symtab.c and callers, part of bison,
Copyright 1984, 1989, 1992, 2000, 2001, 2002 Free Software Foundation, Inc.
Copyright (C) 1984, 1989, 1992, 2000, 2001, 2002
Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.