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

  1. #include "y3.h"
  2.  
  3. output()
  4.    {
  5.    /* print the output for the states */
  6.  
  7.    int i, k, c;
  8.    register struct wset *u, *v;
  9.  
  10.    fprintf( ftable, "short yyexca[] ={\n" );
  11.  
  12.    SLOOP(i) 
  13.       {
  14.       /* output the stuff for state i */
  15.       nolook = !(tystate[i]==MUSTLOOKAHEAD);
  16.       closure(i);
  17.       /* output actions */
  18.       nolook = 1;
  19.       aryfil( temp1, ntokens+nnonter+1, 0 );
  20.       WSLOOP(wsets,u)
  21.          {
  22.          c = *( u->pitem );
  23.          if( c>1 && c<NTBASE && temp1[c]==0 ) 
  24.             {
  25.             WSLOOP(u,v)
  26.                {
  27.                if( c == *(v->pitem) ) putitem( v->pitem+1, (struct looksets *)0 );
  28.                }
  29.             temp1[c] = state(c);
  30.             }
  31.          else if( c > NTBASE && temp1[ (c -= NTBASE) + ntokens ] == 0 )
  32.             {
  33.             temp1[ c+ntokens ] = amem[indgo[i]+c];
  34.             }
  35.          }
  36.  
  37.       if( i == 1 ) temp1[1] = ACCEPTCODE;
  38.  
  39.       /* now, we have the shifts; look at the reductions */
  40.  
  41.       lastred = 0;
  42.       WSLOOP(wsets,u)
  43.          {
  44.          c = *( u->pitem );
  45.          if( c<=0 )
  46.             {
  47.             /* reduction */
  48.             lastred = -c;
  49.             TLOOP(k)
  50.                {
  51.                if( BIT(u->ws.lset,k) )
  52.                   {
  53.                   if( temp1[k] == 0 ) temp1[k] = c;
  54.                   else if( temp1[k]<0 )
  55.                      {
  56.                      /* reduce/reduce conflict */
  57.                      if( foutput!=NULL )
  58.                         fprintf( foutput,
  59.                         "\n%d: reduce/reduce conflict (red'ns %d and %d ) on %s",
  60.                         i, -temp1[k], lastred, symnam(k) );
  61.                      if( -temp1[k] > lastred ) temp1[k] = -lastred;
  62.                      ++zzrrconf;
  63.                      }
  64.                   else 
  65.                      {
  66.                      /* potential shift/reduce conflict */
  67.                      precftn( lastred, k, i );
  68.                      }
  69.                   }
  70.                }
  71.             }
  72.          }
  73.       wract(i);
  74.       }
  75.  
  76.    fprintf( ftable, "\t};\n" );
  77.  
  78.    wdef( "YYNPROD", nprod );
  79.  
  80.    }
  81.