From: Akim Demaille Date: Thu, 27 Dec 2001 18:05:30 +0000 (+0000) Subject: All the hacks using a final pseudo state are now useless. X-Git-Tag: before-m4-back-end~97 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/d200e455d069992b6a491a0fbf1cb39a10c6937b All the hacks using a final pseudo state are now useless. * src/LR0.c (set_state_table): state_table holds exactly nstates. * src/lalr.c (nLA): New. (initialize_LA, compute_lookaheads, initialize_lookaheads): Use it instead of lookaheadsp from the pseudo state (nstate + 1). --- diff --git a/ChangeLog b/ChangeLog index 421de6f2..e8f48a0b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2001-12-27 Akim Demaille + + All the hacks using a final pseudo state are now useless. + + * src/LR0.c (set_state_table): state_table holds exactly nstates. + * src/lalr.c (nLA): New. + (initialize_LA, compute_lookaheads, initialize_lookaheads): Use it + instead of lookaheadsp from the pseudo state (nstate + 1). + 2001-12-27 Akim Demaille * src/output.c (action_row, token_actions): Use a state_t instead diff --git a/src/LR0.c b/src/LR0.c index 5e8caef0..148e2bc0 100644 --- a/src/LR0.c +++ b/src/LR0.c @@ -541,10 +541,7 @@ save_reductions (void) static void set_state_table (void) { - /* NSTATES + 1 because lookahead for the pseudo state number NSTATES - might be used (see conflicts.c). It is too opaque for me to - provide a probably less hacky implementation. --akim */ - state_table = XCALLOC (state_t *, nstates + 1); + state_table = XCALLOC (state_t *, nstates); { state_t *sp; diff --git a/src/lalr.c b/src/lalr.c index 0eb32411..8617ae8b 100644 --- a/src/lalr.c +++ b/src/lalr.c @@ -33,14 +33,13 @@ #include "derives.h" #include "getargs.h" -/* All the decorated states, indexed by the state number. Warning: - there is a state_TABLE in LR0.c, but it is different and static. - */ +/* All the decorated states, indexed by the state number. */ state_t **state_table = NULL; int tokensetsize; short *LAruleno; unsigned *LA; +size_t nLA; static int ngotos; short *goto_map; @@ -140,7 +139,7 @@ initialize_LA (void) short *np; reductions *rp; - size_t nLA = state_table[nstates]->lookaheadsp; + /* Avoid having to special case 0. */ if (!nLA) nLA = 1; @@ -504,10 +503,10 @@ compute_FOLLOWS (void) static void compute_lookaheads (void) { - int i; + size_t i; shorts *sp; - for (i = 0; i < state_table[nstates]->lookaheadsp; i++) + for (i = 0; i < nLA; i++) for (sp = lookback[i]; sp; sp = sp->next) { int size = LA (i + 1) - LA (i); @@ -517,7 +516,7 @@ compute_lookaheads (void) } /* Free LOOKBACK. */ - for (i = 0; i < state_table[nstates]->lookaheadsp; i++) + for (i = 0; i < nLA; i++) LIST_FREE (shorts, lookback[i]); XFREE (lookback); @@ -533,7 +532,7 @@ static void initialize_lookaheads (void) { int i; - int count = 0; + nLA = 0; for (i = 0; i < nstates; i++) { int k; @@ -555,13 +554,9 @@ initialize_lookaheads (void) } state_table[i]->nlookaheads = nlookaheads; - state_table[i]->lookaheadsp = count; - count += nlookaheads; + state_table[i]->lookaheadsp = nLA; + nLA += nlookaheads; } - - /* Seems to be needed by conflicts.c. */ - state_table[nstates] = STATE_ALLOC (0); - state_table[nstates]->lookaheadsp = count; } void