home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OS2-YACC.ZIP / YSTAGN.1C < prev    next >
Text File  |  1989-09-29  |  3KB  |  124 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:      YSTAGN.1C
  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.  * ystagn.1c
  24.  *
  25.  * Modified to make debug code conditionally compile.
  26.  * 28-Aug-81
  27.  * Bob Denny
  28.  */
  29.  
  30. void stagen( void )
  31.  
  32.    {
  33.    /* generate the states */
  34.  
  35.    int i;
  36.    register c;
  37.    register struct wset *p, *q;
  38.  
  39.    /* initialize */
  40.  
  41.    nstate = 0;
  42.    /* THIS IS FUNNY from the standpoint of portability */
  43.    /* it represents the magic moment when the mem0 array, which has
  44.         /* been holding the productions, starts to hold item pointers, of a
  45.         /* different type... */
  46.    /* someday, alloc should be used to allocate all this stuff... for now, we
  47.         /* accept that if pointers don't fit in integers, there is a problem... */
  48.  
  49.    pstate[0] = pstate[1] = (struct item *)mem;
  50.    aryfil( clset.lset, tbitset, 0 );
  51.    putitem( prdptr[0]+1, &clset );
  52.    tystate[0] = MUSTDO;
  53.    nstate = 1;
  54.    pstate[2] = pstate[1];
  55.  
  56.    aryfil( amem, ACTSIZE, 0 );
  57.  
  58.    /* now, the main state generation loop */
  59.  
  60. more:
  61.    SLOOP(i)
  62.  
  63.       {
  64.       if( tystate[i] != MUSTDO ) continue;
  65.       tystate[i] = DONE;
  66.       aryfil( temp1, nnonter+1, 0 );
  67.       /* take state i, close it, and do gotos */
  68.       closure(i);
  69.       WSLOOP(wsets,p)
  70.  
  71.          {
  72.          /* generate goto's */
  73.          if( p->flag ) continue;
  74.          p->flag = 1;
  75.          c = *(p->pitem);
  76.          if( c <= 1 ) 
  77.  
  78.             {
  79.             if( pstate[i+1]-pstate[i] <= p-wsets ) tystate[i] = MUSTLOOKAHEAD;
  80.             continue;
  81.  
  82.             }
  83.          /* do a goto on c */
  84.          WSLOOP(p,q)
  85.  
  86.             {
  87.             if( c == *(q->pitem) )
  88.  
  89.                {
  90.                /* this item contributes to the goto */
  91.                putitem( q->pitem + 1, &q->ws );
  92.                q->flag = 1;
  93.                }
  94.             }
  95.          if( c < NTBASE ) 
  96.  
  97.             {
  98.             state(c);  /* register new state */
  99.             }
  100.          else 
  101.  
  102.             {
  103.             temp1[c-NTBASE] = state(c);
  104.             }
  105.          }
  106. #ifdef debug
  107.       if( foutput!=NULL )
  108.  
  109.          {
  110.          fprintf( foutput,  "%d: ", i );
  111.          NTLOOP(j) 
  112.  
  113.             {
  114.             if( temp1[j] ) fprintf( foutput,  "%s %d, ", nontrst[j].name, temp1[j] );
  115.             }
  116.          fprintf( foutput, "\n");
  117.          }
  118. #endif
  119.       indgo[i] = apack( &temp1[1], nnonter-1 ) - 1;
  120.       goto more; /* we have done one goto; do some more */
  121.       }
  122.    /* no more to do... stop */
  123.    }
  124.