home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / alde_c / misc / comm / yaccunx / yg2gen.3c < prev    next >
Encoding:
Text File  |  1983-12-23  |  1.6 KB  |  88 lines

  1. #include "y3.h"
  2.  
  3. /*
  4.  * yg2gen.3c
  5.  *
  6.  * Modified to make debug code conditionally compile.
  7.  * 28-Aug-81
  8.  * Bob Denny
  9.  */
  10.  
  11. go2gen(c)
  12.  
  13.    {
  14.    /* output the gotos for nonterminal c */
  15.  
  16.    int i, work, cc;
  17.    struct item *p, *q;
  18.  
  19.  
  20.    /* first, find nonterminals with gotos on c */
  21.  
  22.    aryfil( temp1, nnonter+1, 0 );
  23.    temp1[c] = 1;
  24.  
  25.    work = 1;
  26.    while( work )
  27.  
  28.       {
  29.       work = 0;
  30.       PLOOP(0,i)
  31.  
  32.          {
  33.          if( (cc=prdptr[i][1]-NTBASE) >= 0 )
  34.  
  35.             {
  36.             /* cc is a nonterminal */
  37.             if( temp1[cc] != 0 )
  38.  
  39.                {
  40.                /* cc has a goto on c */
  41.                cc = *prdptr[i]-NTBASE; /* thus, the left side of production i does too */
  42.                if( temp1[cc] == 0 )
  43.  
  44.                   {
  45.                   work = 1;
  46.                   temp1[cc] = 1;
  47.                   }
  48.                }
  49.             }
  50.          }
  51.       }
  52.  
  53.    /* now, we have temp1[c] = 1 if a goto on c in closure of cc */
  54.  
  55. #ifdef debug
  56.    if( foutput!=NULL )
  57.  
  58.       {
  59.       fprintf( foutput, "%s: gotos on ", nontrst[c].name );
  60.       NTLOOP(i) if( temp1[i] ) fprintf( foutput, "%s ", nontrst[i].name);
  61.       fprintf( foutput, "\n");
  62.  
  63.       }
  64. #endif
  65.    /* now, go through and put gotos into tystate */
  66.  
  67.    aryfil( tystate, nstate, 0 );
  68.    SLOOP(i)
  69.  
  70.       {
  71.       ITMLOOP(i,p,q)
  72.  
  73.          {
  74.          if( (cc= *p->pitem) >= NTBASE )
  75.  
  76.             {
  77.             if( temp1[cc -= NTBASE] )
  78.  
  79.                {
  80.                /* goto on c is possible */
  81.                tystate[i] = amem[indgo[i]+c];
  82.                break;
  83.                }
  84.             }
  85.          }
  86.       }
  87.    }
  88.  
  89.