From 5edafffd36392c94b6e308f5d4f4eb752a83aa19 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 10 Dec 2001 09:10:28 +0000 Subject: [PATCH] * src/lalr.c (initialize_lookaheads): New. Extracted from... * src/LR0.c (set_state_table): here. * src/lalr.c (lalr): Call it. --- ChangeLog | 6 ++++++ src/LR0.c | 33 --------------------------------- src/lalr.c | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 33 deletions(-) diff --git a/ChangeLog b/ChangeLog index e108638d..ff06798a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2001-12-10 Akim Demaille + + * src/lalr.c (initialize_lookaheads): New. Extracted from... + * src/LR0.c (set_state_table): here. + * src/lalr.c (lalr): Call it. + 2001-12-10 Akim Demaille * src/state.h (shifts): Remove the `number' member: shifts are diff --git a/src/LR0.c b/src/LR0.c index d3f099b6..5e8caef0 100644 --- a/src/LR0.c +++ b/src/LR0.c @@ -560,39 +560,6 @@ set_state_table (void) 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; - } } /*-------------------------------------------------------------------. diff --git a/src/lalr.c b/src/lalr.c index b1188d64..150b15e9 100644 --- a/src/lalr.c +++ b/src/lalr.c @@ -534,11 +534,48 @@ compute_lookaheads (void) } +/*--------------------------------------. +| Initializing the lookaheads members. | +`--------------------------------------*/ + +static void +initialize_lookaheads (void) +{ + 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; +} + void lalr (void) { tokensetsize = WORDSIZE (ntokens); + initialize_lookaheads (); initialize_LA (); set_goto_map (); initialize_F (); -- 2.45.2