home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / YACCUNX.ZIP / YSTAGN.1C < prev    next >
Encoding:
Text File  |  1983-12-23  |  2.4 KB  |  104 lines

  1. #include "y1.h"
  2.  
  3. /*
  4.  * ystagn.1c
  5.  *
  6.  * Modified to make debug code conditionally compile.
  7.  * 28-Aug-81
  8.  * Bob Denny
  9.  */
  10.  
  11. stagen()
  12.  
  13.    {
  14.    /* generate the states */
  15.  
  16.    int i, j;
  17.    register c;
  18.    register struct wset *p, *q;
  19.  
  20.    /* initialize */
  21.  
  22.    nstate = 0;
  23.    /* THIS IS FUNNY from the standpoint of portability */
  24.    /* it represents the magic moment when the mem0 array, which has
  25.         /* been holding the productions, starts to hold item pointers, of a
  26.         /* different type... */
  27.    /* someday, alloc should be used to allocate all this stuff... for now, we
  28.         /* accept that if pointers don't fit in integers, there is a problem... */
  29.  
  30.    pstate[0] = pstate[1] = (struct item *)mem;
  31.    aryfil( clset.lset, tbitset, 0 );
  32.    putitem( prdptr[0]+1, &clset );
  33.    tystate[0] = MUSTDO;
  34.    nstate = 1;
  35.    pstate[2] = pstate[1];
  36.  
  37.    aryfil( amem, ACTSIZE, 0 );
  38.  
  39.    /* now, the main state generation loop */
  40.  
  41. more:
  42.    SLOOP(i)
  43.  
  44.       {
  45.       if( tystate[i] != MUSTDO ) continue;
  46.       tystate[i] = DONE;
  47.       aryfil( temp1, nnonter+1, 0 );
  48.       /* take state i, close it, and do gotos */
  49.       closure(i);
  50.       WSLOOP(wsets,p)
  51.  
  52.          {
  53.          /* generate goto's */
  54.          if( p->flag ) continue;
  55.          p->flag = 1;
  56.          c = *(p->pitem);
  57.          if( c <= 1 ) 
  58.  
  59.             {
  60.             if( pstate[i+1]-pstate[i] <= p-wsets ) tystate[i] = MUSTLOOKAHEAD;
  61.             continue;
  62.             }
  63.          /* do a goto on c */
  64.          WSLOOP(p,q)
  65.  
  66.             {
  67.             if( c == *(q->pitem) )
  68.  
  69.                {
  70.                /* this item contributes to the goto */
  71.                putitem( q->pitem + 1, &q->ws );
  72.                q->flag = 1;
  73.                }
  74.             }
  75.          if( c < NTBASE ) 
  76.  
  77.             {
  78.             state(c);  /* register new state */
  79.             }
  80.          else 
  81.  
  82.             {
  83.             temp1[c-NTBASE] = state(c);
  84.             }
  85.          }
  86. #ifdef debug
  87.       if( foutput!=NULL )
  88.  
  89.          {
  90.          fprintf( foutput,  "%d: ", i );
  91.          NTLOOP(j) 
  92.  
  93.             {
  94.             if( temp1[j] ) fprintf( foutput,  "%s %d, ", nontrst[j].name, temp1[j] );
  95.             }
  96.          fprintf( foutput, "\n");
  97.          }
  98. #endif
  99.       indgo[i] = apack( &temp1[1], nnonter-1 ) - 1;
  100.       goto more; /* we have done one goto; do some more */
  101.       }
  102.    /* no more to do... stop */
  103.    }
  104.