/[bison]/bison/src/lalr.c
ViewVC logotype

Diff of /bison/src/lalr.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.55 by akim, Sat Dec 29 14:20:27 2001 UTC revision 1.56 by akim, Sat Dec 29 14:20:47 2001 UTC
# Line 36  Line 36 
36  #include "getargs.h"  #include "getargs.h"
37    
38  /* All the decorated states, indexed by the state number.  */  /* All the decorated states, indexed by the state number.  */
39  state_t **state_table = NULL;  state_t **states = NULL;
40    
41  int tokensetsize;  int tokensetsize;
42  short *LAruleno;  short *LAruleno;
# Line 150  initialize_LA (void) Line 150  initialize_LA (void)
150    
151    np = LAruleno;    np = LAruleno;
152    for (i = 0; i < nstates; i++)    for (i = 0; i < nstates; i++)
153      if (!state_table[i]->consistent)      if (!states[i]->consistent)
154        for (j = 0; j < state_table[i]->reductions->nreds; j++)        for (j = 0; j < states[i]->reductions->nreds; j++)
155          *np++ = state_table[i]->reductions->rules[j];          *np++ = states[i]->reductions->rules[j];
156  }  }
157    
158    
# Line 168  set_goto_map (void) Line 168  set_goto_map (void)
168    ngotos = 0;    ngotos = 0;
169    for (state = 0; state < nstates; ++state)    for (state = 0; state < nstates; ++state)
170      {      {
171        shifts *sp = state_table[state]->shifts;        shifts *sp = states[state]->shifts;
172        for (i = sp->nshifts - 1; i >= 0 && SHIFT_IS_GOTO (sp, i); --i)        for (i = sp->nshifts - 1; i >= 0 && SHIFT_IS_GOTO (sp, i); --i)
173          {          {
174            if (ngotos == MAXSHORT)            if (ngotos == MAXSHORT)
# Line 199  set_goto_map (void) Line 199  set_goto_map (void)
199    
200    for (state = 0; state < nstates; ++state)    for (state = 0; state < nstates; ++state)
201      {      {
202        shifts *sp = state_table[state]->shifts;        shifts *sp = states[state]->shifts;
203        for (i = sp->nshifts - 1; i >= 0 && SHIFT_IS_GOTO (sp, i); --i)        for (i = sp->nshifts - 1; i >= 0 && SHIFT_IS_GOTO (sp, i); --i)
204          {          {
205            int k = temp_map[SHIFT_SYMBOL (sp, i)]++;            int k = temp_map[SHIFT_SYMBOL (sp, i)]++;
# Line 260  initialize_F (void) Line 260  initialize_F (void)
260    for (i = 0; i < ngotos; i++)    for (i = 0; i < ngotos; i++)
261      {      {
262        int stateno = to_state[i];        int stateno = to_state[i];
263        shifts *sp = state_table[stateno]->shifts;        shifts *sp = states[stateno]->shifts;
264    
265        int j;        int j;
266        for (j = 0; j < sp->nshifts && SHIFT_IS_SHIFT (sp, j); j++)        for (j = 0; j < sp->nshifts && SHIFT_IS_SHIFT (sp, j); j++)
# Line 409  build_relations (void) Line 409  build_relations (void)
409    for (i = 0; i < ngotos; i++)    for (i = 0; i < ngotos; i++)
410      {      {
411        int nedges = 0;        int nedges = 0;
412        int symbol1 = state_table[to_state[i]]->accessing_symbol;        int symbol1 = states[to_state[i]]->accessing_symbol;
413        short *rulep;        short *rulep;
414    
415        for (rulep = derives[symbol1]; *rulep > 0; rulep++)        for (rulep = derives[symbol1]; *rulep > 0; rulep++)
# Line 417  build_relations (void) Line 417  build_relations (void)
417            int done;            int done;
418            int length = 1;            int length = 1;
419            short *rp;            short *rp;
420            state_t *state = state_table[from_state[i]];            state_t *state = states[from_state[i]];
421            states1[0] = state->number;            states1[0] = state->number;
422    
423            for (rp = &ritem[rules[*rulep].rhs]; *rp >= 0; rp++)            for (rp = &ritem[rules[*rulep].rhs]; *rp >= 0; rp++)
# Line 426  build_relations (void) Line 426  build_relations (void)
426                int j;                int j;
427                for (j = 0; j < sp->nshifts; j++)                for (j = 0; j < sp->nshifts; j++)
428                  {                  {
429                    state = state_table[sp->shifts[j]];                    state = states[sp->shifts[j]];
430                    if (state->accessing_symbol == *rp)                    if (state->accessing_symbol == *rp)
431                      break;                      break;
432                  }                  }
# Line 522  initialize_lookaheads (void) Line 522  initialize_lookaheads (void)
522      {      {
523        int k;        int k;
524        int nlookaheads = 0;        int nlookaheads = 0;
525        reductions *rp = state_table[i]->reductions;        reductions *rp = states[i]->reductions;
526        shifts *sp = state_table[i]->shifts;        shifts *sp = states[i]->shifts;
527    
528        /* We need a lookahead either to distinguish different        /* We need a lookahead either to distinguish different
529           reductions (i.e., there are two or more), or to distinguish a           reductions (i.e., there are two or more), or to distinguish a
# Line 533  initialize_lookaheads (void) Line 533  initialize_lookaheads (void)
533            || (rp->nreds == 1 && sp->nshifts && SHIFT_IS_SHIFT (sp, 0)))            || (rp->nreds == 1 && sp->nshifts && SHIFT_IS_SHIFT (sp, 0)))
534          nlookaheads += rp->nreds;          nlookaheads += rp->nreds;
535        else        else
536          state_table[i]->consistent = 1;          states[i]->consistent = 1;
537    
538        for (k = 0; k < sp->nshifts; k++)        for (k = 0; k < sp->nshifts; k++)
539          if (SHIFT_IS_ERROR (sp, k))          if (SHIFT_IS_ERROR (sp, k))
540            {            {
541              state_table[i]->consistent = 0;              states[i]->consistent = 0;
542              break;              break;
543            }            }
544    
545        state_table[i]->nlookaheads = nlookaheads;        states[i]->nlookaheads = nlookaheads;
546        state_table[i]->lookaheadsp = nLA;        states[i]->lookaheadsp = nLA;
547        nLA += nlookaheads;        nLA += nlookaheads;
548      }      }
549  }  }
# Line 561  lookaheads_print (FILE *out) Line 561  lookaheads_print (FILE *out)
561    for (i = 0; i < nstates; ++i)    for (i = 0; i < nstates; ++i)
562      {      {
563        fprintf (out, "State %d: %d lookaheads\n",        fprintf (out, "State %d: %d lookaheads\n",
564                 i, state_table[i]->nlookaheads);                 i, states[i]->nlookaheads);
565    
566        for (j = 0; j < state_table[i]->nlookaheads; ++j)        for (j = 0; j < states[i]->nlookaheads; ++j)
567          for (k = 0; k < ntokens; ++k)          for (k = 0; k < ntokens; ++k)
568            if (BITISSET (LA (state_table[i]->lookaheadsp + j), j))            if (BITISSET (LA (states[i]->lookaheadsp + j), j))
569              fprintf (out, "   on %d (%s) -> rule %d\n",              fprintf (out, "   on %d (%s) -> rule %d\n",
570                       k, symbols[k]->tag,                       k, symbols[k]->tag,
571                       -LAruleno[state_table[i]->lookaheadsp + j] - 1);                       -LAruleno[states[i]->lookaheadsp + j] - 1);
572      }      }
573    fprintf (out, "Lookaheads: END\n");    fprintf (out, "Lookaheads: END\n");
574  }  }

Legend:
Removed from v.1.55  
changed lines
  Added in v.1.56

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26