home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / alde_c / misc / comm / yaccunx / ywract.3c < prev    next >
Encoding:
Text File  |  1983-12-24  |  1.9 KB  |  83 lines

  1. #include "y3.h"
  2.  
  3. wract(i)
  4.    {
  5.    /* output state i */
  6.    /* temp1 has the actions, lastred the default */
  7.    int p, p0, p1;
  8.    int ntimes, tred, count, j;
  9.    int flag;
  10.  
  11.    /* find the best choice for lastred */
  12.  
  13.    lastred = 0;
  14.    ntimes = 0;
  15.    TLOOP(j)
  16.       {
  17.       if( temp1[j] >= 0 ) continue;
  18.       if( temp1[j]+lastred == 0 ) continue;
  19.       /* count the number of appearances of temp1[j] */
  20.       count = 0;
  21.       tred = -temp1[j];
  22.       levprd[tred] |= REDFLAG;
  23.       TLOOP(p)
  24.          {
  25.          if( temp1[p]+tred == 0 ) ++count;
  26.          }
  27.       if( count >ntimes )
  28.          {
  29.          lastred = tred;
  30.          ntimes = count;
  31.          }
  32.       }
  33.  
  34.    /* for error recovery, arrange that, if there is a shift on the
  35.         /* error recovery token, `error', that the default be the error action */
  36.    if( temp1[1] > 0 ) lastred = 0;
  37.  
  38.    /* clear out entries in temp1 which equal lastred */
  39.    TLOOP(p) if( temp1[p]+lastred == 0 )temp1[p]=0;
  40.  
  41.    wrstate(i);
  42.    defact[i] = lastred;
  43.  
  44.    flag = 0;
  45.    TLOOP(p0)
  46.       {
  47.       if( (p1=temp1[p0])!=0 ) 
  48.          {
  49.          if( p1 < 0 )
  50.             {
  51.             p1 = -p1;
  52.             goto exc;
  53.             }
  54.          else if( p1 == ACCEPTCODE ) 
  55.             {
  56.             p1 = -1;
  57.             goto exc;
  58.             }
  59.          else if( p1 == ERRCODE ) 
  60.             {
  61.             p1 = 0;
  62.             goto exc;
  63. exc:
  64.             if( flag++ == 0 ) fprintf( ftable, "-1, %d,\n", i );
  65.             fprintf( ftable, "\t%d, %d,\n", tokset[p0].value, p1 );
  66.             ++zzexcp;
  67.             }
  68.          else 
  69.             {
  70.             fprintf( ftemp, "%d,%d,", tokset[p0].value, p1 );
  71.             ++zzacent;
  72.             }
  73.          }
  74.       }
  75.    if( flag ) 
  76.       {
  77.       defact[i] = -2;
  78.       fprintf( ftable, "\t-2, %d,\n", lastred );
  79.       }
  80.    fprintf( ftemp, "\n" );
  81.    return;
  82.    }
  83.