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

  1. #include "y3.h"
  2.  
  3. wrstate(i)
  4.    {
  5.    /* writes state i */
  6.    register j0,j1;
  7.    register struct item *pp, *qq;
  8.    register struct wset *u;
  9.  
  10.    if( foutput == NULL ) return;
  11.    fprintf( foutput, "\nstate %d\n",i);
  12.    ITMLOOP(i,pp,qq) fprintf( foutput, "\t%s\n", writem(pp->pitem));
  13.    if( tystate[i] == MUSTLOOKAHEAD )
  14.       {
  15.       /* print out empty productions in closure */
  16.       WSLOOP( wsets+(pstate[i+1]-pstate[i]), u )
  17.          {
  18.          if( *(u->pitem) < 0 ) fprintf( foutput, "\t%s\n", writem(u->pitem) );
  19.          }
  20.       }
  21.  
  22.    /* check for state equal to another */
  23.  
  24.    TLOOP(j0) if( (j1=temp1[j0]) != 0 )
  25.       {
  26.       fprintf( foutput, "\n\t%s  ", symnam(j0) );
  27.       if( j1>0 )
  28.          {
  29.          /* shift, error, or accept */
  30.          if( j1 == ACCEPTCODE ) fprintf( foutput,  "accept" );
  31.          else if( j1 == ERRCODE ) fprintf( foutput, "error" );
  32.          else fprintf( foutput,  "shift %d", j1 );
  33.          }
  34.       else fprintf( foutput, "reduce %d",-j1 );
  35.       }
  36.  
  37.    /* output the final production */
  38.  
  39.    if( lastred ) fprintf( foutput, "\n\t.  reduce %d\n\n", lastred );
  40.    else fprintf( foutput, "\n\t.  error\n\n" );
  41.  
  42.    /* now, output nonterminal actions */
  43.  
  44.    j1 = ntokens;
  45.    for( j0 = 1; j0 <= nnonter; ++j0 )
  46.       {
  47.       if( temp1[++j1] ) fprintf( foutput, "\t%s  goto %d\n", symnam( j0+NTBASE), temp1[j1] );
  48.       }
  49.  
  50.    }
  51.  
  52. wdef( s, n ) char *s; 
  53.  
  54.    {
  55.    /* output a definition of s to the value n */
  56.    fprintf( ftable, "# define %s %d\n", s, n );
  57.    }
  58.