home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OS2-YACC.ZIP / YG2GEN.3C < prev    next >
Text File  |  1989-09-30  |  2KB  |  108 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:      YG2GEN.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. /*
  23.  * yg2gen.3c
  24.  *
  25.  * Modified to make debug code conditionally compile.
  26.  * 28-Aug-81
  27.  * Bob Denny
  28.  */
  29.  
  30. void go2gen( int c )
  31.  
  32.    {
  33.    /* output the gotos for nonterminal c */
  34.  
  35.    int i, work, cc;
  36.    struct item *p, *q;
  37.  
  38.  
  39.    /* first, find nonterminals with gotos on c */
  40.  
  41.    aryfil( temp1, nnonter+1, 0 );
  42.    temp1[c] = 1;
  43.  
  44.    work = 1;
  45.    while( work )
  46.  
  47.       {
  48.       work = 0;
  49.       PLOOP(0,i)
  50.  
  51.          {
  52.          if( (cc=prdptr[i][1]-NTBASE) >= 0 )
  53.  
  54.             {
  55.             /* cc is a nonterminal */
  56.             if( temp1[cc] != 0 )
  57.  
  58.                {
  59.                /* cc has a goto on c */
  60.                cc = *prdptr[i]-NTBASE; /* thus, the left side of production i does too */
  61.                if( temp1[cc] == 0 )
  62.  
  63.                   {
  64.                   work = 1;
  65.                   temp1[cc] = 1;
  66.                   }
  67.                }
  68.             }
  69.          }
  70.       }
  71.  
  72.    /* now, we have temp1[c] = 1 if a goto on c in closure of cc */
  73.  
  74. #ifdef debug
  75.    if( foutput!=NULL )
  76.  
  77.       {
  78.       fprintf( foutput, "%s: gotos on ", nontrst[c].name );
  79.       NTLOOP(i) if( temp1[i] ) fprintf( foutput, "%s ", nontrst[i].name);
  80.       fprintf( foutput, "\n");
  81.  
  82.       }
  83. #endif
  84.    /* now, go through and put gotos into tystate */
  85.  
  86.    aryfil( tystate, nstate, 0 );
  87.    SLOOP(i)
  88.  
  89.       {
  90.       ITMLOOP(i,p,q)
  91.  
  92.          {
  93.          if( (cc= *p->pitem) >= NTBASE )
  94.  
  95.             {
  96.             if( temp1[cc -= NTBASE] )
  97.  
  98.                {
  99.                /* goto on c is possible */
  100.                tystate[i] = amem[indgo[i]+c];
  101.                break;
  102.                }
  103.             }
  104.          }
  105.       }
  106.    }
  107.  
  108.