home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / program / c / yaccsrc2 / ystagn.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-19  |  2.7 KB  |  114 lines

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