From: Akim Demaille Date: Sun, 7 Apr 2002 17:42:31 +0000 (+0000) Subject: * src/gram.h (rule_s): prec and precsym are now pointers X-Git-Tag: BISON-1_49a~66 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/03b31c0ce805a157e787a50f1ea6f22bea84fe54 * 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. --- diff --git a/ChangeLog b/ChangeLog index fea35639..3dbfb57e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2002-04-07 Akim Demaille + + * 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 * src/lalr.c, src/LR0.c, src/closure.c, src/gram.c, src/reduce.c: diff --git a/src/conflicts.c b/src/conflicts.c index df7b457c..22e7d8a3 100644 --- a/src/conflicts.c +++ b/src/conflicts.c @@ -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); diff --git a/src/gram.h b/src/gram.h index 024501e3..c6988460 100644 --- a/src/gram.h +++ b/src/gram.h @@ -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; diff --git a/src/reader.c b/src/reader.c index b09d9f6c..01b5940c 100644 --- a/src/reader.c +++ b/src/reader.c @@ -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++; diff --git a/src/reduce.c b/src/reduce.c index 439e5207..23ad38bc 100644 --- a/src/reduce.c +++ b/src/reduce.c @@ -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++) diff --git a/src/symtab.h b/src/symtab.h index 82892ade..5b03e567 100644 --- a/src/symtab.h +++ b/src/symtab.h @@ -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.