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

  1. /*
  2.  * 4-Dec-89 (MvL) Corrected (TC)-bug
  3.  */
  4.  
  5. # include "y4.h" 
  6.  
  7. void stin( i )
  8. {
  9.   register * r,
  10.            * s,
  11.              n,
  12.              flag,
  13.              j,
  14.            * q1,
  15.            * q2;
  16.  
  17.   greed[ i ] = 0;
  18.  
  19.   /* enter state i into the yyact array */
  20.  
  21.   q1 = mem0 + yypact[ i ];     /* these two statements switched */
  22.   q2 = mem0 + yypact[ i + 1 ]; /* ----------------------------- */
  23.   /* find an acceptable place */
  24.  
  25.   for ( n = -maxoff; n < ACTSIZE; ++n )
  26.     {
  27.  
  28.       flag    = 0;
  29.       for ( r = q1; r < q2; r += 2 )
  30.         {
  31.           if ( ( s = *r + n + yyact ) < yyact )
  32.             goto nextn;
  33.           if ( *s == 0 )
  34.             ++flag;
  35.           else
  36.             if ( *s != r[ 1 ] )
  37.               goto nextn;
  38.         }
  39.  
  40.       /* check that the position equals another only if the states are identical */
  41.  
  42.       for ( j = 0; j < nstate; ++j )
  43.         {
  44.           if ( pa[ j ] == n )
  45.             {
  46.               if ( flag )
  47.                 goto nextn; /* we have some disagreement */
  48.               if ( yypact[ j + 1 ] + yypact[ i ] == yypact[ j ] +
  49.                    yypact[ i + 1 ] )
  50.                 {
  51.                   /* states are equal */
  52.                   pa[ i ] = n;
  53.                   if ( adb > 1 )
  54.                     fprintf( ftable,
  55.                              "State %d: entry at %d equals state %d\n",
  56.                              i,
  57.                              n,
  58.                              j );
  59.                   return;
  60.                 }
  61.               goto nextn; /* we have some disagreement */
  62.             }
  63.         }
  64.  
  65.       for ( r = q1; r < q2; r += 2 )
  66.         {
  67.           if ( ( s = *r + n + yyact ) >= &yyact[ ACTSIZE ] )
  68.             error( "out of space in optimizer a array" );
  69.           if ( s > maxa )
  70.             maxa = s;
  71.           if ( *s != 0 && *s != r[ 1 ] )
  72.             error( "clobber of yyact array, pos'n %d, by %d",
  73.                    s - yyact,
  74.                    r[ 1 ] );
  75.           *s = r[ 1 ];
  76.         }
  77.       pa[ i ] = n;
  78.       if ( adb > 1 )
  79.         fprintf( ftable, "State %d: entry at %d\n", i, pa[ i ] );
  80.       return;
  81.  
  82.       nextn : ;
  83.     }
  84.  
  85.   error( "Error; failure to place state %d\n", i );
  86. }
  87.