From 652a871c294ff727099daa57c494eaca9da6c1d3 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 19 Nov 2001 10:19:56 +0000 Subject: [PATCH] * src/gram.h (rprec, rprecsym, rassoc): Remove, now part of... (rule_t): this. * src/conflicts.c, src/reader.c, src/reduce.c: Adjust. --- ChangeLog | 6 ++++++ src/conflicts.c | 4 ++-- src/gram.h | 34 +++++++++++++++++++--------------- src/reader.c | 13 +++++-------- src/reduce.c | 18 +++++++++++------- 5 files changed, 43 insertions(+), 32 deletions(-) diff --git a/ChangeLog b/ChangeLog index 32cbf36d..c8fe7aed 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2001-11-19 Akim Demaille + + * 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 * src/gram.h (rule_t): New. diff --git a/src/conflicts.c b/src/conflicts.c index 73df3b64..fd7af88c 100644 --- a/src/conflicts.c +++ b/src/conflicts.c @@ -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; diff --git a/src/gram.h b/src/gram.h index 66031cc3..c12698b6 100644 --- a/src/gram.h +++ b/src/gram.h @@ -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. */ diff --git a/src/reader.c b/src/reader.c index 93024ea1..b7795dee 100644 --- a/src/reader.c +++ b/src/reader.c @@ -1923,9 +1923,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; @@ -1945,8 +1942,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; @@ -1956,9 +1953,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; diff --git a/src/reduce.c b/src/reduce.c index 71448410..1e65eee0 100644 --- a/src/reduce.c +++ b/src/reduce.c @@ -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)); -- 2.45.2