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

Diff of /bison/src/LR0.c

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

revision 1.29 by akim, Wed Dec 5 09:27:23 2001 UTC revision 1.30 by akim, Wed Dec 5 09:29:33 2001 UTC
# Line 387  insert_start_shift (void) Line 387  insert_start_shift (void)
387  static void  static void
388  augment_automaton (void)  augment_automaton (void)
389  {  {
   int i;  
   int k;  
390    core *statep;    core *statep;
391    shifts *sp;    shifts *sp;
   shifts *sp2;  
392    shifts *sp1 = NULL;    shifts *sp1 = NULL;
393    
394    sp = first_shift;    sp = first_shift;
395    
396    if (sp)    if (!sp)
397      {      {
398        if (sp->number == 0)        /* There are no shifts for any state.  Make one shift, from the
399          {           initial state to the next-to-final state.  */
400            k = sp->nshifts;  
401            statep = first_state->next;        sp = shifts_new (1);
402          sp->shifts[0] = nstates;
403    
404            /* The states reached by shifts from first_state are numbered 1...K.        /* Initialize the chain of shifts with sp.  */
405               Look for one reached by start_symbol.  */        first_shift = sp;
406            while (statep->accessing_symbol < start_symbol        last_shift = sp;
                  && statep->number < k)  
             statep = statep->next;  
407    
408            if (statep->accessing_symbol == start_symbol)        /* Create the next-to-final state, with shift to
409             what will be the final state.  */
410          insert_start_shift ();
411        }
412      else if (sp->number == 0)
413        {
414          statep = first_state->next;
415    
416          /* The states reached by shifts from FIRST_STATE are numbered
417             1..(SP->NSHIFTS).  Look for one reached by START_SYMBOL.  */
418          while (statep->accessing_symbol < start_symbol
419                 && statep->number < sp->nshifts)
420            statep = statep->next;
421    
422          if (statep->accessing_symbol == start_symbol)
423            {
424              /* We already have a next-to-final state.
425                 Make sure it has a shift to what will be the final state.  */
426              while (sp && sp->number < statep->number)
427              {              {
428                /* We already have a next-to-final state.                sp1 = sp;
429                   Make sure it has a shift to what will be the final state.  */                sp = sp->next;
               k = statep->number;  
   
               while (sp && sp->number < k)  
                 {  
                   sp1 = sp;  
                   sp = sp->next;  
                 }  
   
               if (sp && sp->number == k)  
                 {  
                   sp2 = shifts_new (sp->nshifts + 1);  
                   sp2->number = k;  
                   sp2->shifts[0] = nstates;  
                   for (i = sp->nshifts; i > 0; i--)  
                     sp2->shifts[i] = sp->shifts[i - 1];  
   
                   /* Patch sp2 into the chain of shifts in place of sp,  
                      following sp1.  */  
                   sp2->next = sp->next;  
                   sp1->next = sp2;  
                   if (sp == last_shift)  
                     last_shift = sp2;  
                   XFREE (sp);  
                 }  
               else  
                 {  
                   sp2 = shifts_new (1);  
                   sp2->number = k;  
                   sp2->shifts[0] = nstates;  
   
                   /* Patch sp2 into the chain of shifts between sp1 and sp.  */  
                   sp2->next = sp;  
                   sp1->next = sp2;  
                   if (sp == 0)  
                     last_shift = sp2;  
                 }  
430              }              }
431            else  
432              if (sp && sp->number == statep->number)
433              {              {
434                /* There is no next-to-final state as yet.  */                int i;
435                /* Add one more shift in first_shift,                shifts *sp2 = shifts_new (sp->nshifts + 1);
436                   going to the next-to-final state (yet to be made).  */                sp2->number = statep->number;
437                sp = first_shift;                sp2->shifts[0] = nstates;
438                  for (i = sp->nshifts; i > 0; i--)
439                sp2 = shifts_new (sp->nshifts + 1);                  sp2->shifts[i] = sp->shifts[i - 1];
   
               /* Stick this shift into the vector at the proper place.  */  
               statep = first_state->next;  
               for (k = 0, i = 0; i < sp->nshifts; k++, i++)  
                 {  
                   if (statep->accessing_symbol > start_symbol && i == k)  
                     sp2->shifts[k++] = nstates;  
                   sp2->shifts[k] = sp->shifts[i];  
                   statep = statep->next;  
                 }  
               if (i == k)  
                 sp2->shifts[k++] = nstates;  
440    
441                /* Patch sp2 into the chain of shifts                /* Patch sp2 into the chain of shifts in place of sp,
442                   in place of sp, at the beginning.  */                   following sp1.  */
443                sp2->next = sp->next;                sp2->next = sp->next;
444                first_shift = sp2;                sp1->next = sp2;
445                if (last_shift == sp)                if (sp == last_shift)
446                  last_shift = sp2;                  last_shift = sp2;
   
447                XFREE (sp);                XFREE (sp);
448                }
449                /* Create the next-to-final state, with shift to            else
450                   what will be the final state.  */              {
451                insert_start_shift ();                shifts *sp2 = shifts_new (1);
452                  sp2->number = statep->number;
453                  sp2->shifts[0] = nstates;
454    
455                  /* Patch sp2 into the chain of shifts between sp1 and sp.  */
456                  sp2->next = sp;
457                  sp1->next = sp2;
458                  if (sp == 0)
459                    last_shift = sp2;
460              }              }
461          }          }
462        else        else
463          {          {
464            /* The initial state didn't even have any shifts.            int i, k;
465               Give it one shift, to the next-to-final state.  */            shifts *sp2;
466            sp = shifts_new (1);  
467            sp->shifts[0] = nstates;            /* There is no next-to-final state as yet.  */
468              /* Add one more shift in first_shift,
469            /* Patch sp into the chain of shifts at the beginning.  */               going to the next-to-final state (yet to be made).  */
470            sp->next = first_shift;            sp = first_shift;
471            first_shift = sp;  
472              sp2 = shifts_new (sp->nshifts + 1);
473    
474              /* Stick this shift into the vector at the proper place.  */
475              statep = first_state->next;
476              for (k = 0, i = 0; i < sp->nshifts; k++, i++)
477                {
478                  if (statep->accessing_symbol > start_symbol && i == k)
479                    sp2->shifts[k++] = nstates;
480                  sp2->shifts[k] = sp->shifts[i];
481                  statep = statep->next;
482                }
483              if (i == k)
484                sp2->shifts[k++] = nstates;
485    
486              /* Patch sp2 into the chain of shifts
487                 in place of sp, at the beginning.  */
488              sp2->next = sp->next;
489              first_shift = sp2;
490              if (last_shift == sp)
491                last_shift = sp2;
492    
493              XFREE (sp);
494    
495            /* Create the next-to-final state, with shift to            /* Create the next-to-final state, with shift to
496               what will be the final state.  */               what will be the final state.  */
# Line 503  augment_automaton (void) Line 499  augment_automaton (void)
499      }      }
500    else    else
501      {      {
502        /* There are no shifts for any state.        /* The initial state didn't even have any shifts.
503           Make one shift, from the initial state to the next-to-final state.  */           Give it one shift, to the next-to-final state.  */
   
504        sp = shifts_new (1);        sp = shifts_new (1);
505        sp->shifts[0] = nstates;        sp->shifts[0] = nstates;
506    
507        /* Initialize the chain of shifts with sp.  */        /* Patch sp into the chain of shifts at the beginning.  */
508          sp->next = first_shift;
509        first_shift = sp;        first_shift = sp;
       last_shift = sp;  
510    
511        /* Create the next-to-final state, with shift to        /* Create the next-to-final state, with shift to
512           what will be the final state.  */           what will be the final state.  */
513        insert_start_shift ();        insert_start_shift ();
514      }      }
515    

Legend:
Removed from v.1.29  
changed lines
  Added in v.1.30

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