home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / program / c / yaccsrc2 / yg2out.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-19  |  1.4 KB  |  70 lines

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