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

  1. #include "y3.h"
  2.  
  3. go2out()
  4.    {
  5.    /* output the gotos for the nontermninals */
  6.    int i, j, k, best, count, cbest, times;
  7.  
  8.    fprintf( ftemp, "$\n" );  /* mark begining of gotos */
  9.  
  10.    for( i=1; i<=nnonter; ++i ) 
  11.       {
  12.       go2gen(i);
  13.  
  14.       /* find the best one to make default */
  15.  
  16.       best = -1;
  17.       times = 0;
  18.  
  19.       for( j=0; j<=nstate; ++j )
  20.          {
  21.          /* is j the most frequent */
  22.          if( tystate[j] == 0 ) continue;
  23.          if( tystate[j] == best ) continue;
  24.  
  25.          /* is tystate[j] the most frequent */
  26.  
  27.          count = 0;
  28.          cbest = tystate[j];
  29.  
  30.          for( k=j; k<=nstate; ++k ) if( tystate[k]==cbest ) ++count;
  31.  
  32.          if( count > times )
  33.             {
  34.             best = cbest;
  35.             times = count;
  36.             }
  37.          }
  38.  
  39.       /* best is now the default entry */
  40.  
  41.       zzgobest += (times-1);
  42.       for( j=0; j<=nstate; ++j )
  43.          {
  44.          if( tystate[j] != 0 && tystate[j]!=best )
  45.             {
  46.             fprintf( ftemp, "%d,%d,", j, tystate[j] );
  47.             zzgoent += 1;
  48.             }
  49.          }
  50.  
  51.       /* now, the default */
  52.  
  53.       zzgoent += 1;
  54.       fprintf( ftemp, "%d\n", best );
  55.  
  56.       }
  57.    }
  58.  
  59.