home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OS2-YACC.ZIP / YOUTPT.3C < prev    next >
Text File  |  1989-09-30  |  3KB  |  101 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:      YOUTPT.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 "y1.h"
  20. #include "y3.h"
  21.  
  22. void output( void )
  23.    {
  24.    /* print the output for the states */
  25.  
  26.    int i, k, c;
  27.    register struct wset *u, *v;
  28.  
  29.    fprintf( ftable, "short yyexca[] ={\n" );
  30.  
  31.    SLOOP(i) 
  32.       {
  33.       /* output the stuff for state i */
  34.       nolook = !(tystate[i]==MUSTLOOKAHEAD);
  35.       closure(i);
  36.       /* output actions */
  37.       nolook = 1;
  38.       aryfil( temp1, ntokens+nnonter+1, 0 );
  39.       WSLOOP(wsets,u)
  40.          {
  41.          c = *( u->pitem );
  42.          if( c>1 && c<NTBASE && temp1[c]==0 ) 
  43.             {
  44.             WSLOOP(u,v)
  45.                {
  46.                if( c == *(v->pitem) ) putitem( v->pitem+1, (struct looksets *)0 );
  47.                }
  48.             temp1[c] = state(c);
  49.             }
  50.          else if( c > NTBASE && temp1[ (c -= NTBASE) + ntokens ] == 0 )
  51.             {
  52.             temp1[ c+ntokens ] = amem[indgo[i]+c];
  53.             }
  54.          }
  55.  
  56.       if( i == 1 ) temp1[1] = ACCEPTCODE;
  57.  
  58.       /* now, we have the shifts; look at the reductions */
  59.  
  60.       lastred = 0;
  61.       WSLOOP(wsets,u)
  62.          {
  63.          c = *( u->pitem );
  64.          if( c<=0 )
  65.             {
  66.             /* reduction */
  67.             lastred = -c;
  68.             TLOOP(k)
  69.                {
  70.                if( BIT(u->ws.lset,k) )
  71.                   {
  72.                   if( temp1[k] == 0 ) temp1[k] = c;
  73.                   else if( temp1[k]<0 )
  74.                      {
  75.                      /* reduce/reduce conflict */
  76.                      if( foutput!=NULL )
  77.                         fprintf( foutput,
  78.                         "\n%d: reduce/reduce conflict (red'ns %d and %d ) on %s",
  79.                         i, -temp1[k], lastred, symnam(k) );
  80.                      if( -temp1[k] > lastred ) temp1[k] = -lastred;
  81.  
  82.                      ++zzrrconf;
  83.                      }
  84.                   else 
  85.                      {
  86.                      /* potential shift/reduce conflict */
  87.                      precftn( lastred, k, i );
  88.                      }
  89.                   }
  90.                }
  91.             }
  92.          }
  93.       wract(i);
  94.       }
  95.  
  96.    fprintf( ftable, "\t};\n" );
  97.  
  98.    wdef( "YYNPROD", nprod );
  99.  
  100.    }
  101.