home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Professional
/
OS2PRO194.ISO
/
os2
/
prgramer
/
yacc
/
ystin.4c
< prev
next >
Wrap
Text File
|
1989-09-29
|
2KB
|
81 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: YSTIN.4C
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 "y4.h"
void stin( int i )
{
register *r, *s, n, flag, j, *q1, *q2;
greed[i] = 0;
/* enter state i into the a array */
q2 = mem0+yypact[i+1];
q1 = mem0+yypact[i];
/* find an acceptable place */
for( n= -maxoff; n<ACTSIZE; ++n )
{
flag = 0;
for( r = q1; r < q2; r += 2 )
{
if( (s = *r + n + a ) < a ) goto nextn;
if( *s == 0 ) ++flag;
else if( *s != r[1] ) goto nextn;
}
/* check that the position equals another only if the states are identical */
for( j=0; j<nstate; ++j )
{
if( pa[j] == n )
{
if( flag ) goto nextn; /* we have some disagreement */
if( yypact[j+1] + yypact[i] == yypact[j] + yypact[i+1] )
{
/* states are equal */
pa[i] = n;
if( adb>1 ) fprintf( ftable, "State %d: entry at %d equals state %d\n",
i, n, j );
return;
}
goto nextn; /* we have some disagreement */
}
}
for( r = q1; r < q2; r += 2 )
{
if( (s = *r + n + a ) >= &a[ACTSIZE] ) error( "out of space in optimizer a array" );
if( s > maxa ) maxa = s;
if( *s != 0 && *s != r[1] ) error( "clobber of a array, pos'n %d, by %d", s-a, r[1] );
*s = r[1];
}
pa[i] = n;
if( adb>1 ) fprintf( ftable, "State %d: entry at %d\n", i, pa[i] );
return;
nextn:
;
}
error( "Error; failure to place state %d\n", i );
}