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

  1.  
  2. # include "y3.h" 
  3.  
  4. void wract( i )
  5. {
  6.   /* output state i */
  7.   /* temp1 has the actions, lastred the default */
  8.   int p,
  9.       p0,
  10.       p1;
  11.   int ntimes,
  12.       tred,
  13.       count,
  14.       j;
  15.   int flag;
  16.  
  17.   /* find the best choice for lastred */
  18.  
  19.   lastred     = 0;
  20.   ntimes      = 0;
  21.   TLOOP( j )
  22.     {
  23.       if ( temp1[ j ] >= 0 )
  24.         continue ;
  25.       if ( temp1[ j ] + lastred == 0 )
  26.         continue ;
  27.         /* count the number of appearances of temp1[j] */
  28.       count = 0;
  29.       tred  = -temp1[ j ];
  30.       levprd[ tred ] |= REDFLAG;
  31.       TLOOP( p )
  32.         {
  33.           if ( temp1[ p ] + tred == 0 )
  34.             ++count;
  35.         }
  36.       if ( count > ntimes )
  37.         {
  38.           lastred = tred;
  39.           ntimes  = count;
  40.         }
  41.     }
  42.  
  43.   /* for error recovery, arrange that, if there is a shift on the
  44.      error recovery token, `error', that the default be the error action
  45.   */
  46.   if ( temp1[ 1 ] > 0 )
  47.     lastred = 0;
  48.  
  49.     /* clear out entries in temp1 which equal lastred */
  50.   TLOOP( p )
  51.     if ( temp1[ p ] + lastred == 0 )
  52.       temp1[ p ] = 0;
  53.  
  54.   wrstate( i );
  55.   defact[ i ] = lastred;
  56.  
  57.   flag        = 0;
  58.   TLOOP( p0 )
  59.     {
  60.       if ( ( p1 = temp1[ p0 ] ) != 0 )
  61.         {
  62.           if ( p1 < 0 )
  63.             {
  64.               p1 = -p1;
  65.               goto exc;
  66.             }
  67.           else
  68.             if ( p1 == ACCEPTCODE )
  69.               {
  70.                 p1 = -1;
  71.                 goto exc;
  72.               }
  73.             else
  74.               if ( p1 == ERRCODE )
  75.                 {
  76.                   p1 = 0;
  77.                   goto exc;
  78.                   exc : if ( flag++ == 0 )
  79.                     fprintf( ftable, "-1, %d,\n", i );
  80.                   fprintf( ftable,
  81.                            "\t%d, %d,\n",
  82.                            tokset[ p0 ].value,
  83.                            p1 );
  84.                   ++zzexcp;
  85.                 }
  86.               else
  87.                 {
  88.                   fprintf( ftemp, "%d,%d,", tokset[ p0 ].value, p1 );
  89.                   ++zzacent;
  90.                 }
  91.         }
  92.     }
  93.   if ( flag )
  94.     {
  95.       defact[ i ] = -2;
  96.       fprintf( ftable, "\t-2, %d,\n", lastred );
  97.     }
  98.   fprintf( ftemp, "\n" );
  99.   return;
  100. }
  101.