home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / yacc / ywract.3c < prev    next >
Text File  |  1989-09-29  |  3KB  |  102 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:      YWRACT.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 wract( int i )
  22.    {
  23.    /* output state i */
  24.    /* temp1 has the actions, lastred the default */
  25.    int p, p0, p1;
  26.    int ntimes, tred, count, j;
  27.    int flag;
  28.  
  29.    /* find the best choice for lastred */
  30.  
  31.    lastred = 0;
  32.    ntimes = 0;
  33.    TLOOP(j)
  34.       {
  35.       if( temp1[j] >= 0 ) continue;
  36.       if( temp1[j]+lastred == 0 ) continue;
  37.       /* count the number of appearances of temp1[j] */
  38.       count = 0;
  39.       tred = -temp1[j];
  40.       levprd[tred] |= REDFLAG;
  41.       TLOOP(p)
  42.          {
  43.          if( temp1[p]+tred == 0 ) ++count;
  44.          }
  45.       if( count >ntimes )
  46.          {
  47.          lastred = tred;
  48.          ntimes = count;
  49.          }
  50.       }
  51.  
  52.    /* for error recovery, arrange that, if there is a shift on the
  53.         /* error recovery token, `error', that the default be the error action */
  54.    if( temp1[1] > 0 ) lastred = 0;
  55.  
  56.    /* clear out entries in temp1 which equal lastred */
  57.    TLOOP(p) if( temp1[p]+lastred == 0 )temp1[p]=0;
  58.  
  59.    wrstate(i);
  60.    defact[i] = lastred;
  61.  
  62.    flag = 0;
  63.    TLOOP(p0)
  64.       {
  65.       if( (p1=temp1[p0])!=0 ) 
  66.          {
  67.          if( p1 < 0 )
  68.             {
  69.             p1 = -p1;
  70.             goto exc;
  71.             }
  72.          else if( p1 == ACCEPTCODE ) 
  73.             {
  74.             p1 = -1;
  75.             goto exc;
  76.             }
  77.          else if( p1 == ERRCODE ) 
  78.             {
  79.             p1 = 0;
  80.             goto exc;
  81.  
  82. exc:
  83.             if( flag++ == 0 ) fprintf( ftable, "-1, %d,\n", i );
  84.             fprintf( ftable, "\t%d, %d,\n", tokset[p0].value, p1 );
  85.             ++zzexcp;
  86.             }
  87.          else 
  88.             {
  89.             fprintf( ftemp, "%d,%d,", tokset[p0].value, p1 );
  90.             ++zzacent;
  91.             }
  92.          }
  93.       }
  94.    if( flag ) 
  95.       {
  96.       defact[i] = -2;
  97.       fprintf( ftable, "\t-2, %d,\n", lastred );
  98.       }
  99.    fprintf( ftemp, "\n" );
  100.    return;
  101.    }
  102.