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

  1.  
  2. # include "y3.h" 
  3.  
  4. void output( )
  5. {
  6.   /* print the output for the states */
  7.  
  8.   int                    i,
  9.                          k,
  10.                          c;
  11.   register struct wset * u,
  12.                        * v;
  13.  
  14.   fprintf( ftable, "short yyexca[] ={\n" );
  15.  
  16.   SLOOP( i )
  17.     {
  18.       /* output the stuff for state i */
  19.       nolook  = !( tystate[ i ] == MUSTLOOKAHEAD );
  20.       closure( i );
  21.       /* output actions */
  22.       nolook  = 1;
  23.       aryfil( temp1, ntokens + nnonter + 1, 0 );
  24.       WSLOOP( wsets, u )
  25.         {
  26.           c = *( u->pitem );
  27.           if ( c > 1 && c < NTBASE && temp1[ c ] == 0 )
  28.             {
  29.               WSLOOP( u, v )
  30.                 {
  31.                   if ( c == *( v->pitem ) )
  32.                     putitem( v->pitem + 1, ( struct looksets * )0 );
  33.                 }
  34.               temp1[ c ] = state( c );
  35.             }
  36.           else
  37.             if ( c > NTBASE && temp1[ ( c -= NTBASE ) + ntokens ] == 0 )
  38.               {
  39.                 temp1[ c + ntokens ] = amem[ indgo[ i ] + c ];
  40.               }
  41.         }
  42.  
  43.       if ( i == 1 )
  44.         temp1[ 1 ] = ACCEPTCODE;
  45.  
  46.         /* now, we have the shifts; look at the reductions */
  47.  
  48.       lastred = 0;
  49.       WSLOOP( wsets, u )
  50.         {
  51.           c = *( u->pitem );
  52.           if ( c <= 0 )
  53.             {
  54.               /* reduction */
  55.               lastred = -c;
  56.               TLOOP( k )
  57.                 {
  58.                   if ( BIT( u->ws.lset, k ) )
  59.                     {
  60.                       if ( temp1[ k ] == 0 )
  61.                         temp1[ k ] = c;
  62.                       else
  63.                         if ( temp1[ k ] < 0 )
  64.                           {
  65.                             /* reduce/reduce conflict */
  66.                             if ( foutput != NULL )
  67.                               {
  68.                                 fprintf( foutput,
  69.                                          "\n%d: reduce/reduce conflict (red'ns %d and %d ) on %s",
  70.                                          i,
  71.                                          -temp1[ k ],
  72.                                          lastred,
  73.                                          symnam( k ) );
  74.                               }
  75.                             if ( -temp1[ k ] > lastred )
  76.                               temp1[ k ] = -lastred;
  77.                             ++zzrrconf;
  78.                           }
  79.                         else
  80.                           {
  81.                             /* potential shift/reduce conflict */
  82.                             precftn( lastred, k, i );
  83.                           }
  84.                     }
  85.                 }
  86.             }
  87.         }
  88.       wract( i );
  89.     }
  90.  
  91.   fprintf( ftable, "\t};\n" );
  92.  
  93.   wdef( "YYNPROD", nprod );
  94.  
  95. }
  96.