home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OS2-YACC.ZIP / YCPFIR.1C < prev    next >
Text File  |  1989-09-29  |  2KB  |  99 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:      YCPFIR.1C
  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.  
  21. /*
  22.  * ycpfir.1c
  23.  *
  24.  * Modified to make debug code conditionally compile.
  25.  * 28-Aug-81
  26.  * Bob Denny
  27.  */
  28.  
  29.  
  30. void cpfir( void )
  31.    {
  32.    /* compute an array with the first of nonterminals */
  33.    register *p, **s, i, **t, ch, changes;
  34.  
  35.    zzcwp = &wsets[nnonter];
  36.    NTLOOP(i)
  37.  
  38.       {
  39.       aryfil( wsets[i].ws.lset, tbitset, 0 );
  40.       t = pres[i+1];
  41.       for( s=pres[i]; s<t; ++s )
  42.  
  43.          {
  44.          /* initially fill the sets */
  45.          for( p = *s; (ch = *p) > 0 ; ++p ) 
  46.  
  47.             {
  48.             if( ch < NTBASE ) 
  49.  
  50.                {
  51.                SETBIT( wsets[i].ws.lset, ch );
  52.                break;
  53.                }
  54.             else if( !pempty[ch-NTBASE] ) break;
  55.             }
  56.          }
  57.       }
  58.  
  59.    /* now, reflect transitivity */
  60.  
  61.    changes = 1;
  62.    while( changes )
  63.  
  64.       {
  65.       changes = 0;
  66.       NTLOOP(i)
  67.  
  68.          {
  69.          t = pres[i+1];
  70.          for( s=pres[i]; s<t; ++s )
  71.  
  72.             {
  73.             for( p = *s; ( ch = (*p-NTBASE) ) >= 0; ++p ) 
  74.  
  75.                {
  76.                changes |= setunion( wsets[i].ws.lset, wsets[ch].ws.lset );
  77.                if( !pempty[ch] ) break;
  78.                }
  79.             }
  80.  
  81.          }
  82.       }
  83.  
  84.    NTLOOP(i) pfirst[i] = flset( &wsets[i].ws );
  85. #ifdef debug
  86.    if( (foutput!=NULL) )
  87.  
  88.       {
  89.       NTLOOP(i) 
  90.  
  91.          {
  92.          fprintf( foutput,  "\n%s: ", nontrst[i].name );
  93.          prlook( pfirst[i] );
  94.          fprintf( foutput,  " %d\n", pempty[i] );
  95.          }
  96.       }
  97. #endif
  98.    }
  99.