home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / alde_c / misc / comm / yaccunx / ystin.4c < prev    next >
Encoding:
Text File  |  1983-12-25  |  1.6 KB  |  62 lines

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