home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OS2-YACC.ZIP / YWSTAT.3C < prev    next >
Text File  |  1989-09-30  |  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:      YWSTAT.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 wrstate( int i )
  23.    {
  24.    /* writes state i */
  25.    register j0,j1;
  26.    register struct item *pp, *qq;
  27.    register struct wset *u;
  28.  
  29.    if( foutput == NULL ) return;
  30.    fprintf( foutput, "\nstate %d\n",i);
  31.    ITMLOOP(i,pp,qq) fprintf( foutput, "\t%s\n", writem(pp->pitem));
  32.    if( tystate[i] == MUSTLOOKAHEAD )
  33.       {
  34.       /* print out empty productions in closure */
  35.       WSLOOP( wsets+(pstate[i+1]-pstate[i]), u )
  36.          {
  37.          if( *(u->pitem) < 0 ) fprintf( foutput, "\t%s\n", writem(u->pitem) );
  38.          }
  39.       }
  40.  
  41.    /* check for state equal to another */
  42.  
  43.    TLOOP(j0) if( (j1=temp1[j0]) != 0 )
  44.       {
  45.       fprintf( foutput, "\n\t%s  ", symnam(j0) );
  46.       if( j1>0 )
  47.          {
  48.          /* shift, error, or accept */
  49.          if( j1 == ACCEPTCODE ) fprintf( foutput,  "accept" );
  50.          else if( j1 == ERRCODE ) fprintf( foutput, "error" );
  51.          else fprintf( foutput,  "shift %d", j1 );
  52.          }
  53.       else fprintf( foutput, "reduce %d",-j1 );
  54.       }
  55.  
  56.    /* output the final production */
  57.  
  58.    if( lastred ) fprintf( foutput, "\n\t.  reduce %d\n\n", lastred );
  59.    else fprintf( foutput, "\n\t.  error\n\n" );
  60.  
  61.    /* now, output nonterminal actions */
  62.  
  63.    j1 = ntokens;
  64.    for( j0 = 1; j0 <= nnonter; ++j0 )
  65.       {
  66.       if( temp1[++j1] ) fprintf( foutput, "\t%s  goto %d\n", symnam( j0+NTBASE), temp1[j1] );
  67.       }
  68.  
  69.    }
  70.  
  71. void wdef( char *s, int n )
  72.  
  73.    {
  74.    /* output a definition of s to the value n */
  75.    fprintf( ftable, "# define %s %d\n", s, n );
  76.    }
  77.