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

  1.  
  2. # include "y3.h" 
  3.  
  4. void wrstate( i )
  5. {
  6.   /* writes state i */
  7.   register               j0,
  8.                          j1;
  9.   register struct item * pp,
  10.                        * qq;
  11.   register struct wset * u;
  12.  
  13.   if ( foutput == NULL )
  14.     return;
  15.   fprintf( foutput, "\nstate %d\n", i );
  16.   ITMLOOP( i, pp, qq )
  17.     {
  18.       fprintf( foutput, "\t%s\n", writem( pp->pitem ) );
  19.     }
  20.   if ( tystate[ i ] == MUSTLOOKAHEAD )
  21.     {
  22.       /* print out empty productions in closure */
  23.       WSLOOP( wsets + ( pstate[ i + 1 ] - pstate[ i ] ), u )
  24.         {
  25.           if ( *( u->pitem ) < 0 )
  26.             fprintf( foutput, "\t%s\n", writem( u->pitem ) );
  27.         }
  28.     }
  29.  
  30.     /* check for state equal to another */
  31.  
  32.   TLOOP( j0 )
  33.     if ( ( j1 = temp1[ j0 ] ) != 0 )
  34.       {
  35.         fprintf( foutput, "\n\t%s  ", symnam( j0 ) );
  36.         if ( j1 > 0 )
  37.           {
  38.             /* shift, error, or accept */
  39.             if ( j1 == ACCEPTCODE )
  40.               fprintf( foutput, "accept" );
  41.             else
  42.               if ( j1 == ERRCODE )
  43.                 fprintf( foutput, "error" );
  44.               else
  45.                 fprintf( foutput, "shift %d", j1 );
  46.           }
  47.         else
  48.           fprintf( foutput, "reduce %d", -j1 );
  49.       }
  50.  
  51.       /* output the final production */
  52.  
  53.   if ( lastred )
  54.     fprintf( foutput, "\n\t.  reduce %d\n\n", lastred );
  55.   else
  56.     fprintf( foutput, "\n\t.  error\n\n" );
  57.  
  58.   /* now, output nonterminal actions */
  59.  
  60.   j1 = ntokens;
  61.   for ( j0 = 1; j0 <= nnonter; ++j0 )
  62.     {
  63.       if ( temp1[ ++j1 ] )
  64.         fprintf( foutput,
  65.                  "\t%s  goto %d\n",
  66.                  symnam( j0 + NTBASE ),
  67.                  temp1[ j1 ] );
  68.     }
  69.  
  70. }
  71.  
  72. void wdef( s, n )
  73. char * s;
  74.  
  75. {
  76.   /* output a definition of s to the value n */
  77.   fprintf( ftable, "# define %s %d\n", s, n );
  78. }
  79.