From: Akim Demaille Date: Mon, 10 Dec 2001 09:08:46 +0000 (+0000) Subject: * src/lalr.c (set_state_table): Move to... X-Git-Tag: before-m4-back-end~164 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/6a164e0c9619066b9d3f9e2401f68b602d4159e1 * src/lalr.c (set_state_table): Move to... * src/LR0.c: here. * src/lalr.c (lalr): Don't call it... * src/LR0.c (generate_states): do it. * src/LR0.h (first_state): Remove, only the table is used. --- diff --git a/ChangeLog b/ChangeLog index 0285745c..11d51ecc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2001-12-10 Akim Demaille + + * src/lalr.c (set_state_table): Move to... + * src/LR0.c: here. + * src/lalr.c (lalr): Don't call it... + * src/LR0.c (generate_states): do it. + * src/LR0.h (first_state): Remove, only the table is used. + + 2001-12-10 Akim Demaille * src/LR0.h (first_shift, first_reduction): Remove. diff --git a/src/LR0.c b/src/LR0.c index a969abb4..ccd55f6a 100644 --- a/src/LR0.c +++ b/src/LR0.c @@ -35,8 +35,8 @@ int nstates; int final_state; -state_t *first_state = NULL; -shifts *first_shift = NULL; +static state_t *first_state = NULL; +static shifts *first_shift = NULL; static state_t *this_state = NULL; static state_t *last_state = NULL; @@ -601,6 +601,67 @@ save_reductions (void) } +/*--------------------. +| Build STATE_TABLE. | +`--------------------*/ + +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_t *sp; + for (sp = first_state; sp; sp = sp->next) + state_table[sp->number] = sp; + } + + /* Pessimization, but simplification of the code: make sure all the + states have a shifts, even if reduced to 0 shifts. */ + { + int i; + for (i = 0; i < nstates; i++) + if (!state_table[i]->shifts) + state_table[i]->shifts = shifts_new (0); + } + + /* Initializing the lookaheads members. Please note that it must be + performed after having set some of the other members which are + used below. Change with extreme caution. */ + { + int i; + int count = 0; + for (i = 0; i < nstates; i++) + { + int k; + reductions *rp = state_table[i]->reductions; + shifts *sp = state_table[i]->shifts; + + state_table[i]->lookaheads = count; + + if (rp + && (rp->nreds > 1 || (sp->nshifts && SHIFT_IS_SHIFT (sp, 0)))) + count += rp->nreds; + else + state_table[i]->consistent = 1; + + for (k = 0; k < sp->nshifts; k++) + if (SHIFT_IS_ERROR (sp, k)) + { + state_table[i]->consistent = 0; + break; + } + } + + /* Seems to be needed by conflicts.c. */ + state_table[nstates] = STATE_ALLOC (0); + state_table[nstates]->lookaheads = count; + } +} + /*-------------------------------------------------------------------. | Compute the nondeterministic finite state machine (see state.h for | | details) from the grammar. | @@ -644,4 +705,7 @@ generate_states (void) /* set up initial and final states as parser wants them */ augment_automaton (); + + /* Set up STATE_TABLE. */ + set_state_table (); } diff --git a/src/LR0.h b/src/LR0.h index 14a0fb25..2866a0d7 100644 --- a/src/LR0.h +++ b/src/LR0.h @@ -27,6 +27,5 @@ void generate_states PARAMS ((void)); extern int nstates; extern int final_state; -extern state_t *first_state; #endif /* !LR0_H_ */ diff --git a/src/lalr.c b/src/lalr.c index 6042eca8..b1188d64 100644 --- a/src/lalr.c +++ b/src/lalr.c @@ -132,68 +132,6 @@ digraph (short **relation) } -/*--------------------. -| Build STATE_TABLE. | -`--------------------*/ - -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_t *sp; - for (sp = first_state; sp; sp = sp->next) - state_table[sp->number] = sp; - } - - /* Pessimization, but simplification of the code: make sure all the - states have a shifts, even if reduced to 0 shifts. */ - { - int i; - for (i = 0; i < nstates; i++) - if (!state_table[i]->shifts) - state_table[i]->shifts = shifts_new (0); - } - - /* Initializing the lookaheads members. Please note that it must be - performed after having set some of the other members which are - used below. Change with extreme caution. */ - { - int i; - int count = 0; - for (i = 0; i < nstates; i++) - { - int k; - reductions *rp = state_table[i]->reductions; - shifts *sp = state_table[i]->shifts; - - state_table[i]->lookaheads = count; - - if (rp - && (rp->nreds > 1 || (sp->nshifts && SHIFT_IS_SHIFT (sp, 0)))) - count += rp->nreds; - else - state_table[i]->consistent = 1; - - for (k = 0; k < sp->nshifts; k++) - if (SHIFT_IS_ERROR (sp, k)) - { - state_table[i]->consistent = 0; - break; - } - } - - /* Seems to be needed by conflicts.c. */ - state_table[nstates] = STATE_ALLOC (0); - state_table[nstates]->lookaheads = count; - } -} - - static void initialize_LA (void) { @@ -601,7 +539,6 @@ lalr (void) { tokensetsize = WORDSIZE (ntokens); - set_state_table (); initialize_LA (); set_goto_map (); initialize_F ();