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

  1.  
  2. # include "y1.h" 
  3.  
  4. /*
  5.  * ycpfir.1c
  6.  *
  7.  * Modified to make debug code conditionally compile.
  8.  * 28-Aug-81
  9.  * Bob Denny
  10.  */
  11.  
  12.  
  13. void cpfir( )
  14.  
  15.  
  16.  
  17. {
  18.   /* compute an array with the first of nonterminals */
  19.   register * p,
  20.          * * s,
  21.              i,
  22.          * * t,
  23.              ch,
  24.              changes;
  25.  
  26.   zzcwp   = &wsets[ nnonter ];
  27.   NTLOOP( i )
  28.  
  29.     {
  30.       aryfil( wsets[ i ].ws.lset, tbitset, 0 );
  31.       t = pres[ i + 1 ];
  32.       for ( s = pres[ i ]; s < t; ++s )
  33.  
  34.         {
  35.           /* initially fill the sets */
  36.           for ( p = *s; ( ch = *p ) > 0; ++p )
  37.  
  38.             {
  39.               if ( ch < NTBASE )
  40.  
  41.                 {
  42.                   SETBIT( wsets[ i ].ws.lset, ch );
  43.                   break ;
  44.                 }
  45.               else
  46.                 if ( !pempty[ ch - NTBASE ] )
  47.                   break ;
  48.             }
  49.         }
  50.     }
  51.  
  52.   /* now, reflect transitivity */
  53.  
  54.   changes = 1;
  55.   while ( changes )
  56.  
  57.     {
  58.       changes = 0;
  59.       NTLOOP( i )
  60.  
  61.         {
  62.           t = pres[ i + 1 ];
  63.           for ( s = pres[ i ]; s < t; ++s )
  64.  
  65.             {
  66.               for ( p = *s; ( ch = ( *p - NTBASE ) ) >= 0; ++p )
  67.  
  68.                 {
  69.                   changes |= setunion( wsets[ i ].ws.lset,
  70.                                        wsets[ ch ].ws.lset );
  71.                   if ( !pempty[ ch ] )
  72.                     break ;
  73.                 }
  74.             }
  75.         }
  76.     }
  77.  
  78.   NTLOOP( i )
  79.     pfirst[ i ] = flset( &wsets[ i ].ws );
  80.   # ifdef debug
  81.   if ( ( foutput != NULL ) )
  82.  
  83.     {
  84.       NTLOOP( i )
  85.  
  86.         {
  87.           fprintf( foutput, "\n%s: ", nontrst[ i ].name );
  88.           prlook( pfirst[ i ] );
  89.           fprintf( foutput, " %d\n", pempty[ i ] );
  90.         }
  91.     }
  92.     # endif 
  93. }
  94.