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.             }
  64.          /* do a goto on c */
  65.          WSLOOP(p,q)
  66.  
  67.             {
  68.             if( c == *(q->pitem) )
  69.  
  70.                {
  71.                /* this item contributes to the goto */
  72.                putitem( q->pitem + 1, &q->ws );
  73.                q->flag = 1;
  74.                }
  75.             }
  76.          if( c < NTBASE ) 
  77.  
  78.             {
  79.             state(c);  /* register new state */
  80.             }
  81.          else 
  82.  
  83.             {
  84.             temp1[c-NTBASE] = state(c);
  85.             }
  86.          }
  87. #ifdef debug
  88.       if( foutput!=NULL )
  89.  
  90.          {
  91.          fprintf( foutput,  "%d: ", i );
  92.          NTLOOP(j) 
  93.  
  94.             {
  95.             if( temp1[j] ) fprintf( foutput,  "%s %d, ", nontrst[j].name, temp1[j] );
  96.             }
  97.          fprintf( foutput, "\n");
  98.          }
  99. #endif
  100.       indgo[i] = apack( &temp1[1], nnonter-1 ) - 1;
  101.       goto more; /* we have done one goto; do some more */
  102.       }
  103.    /* no more to do... stop */
  104.    }
  105.