home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OS2-YACC.ZIP / YSTIN.4C < prev    next >
Text File  |  1989-09-30  |  2KB  |  81 lines

  1. /*
  2.   HEADER: CUG     nnn.nn;
  3.   TITLE:     YACC - Yet Another Compilier-Compilier
  4.   VERSION:     1.0 for IBM-PC
  5.   DATE:      JAN 28, 1985
  6.   DESCRIPTION:     LALR(1) Parser Generator. From UNIX
  7.   KEYWORDS:     Parser Generator Compilier-Compilier YACC
  8.   SYSTEM:     IBM-PC and Compatiables
  9.   FILENAME:      YSTIN.4C
  10.   WARNINGS:     This program is not for the casual user. It will
  11.          be useful primarily to expert developers.
  12.   CRC:         N/A
  13.   SEE-ALSO:     LEX and PREP
  14.   AUTHORS:     Scott Guthery 11100 leafwood lane Austin, TX 78750
  15.   COMPILERS:     DESMET-C
  16.   REFERENCES:     UNIX Systems Manuals
  17. */
  18.  
  19. #include "y1.h"
  20. #include "y4.h"
  21.  
  22. void stin( int i )
  23.    {
  24.    register *r, *s, n, flag, j, *q1, *q2;
  25.  
  26.    greed[i] = 0;
  27.  
  28.    /* enter state i into the a array */
  29.  
  30.    q2 = mem0+yypact[i+1];
  31.    q1 = mem0+yypact[i];
  32.    /* find an acceptable place */
  33.  
  34.    for( n= -maxoff; n<ACTSIZE; ++n )
  35.       {
  36.  
  37.       flag = 0;
  38.       for( r = q1; r < q2; r += 2 )
  39.          {
  40.          if( (s = *r + n + a ) < a ) goto nextn;
  41.          if( *s == 0 ) ++flag;
  42.          else if( *s != r[1] ) goto nextn;
  43.          }
  44.  
  45.       /* check that the position equals another only if the states are identical */
  46.  
  47.       for( j=0; j<nstate; ++j )
  48.          {
  49.          if( pa[j] == n ) 
  50.             {
  51.             if( flag ) goto nextn;  /* we have some disagreement */
  52.             if( yypact[j+1] + yypact[i] == yypact[j] + yypact[i+1] )
  53.                {
  54.                /* states are equal */
  55.                pa[i] = n;
  56.                if( adb>1 ) fprintf( ftable, "State %d: entry at %d equals state %d\n",
  57.                i, n, j );
  58.                return;
  59.                }
  60.             goto nextn;  /* we have some disagreement */
  61.             }
  62.          }
  63.  
  64.       for( r = q1; r < q2; r += 2 )
  65.          {
  66.          if( (s = *r + n + a ) >= &a[ACTSIZE] ) error( "out of space in optimizer a array" );
  67.          if( s > maxa ) maxa = s;
  68.          if( *s != 0 && *s != r[1] ) error( "clobber of a array, pos'n %d, by %d", s-a, r[1] );
  69.          *s = r[1];
  70.          }
  71.       pa[i] = n;
  72.       if( adb>1 ) fprintf( ftable, "State %d: entry at %d\n", i, pa[i] );
  73.       return;
  74.  
  75. nextn:  
  76.       ;
  77.       }
  78.  
  79.    error( "Error; failure to place state %d\n", i );
  80.    }
  81.