home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
OS2-YACC.ZIP
/
YSTAGN.1C
< prev
next >
Wrap
Text File
|
1989-09-29
|
3KB
|
124 lines
/*
HEADER: CUG nnn.nn;
TITLE: YACC - Yet Another Compilier-Compilier
VERSION: 1.0 for IBM-PC
DATE: JAN 28, 1985
DESCRIPTION: LALR(1) Parser Generator. From UNIX
KEYWORDS: Parser Generator Compilier-Compilier YACC
SYSTEM: IBM-PC and Compatiables
FILENAME: YSTAGN.1C
WARNINGS: This program is not for the casual user. It will
be useful primarily to expert developers.
CRC: N/A
SEE-ALSO: LEX and PREP
AUTHORS: Scott Guthery 11100 leafwood lane Austin, TX 78750
COMPILERS: DESMET-C
REFERENCES: UNIX Systems Manuals
*/
#include "y1.h"
#include "y3.h"
/*
* ystagn.1c
*
* Modified to make debug code conditionally compile.
* 28-Aug-81
* Bob Denny
*/
void stagen( void )
{
/* generate the states */
int i;
register c;
register struct wset *p, *q;
/* initialize */
nstate = 0;
/* THIS IS FUNNY from the standpoint of portability */
/* it represents the magic moment when the mem0 array, which has
/* been holding the productions, starts to hold item pointers, of a
/* different type... */
/* someday, alloc should be used to allocate all this stuff... for now, we
/* accept that if pointers don't fit in integers, there is a problem... */
pstate[0] = pstate[1] = (struct item *)mem;
aryfil( clset.lset, tbitset, 0 );
putitem( prdptr[0]+1, &clset );
tystate[0] = MUSTDO;
nstate = 1;
pstate[2] = pstate[1];
aryfil( amem, ACTSIZE, 0 );
/* now, the main state generation loop */
more:
SLOOP(i)
{
if( tystate[i] != MUSTDO ) continue;
tystate[i] = DONE;
aryfil( temp1, nnonter+1, 0 );
/* take state i, close it, and do gotos */
closure(i);
WSLOOP(wsets,p)
{
/* generate goto's */
if( p->flag ) continue;
p->flag = 1;
c = *(p->pitem);
if( c <= 1 )
{
if( pstate[i+1]-pstate[i] <= p-wsets ) tystate[i] = MUSTLOOKAHEAD;
continue;
}
/* do a goto on c */
WSLOOP(p,q)
{
if( c == *(q->pitem) )
{
/* this item contributes to the goto */
putitem( q->pitem + 1, &q->ws );
q->flag = 1;
}
}
if( c < NTBASE )
{
state(c); /* register new state */
}
else
{
temp1[c-NTBASE] = state(c);
}
}
#ifdef debug
if( foutput!=NULL )
{
fprintf( foutput, "%d: ", i );
NTLOOP(j)
{
if( temp1[j] ) fprintf( foutput, "%s %d, ", nontrst[j].name, temp1[j] );
}
fprintf( foutput, "\n");
}
#endif
indgo[i] = apack( &temp1[1], nnonter-1 ) - 1;
goto more; /* we have done one goto; do some more */
}
/* no more to do... stop */
}