home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / YACCUNX.ZIP / YCPFIR.1C < prev    next >
Encoding:
Text File  |  1983-12-23  |  1.5 KB  |  81 lines

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