home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OS2-YACC.ZIP / YG2OUT.3C < prev    next >
Text File  |  1989-09-29  |  2KB  |  77 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:      YG2OUT.3C
  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 "y3.h"
  20.  
  21. void go2out( void )
  22.    {
  23.    /* output the gotos for the nontermninals */
  24.    int i, j, k, best, count, cbest, times;
  25.  
  26.    fprintf( ftemp, "$\n" );  /* mark begining of gotos */
  27.  
  28.    for( i=1; i<=nnonter; ++i ) 
  29.       {
  30.       go2gen(i);
  31.  
  32.       /* find the best one to make default */
  33.  
  34.       best = -1;
  35.       times = 0;
  36.  
  37.       for( j=0; j<=nstate; ++j )
  38.          {
  39.          /* is j the most frequent */
  40.          if( tystate[j] == 0 ) continue;
  41.          if( tystate[j] == best ) continue;
  42.  
  43.          /* is tystate[j] the most frequent */
  44.  
  45.          count = 0;
  46.          cbest = tystate[j];
  47.  
  48.          for( k=j; k<=nstate; ++k ) if( tystate[k]==cbest ) ++count;
  49.  
  50.          if( count > times )
  51.             {
  52.             best = cbest;
  53.             times = count;
  54.             }
  55.          }
  56.  
  57.       /* best is now the default entry */
  58.  
  59.       zzgobest += (times-1);
  60.       for( j=0; j<=nstate; ++j )
  61.          {
  62.          if( tystate[j] != 0 && tystate[j]!=best )
  63.             {
  64.             fprintf( ftemp, "%d,%d,", j, tystate[j] );
  65.             zzgoent += 1;
  66.             }
  67.          }
  68.  
  69.       /* now, the default */
  70.  
  71.       zzgoent += 1;
  72.       fprintf( ftemp, "%d\n", best );
  73.  
  74.       }
  75.    }
  76.  
  77.