/[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.17 by akim, Thu Oct 4 14:55:20 2001 UTC revision 1.18 by akim, Mon Nov 19 10:07:14 2001 UTC
# Line 32  Line 32 
32  #include "nullable.h"  #include "nullable.h"
33  #include "derives.h"  #include "derives.h"
34    
35    /* All the decorated states, indexed by the state number.  Warning:
36       there is a state_TABLE in LR0.c, but it is different and static.
37       */
38    state_t *state_table = NULL;
39    
40  int tokensetsize;  int tokensetsize;
41  short *lookaheads;  short *lookaheads;
42  short *LAruleno;  short *LAruleno;
43  unsigned *LA;  unsigned *LA;
44  short *accessing_symbol;  
45  char *consistent;  char *consistent;
 core **state_table;  
46  shifts **shift_table;  shifts **shift_table;
47  reductions **reduction_table;  reductions **reduction_table;
48  short *goto_map;  short *goto_map;
# Line 146  set_state_table (void) Line 150  set_state_table (void)
150  {  {
151    core *sp;    core *sp;
152    
153    state_table = XCALLOC (core *, nstates);    state_table = XCALLOC (state_t, nstates);
   
   for (sp = first_state; sp; sp = sp->next)  
     state_table[sp->number] = sp;  
 }  
   
   
 static void  
 set_accessing_symbol (void)  
 {  
   core *sp;  
   
   accessing_symbol = XCALLOC (short, nstates);  
154    
155    for (sp = first_state; sp; sp = sp->next)    for (sp = first_state; sp; sp = sp->next)
156      accessing_symbol[sp->number] = sp->accessing_symbol;      {
157          state_table[sp->number].state = sp;
158          state_table[sp->number].accessing_symbol = sp->accessing_symbol;
159        }
160  }  }
161    
162    
# Line 238  initialize_LA (void) Line 233  initialize_LA (void)
233    
234        rp = reduction_table[i];        rp = reduction_table[i];
235        sp = shift_table[i];        sp = shift_table[i];
236        if (rp && (rp->nreds > 1        if (rp
237                   || (sp && !ISVAR (accessing_symbol[sp->shifts[0]]))))            && (rp->nreds > 1
238                  || (sp && !ISVAR (state_table[sp->shifts[0]].accessing_symbol))))
239          count += rp->nreds;          count += rp->nreds;
240        else        else
241          consistent[i] = 1;          consistent[i] = 1;
242    
243        if (sp)        if (sp)
244          for (k = 0; k < sp->nshifts; k++)          for (k = 0; k < sp->nshifts; k++)
245            {            if (state_table[sp->shifts[k]].accessing_symbol
246              if (accessing_symbol[sp->shifts[k]] == error_token_number)                == error_token_number)
247                {              {
248                  consistent[i] = 0;                consistent[i] = 0;
249                  break;                break;
250                }              }
           }  
251      }      }
252    
253    lookaheads[nstates] = count;    lookaheads[nstates] = count;
# Line 302  set_goto_map (void) Line 297  set_goto_map (void)
297      {      {
298        for (i = sp->nshifts - 1; i >= 0; i--)        for (i = sp->nshifts - 1; i >= 0; i--)
299          {          {
300            symbol = accessing_symbol[sp->shifts[i]];            symbol = state_table[sp->shifts[i]].accessing_symbol;
301    
302            if (ISTOKEN (symbol))            if (ISTOKEN (symbol))
303              break;              break;
# Line 337  set_goto_map (void) Line 332  set_goto_map (void)
332        for (i = sp->nshifts - 1; i >= 0; i--)        for (i = sp->nshifts - 1; i >= 0; i--)
333          {          {
334            state2 = sp->shifts[i];            state2 = sp->shifts[i];
335            symbol = accessing_symbol[state2];            symbol = state_table[state2].accessing_symbol;
336    
337            if (ISTOKEN (symbol))            if (ISTOKEN (symbol))
338              break;              break;
# Line 421  initialize_F (void) Line 416  initialize_F (void)
416    
417            for (j = 0; j < k; j++)            for (j = 0; j < k; j++)
418              {              {
419                symbol = accessing_symbol[sp->shifts[j]];                symbol = state_table[sp->shifts[j]].accessing_symbol;
420                if (ISVAR (symbol))                if (ISVAR (symbol))
421                  break;                  break;
422                SETBIT (rowp, symbol);                SETBIT (rowp, symbol);
# Line 429  initialize_F (void) Line 424  initialize_F (void)
424    
425            for (; j < k; j++)            for (; j < k; j++)
426              {              {
427                symbol = accessing_symbol[sp->shifts[j]];                symbol = state_table[sp->shifts[j]].accessing_symbol;
428                if (nullable[symbol])                if (nullable[symbol])
429                  edge[nedges++] = map_goto (stateno, symbol);                  edge[nedges++] = map_goto (stateno, symbol);
430              }              }
# Line 574  build_relations (void) Line 569  build_relations (void)
569      {      {
570        nedges = 0;        nedges = 0;
571        state1 = from_state[i];        state1 = from_state[i];
572        symbol1 = accessing_symbol[to_state[i]];        symbol1 = state_table[to_state[i]].accessing_symbol;
573    
574        for (rulep = derives[symbol1]; *rulep > 0; rulep++)        for (rulep = derives[symbol1]; *rulep > 0; rulep++)
575          {          {
# Line 591  build_relations (void) Line 586  build_relations (void)
586                for (j = 0; j < k; j++)                for (j = 0; j < k; j++)
587                  {                  {
588                    stateno = sp->shifts[j];                    stateno = sp->shifts[j];
589                    if (accessing_symbol[stateno] == symbol2)                    if (state_table[stateno].accessing_symbol == symbol2)
590                      break;                      break;
591                  }                  }
592    
# Line 709  lalr (void) Line 704  lalr (void)
704    tokensetsize = WORDSIZE (ntokens);    tokensetsize = WORDSIZE (ntokens);
705    
706    set_state_table ();    set_state_table ();
   set_accessing_symbol ();  
707    set_shift_table ();    set_shift_table ();
708    set_reduction_table ();    set_reduction_table ();
709    set_maxrhs ();    set_maxrhs ();

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.18

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