From: Akim Demaille Date: Sun, 7 Apr 2002 17:41:44 +0000 (+0000) Subject: * src/lalr.h, src/lalr.c (LAruleno): Replace with... X-Git-Tag: BISON-1_49a~69 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/b0299a2ebb1a000b67d23d3cfecb52f699dd734a?ds=inline * src/lalr.h, src/lalr.c (LAruleno): Replace with... (LArule): this, which is an array to rule_t*. * src/print.c, src/conflicts.c: Adjust. --- diff --git a/ChangeLog b/ChangeLog index aecf5f91..e012853c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2002-04-07 Akim Demaille + + * src/lalr.h, src/lalr.c (LAruleno): Replace with... + (LArule): this, which is an array to rule_t*. + * src/print.c, src/conflicts.c: Adjust. + + 2002-04-07 Akim Demaille * src/gram.h (rule_t): Rename `number' as `user_number'. diff --git a/src/conflicts.c b/src/conflicts.c index 50669cbf..df7b457c 100644 --- a/src/conflicts.c +++ b/src/conflicts.c @@ -46,7 +46,9 @@ log_resolution (state_t *state, int LAno, int token, const char *resolution) obstack_fgrow4 (&output_obstack, _("\ Conflict in state %d between rule %d and token %s resolved as %s.\n"), - state->number, LAruleno[LAno], symbols[token]->tag, + state->number, + LArule[LAno]->number, + symbols[token]->tag, resolution); } @@ -95,7 +97,7 @@ resolve_sr_conflict (state_t *state, int lookahead) { int i; /* find the rule to reduce by to get precedence of reduction */ - int redprec = rules[LAruleno[lookahead]].prec; + int redprec = LArule[lookahead]->prec; errs *errp = errs_new (ntokens + 1); errp->nerrs = 0; @@ -172,7 +174,7 @@ set_conflicts (state_t *state) check for shift-reduce conflict, and try to resolve using precedence */ for (i = 0; i < state->nlookaheads; ++i) - if (rules[LAruleno[state->lookaheadsp + i]].prec + if (LArule[state->lookaheadsp + i]->prec && !bitset_disjoint_p (LA[state->lookaheadsp + i], lookaheadset)) { resolve_sr_conflict (state, state->lookaheadsp + i); diff --git a/src/lalr.c b/src/lalr.c index 192e46e2..e1e2719d 100644 --- a/src/lalr.c +++ b/src/lalr.c @@ -1,5 +1,6 @@ /* Compute look-ahead criteria for bison, - Copyright 1984, 1986, 1989, 2000, 2001 Free Software Foundation, Inc. + Copyright (C) 1984, 1986, 1989, 2000, 2001, 2002 + Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -40,7 +41,7 @@ /* All the decorated states, indexed by the state number. */ state_t **states = NULL; -short *LAruleno = NULL; +rule_t **LArule = NULL; bitsetv LA = NULL; size_t nLA; @@ -134,21 +135,21 @@ initialize_LA (void) { size_t i; int j; - short *np; + rule_t **np; /* Avoid having to special case 0. */ if (!nLA) nLA = 1; LA = bitsetv_create (nLA, ntokens, BITSET_FIXED); - LAruleno = XCALLOC (short, nLA); + LArule = XCALLOC (rule_t *, nLA); lookback = XCALLOC (shorts *, nLA); - np = LAruleno; + np = LArule; for (i = 0; i < nstates; i++) if (!states[i]->consistent) for (j = 0; j < states[i]->reductions->nreds; j++) - *np++ = states[i]->reductions->rules[j]; + *np++ = &rules[states[i]->reductions->rules[j]]; } @@ -296,10 +297,10 @@ add_lookback_edge (state_t *state, int ruleno, int gotono) shorts *sp; for (i = 0; i < state->nlookaheads; ++i) - if (LAruleno[state->lookaheadsp + i] == ruleno) + if (LArule[state->lookaheadsp + i]->number == ruleno) break; - assert (LAruleno[state->lookaheadsp + i] == ruleno); + assert (LArule[state->lookaheadsp + i]->number == ruleno); sp = XCALLOC (shorts, 1); sp->next = lookback[state->lookaheadsp + i]; @@ -561,7 +562,7 @@ lookaheads_print (FILE *out) if (bitset_test (LA[states[i]->lookaheadsp + j], j)) fprintf (out, " on %d (%s) -> rule %d\n", k, symbols[k]->tag, - -LAruleno[states[i]->lookaheadsp + j] - 1); + LArule[states[i]->lookaheadsp + j]->number - 1); } fprintf (out, "Lookaheads: END\n"); } diff --git a/src/lalr.h b/src/lalr.h index 4b57ae30..9731563d 100644 --- a/src/lalr.h +++ b/src/lalr.h @@ -1,5 +1,5 @@ /* Compute look-ahead criteria for bison, - Copyright 1984, 1986, 1989, 2000, 2002 Free Software Foundation, Inc. + Copyright (C) 1984, 1986, 1989, 2000, 2002 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -26,6 +26,8 @@ /* Import the definition of CORE, SHIFTS and REDUCTIONS. */ # include "state.h" +/* Import the definition of RULE_T. */ +# include "gram.h" /* Compute how to make the finite state machine deterministic; find which rules need lookahead in each state, and which lookahead @@ -50,16 +52,15 @@ extern short *goto_map; extern short *from_state; extern short *to_state; -/* LARULENO is a vector which records the rules that need lookahead in - various states. The elements of LARULENO that apply to state S are - those from LOOKAHEADS[S] through LOOKAHEADS[S+1]-1. Each element - of LARULENO is a rule number. +/* LARULE is a vector which records the rules that need lookahead in + various states. The elements of LARULE that apply to state S are + those from LOOKAHEADS[S] through LOOKAHEADS[S+1]-1. - If LR is the length of LAruleno, then a number from 0 to LR-1 can + If LR is the length of LArule, then a number from 0 to LR-1 can specify both a rule and a state where the rule might be applied. */ -extern short *LAruleno; +extern rule_t **LArule; /* LA is a lr by ntokens matrix of bits. LA[l, i] is 1 if the rule LAruleno[l] is applicable in the appropriate state when the next diff --git a/src/output.c b/src/output.c index a098cb63..b813b537 100644 --- a/src/output.c +++ b/src/output.c @@ -348,7 +348,7 @@ action_row (state_t *state) /* and record this rule as the rule to use if that token follows. */ if (bitset_test (LA[state->lookaheadsp + i], j)) - actrow[j] = -LAruleno[state->lookaheadsp + i]; + actrow[j] = -LArule[state->lookaheadsp + i]->number; } /* Now see which tokens are allowed for shifts in this state. For @@ -395,7 +395,7 @@ action_row (state_t *state) for (i = 0; i < state->nlookaheads; i++) { int count = 0; - int rule = -LAruleno[state->lookaheadsp + i]; + int rule = -LArule[state->lookaheadsp + i]->number; int j; for (j = 0; j < ntokens; j++) @@ -918,7 +918,7 @@ output_actions (void) token_actions (); bitsetv_free (LA); - XFREE (LAruleno); + free (LArule); goto_actions (); XFREE (goto_map + ntokens); diff --git a/src/print.c b/src/print.c index 509e437b..5c1ef127 100644 --- a/src/print.c +++ b/src/print.c @@ -1,5 +1,6 @@ /* Print information on generated parser, for bison, - Copyright 1984, 1986, 1989, 2000, 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 1984, 1986, 1989, 2000, 2001, 2002 + Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -213,24 +214,26 @@ print_reductions (FILE *out, state_t *state) if (state->nlookaheads == 1 && !nodefault) { - int default_rule = LAruleno[state->lookaheadsp]; + rule_t *default_rule = LArule[state->lookaheadsp]; bitset_and (lookaheadset, LA[state->lookaheadsp], shiftset); for (i = 0; i < ntokens; i++) if (bitset_test (lookaheadset, i)) fprintf (out, _(" %-4s\t[reduce using rule %d (%s)]\n"), - escape (symbols[i]->tag), default_rule - 1, - escape2 (rules[default_rule].lhs->tag)); + escape (symbols[i]->tag), + default_rule->number - 1, + escape2 (default_rule->lhs->tag)); fprintf (out, _(" $default\treduce using rule %d (%s)\n\n"), - default_rule - 1, escape (rules[default_rule].lhs->tag)); + default_rule->number - 1, + escape (default_rule->lhs->tag)); } else if (state->nlookaheads >= 1) { int cmax = 0; int default_LA = -1; - int default_rule = 0; + rule_t *default_rule = NULL; if (!nodefault) for (i = 0; i < state->nlookaheads; ++i) @@ -248,7 +251,7 @@ print_reductions (FILE *out, state_t *state) { cmax = count; default_LA = state->lookaheadsp + i; - default_rule = LAruleno[state->lookaheadsp + i]; + default_rule = LArule[state->lookaheadsp + i]; } bitset_or (shiftset, shiftset, lookaheadset); @@ -275,8 +278,8 @@ print_reductions (FILE *out, state_t *state) fprintf (out, _(" %-4s\treduce using rule %d (%s)\n"), escape (symbols[i]->tag), - LAruleno[state->lookaheadsp + j] - 1, - escape2 (rules[LAruleno[state->lookaheadsp + j]].lhs->tag)); + LArule[state->lookaheadsp + j]->number - 1, + escape2 (LArule[state->lookaheadsp + j]->lhs->tag)); else defaulted = 1; @@ -288,22 +291,22 @@ print_reductions (FILE *out, state_t *state) fprintf (out, _(" %-4s\treduce using rule %d (%s)\n"), escape (symbols[i]->tag), - LAruleno[default_LA] - 1, - escape2 (rules[LAruleno[default_LA]].lhs->tag)); + LArule[default_LA]->number - 1, + escape2 (LArule[default_LA]->lhs->tag)); defaulted = 0; fprintf (out, _(" %-4s\t[reduce using rule %d (%s)]\n"), escape (symbols[i]->tag), - LAruleno[state->lookaheadsp + j] - 1, - escape2 (rules[LAruleno[state->lookaheadsp + j]].lhs->tag)); + LArule[state->lookaheadsp + j]->number - 1, + escape2 (LArule[state->lookaheadsp + j]->lhs->tag)); } } } if (default_LA >= 0) fprintf (out, _(" $default\treduce using rule %d (%s)\n"), - default_rule - 1, - escape (rules[default_rule].lhs->tag)); + default_rule->number - 1, + escape (default_rule->lhs->tag)); } }