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 / ygin.4c < prev    next >
Encoding:
Text File  |  1983-12-25  |  1.0 KB  |  55 lines

  1. #include "y4.h"
  2.  
  3. gin(i)
  4.    {
  5.  
  6.    register *p, *r, *s, *q1, *q2;
  7.  
  8.    /* enter gotos on nonterminal i into array a */
  9.  
  10.    ggreed[i] = 0;
  11.  
  12.    q2 = mem0+ yypgo[i+1] - 1;
  13.    q1 = mem0 + yypgo[i];
  14.  
  15.    /* now, find a place for it */
  16.  
  17.    for( p=a; p < &a[ACTSIZE]; ++p )
  18.       {
  19.       if( *p ) continue;
  20.       for( r=q1; r<q2; r+=2 )
  21.          {
  22.          s = p + *r +1;
  23.          if( *s ) goto nextgp;
  24.          if( s > maxa )
  25.             {
  26.             if( (maxa=s) > &a[ACTSIZE] ) error( "a array overflow" );
  27.             }
  28.          }
  29.       /* we have found a spot */
  30.  
  31.       *p = *q2;
  32.       if( p > maxa )
  33.          {
  34.          if( (maxa=p) > &a[ACTSIZE] ) error( "a array overflow" );
  35.          }
  36.       for( r=q1; r<q2; r+=2 )
  37.          {
  38.          s = p + *r + 1;
  39.          *s = r[1];
  40.          }
  41.  
  42.       pgo[i] = p-a;
  43.       if( adb>1 ) fprintf( ftable, "Nonterminal %d, entry at %d\n" , i, pgo[i] );
  44.       goto nextgi;
  45.  
  46. nextgp:  
  47.       ;
  48.       }
  49.  
  50.    error( "cannot place goto %d\n", i );
  51.  
  52. nextgi:  
  53.    ;
  54.    }
  55.