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

  1.  
  2. # include "y3.h" 
  3.  
  4. /*
  5.  * yg2gen.3c
  6.  *
  7.  * Modified to make debug code conditionally compile.
  8.  * 28-Aug-81
  9.  * Bob Denny
  10.  */
  11.  
  12. void go2gen( c )
  13.  
  14.  
  15. {
  16.   /* output the gotos for nonterminal c */
  17.  
  18.   int           i,
  19.                 work,
  20.                 cc;
  21.   struct item * p,
  22.               * q;
  23.  
  24.  
  25.   /* first, find nonterminals with gotos on c */
  26.  
  27.   aryfil( temp1, nnonter + 1, 0 );
  28.   temp1[ c ] = 1;
  29.  
  30.   work       = 1;
  31.   while ( work )
  32.  
  33.     {
  34.       work = 0;
  35.       PLOOP( 0, i )
  36.  
  37.         {
  38.           if ( ( cc = prdptr[ i ][ 1 ] - NTBASE ) >= 0 )
  39.  
  40.             {
  41.               /* cc is a nonterminal */
  42.               if ( temp1[ cc ] != 0 )
  43.  
  44.                 {
  45.                   /* cc has a goto on c */
  46.                   cc = *prdptr[ i ] - NTBASE; /* thus, the left side of production i does too */
  47.                   if ( temp1[ cc ] == 0 )
  48.  
  49.                     {
  50.                       work        = 1;
  51.                       temp1[ cc ] = 1;
  52.                     }
  53.                 }
  54.             }
  55.         }
  56.     }
  57.  
  58.   /* now, we have temp1[c] = 1 if a goto on c in closure of cc */
  59.  
  60.   # ifdef debug
  61.   if ( foutput != NULL )
  62.  
  63.     {
  64.       fprintf( foutput, "%s: gotos on ", nontrst[ c ].name );
  65.       NTLOOP( i )
  66.         if ( temp1[ i ] )
  67.           fprintf( foutput, "%s ", nontrst[ i ].name );
  68.       fprintf( foutput, "\n" );
  69.     }
  70.     # endif 
  71.     /* now, go through and put gotos into tystate */
  72.  
  73.   aryfil( tystate, nstate, 0 );
  74.   SLOOP( i )
  75.  
  76.     {
  77.       ITMLOOP( i, p, q )
  78.  
  79.         {
  80.           if ( ( cc = *p->pitem ) >= NTBASE )
  81.  
  82.             {
  83.               if ( temp1[ cc -= NTBASE ] )
  84.  
  85.                 {
  86.                   /* goto on c is possible */
  87.                   tystate[ i ] = amem[ indgo[ i ] + c ];
  88.                   break ;
  89.                 }
  90.             }
  91.         }
  92.     }
  93. }
  94.  
  95.