[net.sources] Public Domain YACC

mark@ems.UUCP (02/01/87)

	Here is a copy of the Public Domain YACC that I promised earlier.
	For those of you who sent me mail, if you still need me to email
	you a copy, please let me know, otherwise I will assume that you
	have pulled it off of the net.

	This version runs on System V and MS-DOS.  I have not been able
	to get access to a BSD machine to test it there.

	Please send any bug reports, fixes, enhancements, comments or 
	suggestions to me so that they can be included in any later 
	releases or patches.

	Have fun.

	Mark H. Colburn          mark@ems.uucp      
	EMS/McGraw-Hill          {rutgers|amdahl|ihnp4}!meccts!ems!mark
	9855 West 78th Street     
	Eden Prairie, MN 55344   (612) 829-8200 x235

---------------------------------- CUT HERE ----------------------------------
#! /bin/sh
# This is a shell archive (part 1 of 2), meaning:
# 1.  Remove everything above the #! /bin/sh line.
# 2.  Save the resulting text in a file.
# 3.  Execute the file with /bin/sh (not csh).
#
#     The following files will be created:
#		ysetup.c
#		dtxtrn.h
#		yypars.c
#		ygttok.c
#		ycpact.c
#		yclsur.c
#		yclopt.c
#		y1imp.c
#		y2.h
#		ystagn.c
#		ycemty.c
#		ystate.c
#		Makefile
#		y1.h
#		yywrap.c
#
# Created by mark@ems (Mark H. Colburn) on Sun Feb  1 01:20:11 1987
#
if test -f 'ysetup.c'
then
echo shar: will not over-write existing "'ysetup.c'"
else
echo extracting "'ysetup.c'"
sed 's/^X//' >ysetup.c <<'SHAR_EOF'
X/*
X * YSETUP.C  -- Modified for use with DECUS LEX
X *              Variable "yylval" resides in yylex(), not in yypars();
X *              Therefore, is defined "extern" here.
X *
X *              Also, the command line processing for the Decus version
X *              has been changed.  A new switch has been added to allow
X *              specification of the "table" file name(s), and unused
X *              switch processing removed.
X *
X *                               NOTE
X *              This probably won't run on UNIX any more.
X *
X * Bob Denny 27-Aug-81
X * Bob Denny 22-Mar-82 (01) Added header line, changes for 'new' DECUS library
X * Bob Denny 12-Apr-83 (02) Make filename[] size per #define'd FNAMESIZE so
X *                          VAX filenames won't blow out.  Conditionalize
X *                          time handling for banner.  Make filespec buffer
X *                          static for safety, since global "infile" is
X *                          pointed to it.
X * Scott Guthery 15-May-83  (03) Fixed up option flag handling for RT-11
X *			 23-Dec-83  Adapted for IBM PC/XT & DeSmet C compiler
X */
X
X#include "y2.h"
X
Xstatic char	filename[FNAMESIZE];
X
Xint	i, j, lev, t, ty;
Xint	c;
Xint	tempty;
Xint	*p;
Xint	defsw, infsw;
Xchar	actname[8];
Xchar	*cp;
X
Xsetup(argc, argv)
Xint	argc;
Xchar	*argv[];
X{
X	char	finsave[FNAMESIZE];
X
X	defsw = infsw = 0;
X	foutput = NULL;
X	fdefine = NULL;
X	i = 1;                                               /*(03)*/
X	while ( argc > 1 && argv[i][0] == '-' )               /*(03)*/ {
X		while ( *++(argv[i]) ) {
X			switch ( *argv[i] ) {
X			case 'i':
X			case 'I':
X				infsw++;
X				continue;
X			case 'h':
X			case 'H':
X				defsw++;
X				continue;
X			default:
X				fprintf(stderr, "Illegal option: %c\n", *argv[i]);
X				usage();
X			}
X		}
X		i++;                                              /*(03)*/
X		argc--;
X	}
X
X	if (argc < 2) 
X		usage();               /* Catch no filename given */
X
X	/*
X * Now open the input file with a default extension of ".Y",
X * then replace the period in argv[1] with a null, so argv[1]
X * can be used to form the table, defs and info filenames.
X */
X
X	cp = argv[i];
X	while (*cp++ != '.' && *cp != '\0')
X		; /* Scan past '.' or to null */
X	if (*cp == '\0') {
X		strcpy(filename, argv[i]); 
X		strcat(filename, ".Y");
X	} else
X	 {
X		strcpy(filename, argv[i]);
X		*(argv[i] - 1) = '\0';             /* Null the period */
X	}
X
X	strcpy(finsave, filename);
X	if ((finput = fopen( filename, "r" )) == NULL )
X		error( "cannot open input file \"%s\"", filename );
X
X	/*
X * Now open the .H and .I files if requested.
X */
X
X	if (defsw) {
X		strcpy(filename, argv[i]); 
X		strcat(filename, ".H");
X		fdefine = fopen(filename, "w");
X		if (fdefine == NULL) 
X			error("cannot open defs file\"%s\"", filename);
X	}
X
X	if (infsw) {
X		strcpy(filename, argv[i]); 
X		strcat(filename, ".I");
X		foutput = fopen(filename, "w");
X		if (foutput == NULL) 
X			error("cannot open info file\"%s\"", filename);
X	}
X	/*
X * Now the "table" output C file.
X */
X	strcpy(filename, argv[i]); 
X	strcat(filename, ".C");
X	ftable = fopen(filename, "w");
X	if ( ftable == NULL ) 
X		error( "cannot open table file\"%s\"", filename);
X	/*
X * Finally, the temp files.
X */
X	ftemp = fopen( TEMPNAME, "w" );
X	if ( ftemp == NULL ) 
X		error( "cannot open temp file" );
X	faction = fopen( ACTNAME, "w" );
X	if ( faction == NULL ) 
X		error( "cannot open action file" );
X	/*
X * Now put the full filename of the input file into
X * the "filename" buffer for cpyact(), and point the
X * global cell "infile" at it.
X */
X	strcpy(filename, finsave);
X	infile = filename;
X	/*
X * Put out a header line at the beginning of the 'table' file.
X */
X	fprintf(ftable, "/*\n * Created by CSD YACC from \"%s\"\n */\n",
X	    infile);
X	/*
X * Complete  initialization.
X */
X	cnamp = cnames;
X	defin(0, "$end");
X	extval = 0400;
X	defin(0, "error");
X	defin(1, "$accept");
X	mem = mem0;
X	lev = 0;
X	ty = 0;
X	i = 0;
X
X	yyparse();
X}
X
X
Xyyparse()
X{
X	/* sorry -- no yacc parser here.....
X                we must bootstrap somehow... */
X
X	for ( t = gettok(); t != MARK && t != ENDFILE; ) {
X		switch ( t ) {
X
X		case ';':
X			t = gettok();
X			break;
X
X		case START:
X			if ( (t = gettok()) != IDENTIFIER ) {
X				error( "bad %%start construction" );
X			}
X			start = chfind(1, tokname);
X			t = gettok();
X			continue;
X
X		case TYPEDEF:
X			if ( (t = gettok()) != TYPENAME ) 
X				error( "bad syntax in %%type" );
X			ty = numbval;
X			for (; ; ) {
X				t = gettok();
X				switch ( t ) {
X
X				case IDENTIFIER:
X					if ( (t = chfind( 1, tokname ) ) < NTBASE ) {
X						j = TYPE( toklev[t] );
X						if ( j != 0 && j != ty ) {
X							error( "type redeclaration of token %s",
X							    tokset[t].name );
X						} else 
X							SETTYPE( toklev[t], ty);
X					} else
X					 {
X						j = nontrst[t-NTBASE].tvalue;
X						if ( j != 0 && j != ty ) {
X							error( "type redeclaration of nonterminal %s",
X							    nontrst[t-NTBASE].name );
X						} else 
X							nontrst[t-NTBASE].tvalue = ty;
X					}
X				case ',':
X					continue;
X
X				case ';':
X					t = gettok();
X					break;
X				default:
X					break;
X				}
X				break;
X			}
X			continue;
X
X		case UNION:
X			/* copy the union declaration to the output */
X			cpyunion();
X			t = gettok();
X			continue;
X
X		case LEFT:
X		case BINARY:
X		case RIGHT:
X			++i;
X		case TERM:
X			lev = t - TERM;  /* nonzero means new prec. and assoc. */
X			ty = 0;
X
X			/* get identifiers so defined */
X
X			t = gettok();
X			if ( t == TYPENAME ) {
X				/* there is a type defined */
X				ty = numbval;
X				t = gettok();
X			}
X			for (; ; ) {
X				switch ( t ) {
X
X				case ',':
X					t = gettok();
X					continue;
X
X				case ';':
X					break;
X
X				case IDENTIFIER:
X					j = chfind(0, tokname);
X					if ( lev ) {
X						if ( ASSOC(toklev[j]) ) 
X							error( "redeclaration of precedence of%s", tokname );
X						SETASC(toklev[j], lev);
X						SETPLEV(toklev[j], i);
X					}
X					if ( ty ) {
X						if ( TYPE(toklev[j]) ) 
X							error( "redeclaration of type of %s", tokname );
X						SETTYPE(toklev[j], ty);
X					}
X					if ( (t = gettok()) == NUMBER ) {
X						tokset[j].value = numbval;
X						if ( j < ndefout && j > 2 ) {
X							error( "please define type number of %s earlier",
X							    tokset[j].name );
X						}
X						t = gettok();
X					}
X					continue;
X
X				}
X
X				break;
X			}
X
X			continue;
X
X		case LCURLY:
X			defout();
X			cpycode();
X			t = gettok();
X			continue;
X
X		default:
X			printf("Unrecognized character: %o\n", t);
X			error( "syntax error" );
X
X		}
X
X	}
X
X	if ( t == ENDFILE ) {
X		error( "unexpected EOF before %%" );
X	}
X	/* t is MARK */
X
X	defout();
X
X	fprintf( ftable, "#define yyclearin yychar = -1\n" );
X	fprintf( ftable, "#define yyerrok yyerrflag = 0\n" );
X	/*
X   fprintf( ftable,"extern int yychar;\nextern short yyerrflag;\n" );
X*/
X	fprintf( ftable, "#ifndef YYMAXDEPTH\n#define YYMAXDEPTH 150\n#endif\n" );
X	if (!ntypes)
X		fprintf( ftable,  "#ifndef YYSTYPE\n#define YYSTYPE int\n#endif\n" );
X#ifdef unix
X	fprintf( ftable,  "YYSTYPE yylval, yyval;\n" );
X#else
X	fprintf( ftable, "extern YYSTYPE yylval;  /*CSD & DECUS LEX */\n");
X	fprintf( ftable, "YYSTYPE yyval;          /*CSD & DECUS LEX */\n");
X#endif
X	prdptr[0] = mem;
X	/* added production */
X	*mem++ = NTBASE;
X	*mem++ = start;  /* if start is 0, we will overwrite with the lhs of the firstrule */
X	*mem++ = 1;
X	*mem++ = 0;
X	prdptr[1] = mem;
X	while ( (t = gettok()) == LCURLY ) 
X		cpycode();
X	if ( t != C_IDENTIFIER ) 
X		error( "bad syntax on first rule" );
X	if ( !start ) 
X		prdptr[0][1] = chfind(1, tokname);
X
X	/* read rules */
X
X	while ( t != MARK && t != ENDFILE ) {
X
X		/* process a rule */
X
X		if ( t == '|' ) {
X			*mem++ = *prdptr[nprod-1];
X		} else if ( t == C_IDENTIFIER ) {
X			*mem = chfind(1, tokname);
X			if ( *mem < NTBASE ) 
X				error( "token illegal on LHS of grammar rule" );
X			++mem;
X		} else 
X			error( "illegal rule: missing semicolon or | ?" );
X
X		/* read rule body */
X		t = gettok();
Xmore_rule:
X		while ( t == IDENTIFIER ) {
X			*mem = chfind(1, tokname);
X			if ( *mem < NTBASE ) 
X				levprd[nprod] = toklev[*mem];
X			++mem;
X			t = gettok();
X		}
X		if ( t == PREC ) {
X			if ( gettok() != IDENTIFIER) 
X				error( "illegal %%prec syntax" );
X			j = chfind(2, tokname);
X			if ( j >= NTBASE)
X				error("nonterminal %s illegal after %%prec", nontrst[j-NTBASE].name);
X			levprd[nprod] = toklev[j];
X			t = gettok();
X		}
X		if ( t == '=' ) {
X			levprd[nprod] |= ACTFLAG;
X			fprintf( faction, "\ncase %d:", nprod );
X			cpyact( mem - prdptr[nprod] - 1 );
X			fprintf( faction, " break;" );
X			if ( (t = gettok()) == IDENTIFIER ) {
X				/* action within rule... */
X				sprintf( actname, "$$%d", nprod );
X				j = chfind(1, actname);  /* make it a nonterminal */
X				/* the current rule will become rule number nprod+1 */
X				/* move the contents down, and make room for the null */
X				for ( p = mem; p >= prdptr[nprod]; --p ) 
X					p[2] = *p;
X				mem += 2;
X				/* enter null production for action */
X				p = prdptr[nprod];
X				*p++ = j;
X				*p++ = -nprod;
X
X				/* update the production information */
X				levprd[nprod+1] = levprd[nprod] & ~ACTFLAG;
X				levprd[nprod] = ACTFLAG;
X
X				if ( ++nprod >= NPROD ) 
X					error( "more than %d rules", NPROD );
X				prdptr[nprod] = p;
X
X				/* make the action appear in the original rule */
X				*mem++ = j;
X
X				/* get some more of the rule */
X
X				goto more_rule;
X			}
X
X		}
X
X		while ( t == ';' ) 
X			t = gettok();
X
X		*mem++ = -nprod;
X
X		/* check that default action is reasonable */
X
X		if ( ntypes && !(levprd[nprod] & ACTFLAG) && nontrst[*prdptr[nprod]-NTBASE].tvalue ) {
X			/* no explicit action, LHS has value */
X			/*01*/
X			tempty = prdptr[nprod][1];
X			if ( tempty < 0 ) 
X				error( "must return a value, since LHS has a type" );
X			else if ( tempty >= NTBASE ) 
X				tempty = nontrst[tempty-NTBASE].tvalue;
X			else 
X				tempty = TYPE( toklev[tempty] );
X			if ( tempty != nontrst[*prdptr[nprod]-NTBASE].tvalue ) {
X				error( "default action causes potential type clash" );
X			}
X		}
X		if ( ++nprod >= NPROD ) 
X			error( "more than %d rules", NPROD );
X		prdptr[nprod] = mem;
X		levprd[nprod] = 0;
X	}
X	/* end of all rules */
X	fprintf(faction, "/* End of actions */"); /* Properly terminate the last line */
X	finact();
X	if ( t == MARK ) {
X		fprintf( ftable, "\n#line %d\n", lineno );
X		while ( (c = unix_getc(finput)) != EOF ) 
X			putc( c, ftable );
X	}
X	fclose( finput );
X}
X
X
Xusage()
X
X{
X	fprintf(stderr, "UNIX YACC (CSD Variant):\n");
X	fprintf(stderr, "   yacc -hi infile\n\n");
X	fprintf(stderr, "Switches:\n");
X	fprintf(stderr, "   -h   Create definitions header file\n");
X	fprintf(stderr, "   -i   Create parser description file\n\n");
X	fprintf(stderr, "Default input file extension is \".Y\"\n");
X	fprintf(stderr, "Defs file same name, \".H\" extension.\n");
X	fprintf(stderr, "Info file same name, \".I\" extension.\n");
X	exit(EX_ERR);
X}
X
X
SHAR_EOF
if test 10666 -ne "`wc -c < 'ysetup.c'`"
then
echo shar: error transmitting "'ysetup.c'" '(should have been 10666 characters)'
fi
chmod 644 ysetup.c
fi
if test -f 'dtxtrn.h'
then
echo shar: will not over-write existing "'dtxtrn.h'"
else
echo extracting "'dtxtrn.h'"
sed 's/^X//' >dtxtrn.h <<'SHAR_EOF'
X/*
X * DTXTRN.H  -- Original extern file for UNIX YACC.
X *
X * Modified to call in "decus" or "vax11c" .H files to set up
X * parameters as appropriate.
X */
X
X#include <stdio.h>
X#include "system.h"
X
X/*  MANIFEST CONSTANT DEFINITIONS */
X
X/* base of nonterminal internal numbers */
X#define NTBASE 010000
X
X/* internal codes for error and accept actions */
X
X#define ERRCODE  8190
X#define ACCEPTCODE 8191
X
X/* sizes and limits */
X
X#ifdef HUGETAB
X#define ACTSIZE 12000
X#define MEMSIZE 12000
X#define NSTATES 750
X#define NTERMS 127
X#define NPROD 600
X#define NNONTERM 300
X#define TEMPSIZE 1200
X#define CNAMSZ 5000
X#define LSETSIZE 600
X#define WSETSIZE 350
X#endif
X
X#ifdef MEDTAB
X#define ACTSIZE 4000
X#define MEMSIZE 5200
X#define NSTATES 600
X#define NTERMS 127
X#define NPROD 400
X#define NNONTERM 200
X#define TEMPSIZE 800
X#define CNAMSZ 5000
X#define LSETSIZE 450
X#define WSETSIZE 250
X#endif
X
X#ifdef SMALLTAB
X#define ACTSIZE 1000
X#define MEMSIZE 1500
X#define NSTATES 450
X#define NTERMS 127
X#define NPROD 200
X#define NNONTERM 100
X#define TEMPSIZE 600
X#define CNAMSZ 5000
X#define LSETSIZE 200
X#define WSETSIZE 125
X#endif
X
X#define NAMESIZE 50
X#define NTYPES 63
X
X#ifdef WORD32
X#define TBITSET ((32+NTERMS)/32)
X
X/* bit packing macros (may be machine dependent) */
X#define BIT(a,i) ((a)[(i)>>5] & (1<<((i)&037)))
X#define SETBIT(a,i) ((a)[(i)>>5] |= (1<<((i)&037)))
X
X/* number of words needed to hold n+1 bits */
X#define NWORDS(n) (((n)+32)/32)
X
X#else
X
X#define TBITSET ((16+NTERMS)/16)
X
X/* bit packing macros (may be machine dependent) */
X#define BIT(a,i) ((a)[(i)>>4] & (1<<((i)&017)))
X#define SETBIT(a,i) ((a)[(i)>>4] |= (1<<((i)&017)))
X
X/* number of words needed to hold n+1 bits */
X#define NWORDS(n) (((n)+16)/16)
X#endif
X
X/* relationships which must hold:
X        TBITSET ints must hold NTERMS+1 bits...
X        WSETSIZE >= NNONTERM
X        LSETSIZE >= NNONTERM
X        TEMPSIZE >= NTERMS + NNONTERMs + 1
X        TEMPSIZE >= NSTATES
X        */
X
X/* associativities */
X
X#define NOASC 0  /* no assoc. */
X#define LASC 1  /* left assoc. */
X#define RASC 2  /* right assoc. */
X#define BASC 3  /* binary assoc. */
X
X/* flags for state generation */
X
X#define DONE 0
X#define MUSTDO 1
X#define MUSTLOOKAHEAD 2
X
X/* flags for a rule having an action, and being reduced */
X
X#define ACTFLAG 04
X#define REDFLAG 010
X
X/* output parser flags */
X#define YYFLAG1 (-1000)
X
X/* macros for getting associativity and precedence levels */
X
X#define ASSOC(i) ((i)&03)
X#define PLEVEL(i) (((i)>>4)&077)
X#define TYPE(i)  ((i>>10)&077)
X
X/* macros for setting associativity and precedence levels */
X
X#define SETASC(i,j) i|=j
X#define SETPLEV(i,j) i |= (j<<4)
X#define SETTYPE(i,j) i |= (j<<10)
X
X/* looping macros */
X
X#define TLOOP(i) for(i=1;i<=ntokens;++i)
X#define NTLOOP(i) for(i=0;i<=nnonter;++i)
X#define PLOOP(s,i) for(i=s;i<nprod;++i)
X#define SLOOP(i) for(i=0;i<nstate;++i)
X#define WSBUMP(x) ++x
X#define WSLOOP(s,j) for(j=s;j<cwp;++j)
X#define ITMLOOP(i,p,q) q=pstate[i+1];for(p=pstate[i];p<q;++p)
X#define SETLOOP(i) for(i=0;i<tbitset;++i)
X
X/* I/O descriptors */
X
X#ifndef y2imp
Xextern FILE *finput;           /* input file */
Xextern FILE *faction;          /* file for saving actions */
Xextern FILE *fdefine;           /* file for #defines */
Xextern FILE *ftable;           /* y.tab.c file */
Xextern FILE *ftemp;            /* tempfile to pass 2 */
Xextern FILE *foutput;          /* y.output file */
X#endif
X
X/* structure declarations */
X
Xstruct looksets {
X	int	lset[TBITSET];
X};
X
Xstruct item {
X	int	*pitem;
X	struct looksets *look;
X};
X
Xstruct toksymb {
X	char	*name;
X	int	value;
X};
X
Xstruct ntsymb {
X	char	*name;
X	int	tvalue;
X};
X
Xstruct wset {
X	int	*pitem;
X	int	flag;
X	struct looksets ws;
X};
X
X#ifndef y2imp
X/* token information */
Xextern int	ntokens ;    /* number of tokens */
Xextern struct toksymb tokset[];
Xextern int	toklev[];    /* vector with the precedence of the terminals */
X#endif
X
X/* nonterminal information */
X
X#ifndef y2imp
Xextern int	nnonter ;    /* the number of nonterminals */
Xextern struct ntsymb nontrst[];
X#endif
X
X/* grammar rule information */
X#ifndef y2imp
Xextern int	nprod ;      /* number of productions */
Xextern int	*prdptr[];   /* pointers to descriptions of productions */
Xextern int	levprd[] ;   /* contains production levels to break conflicts */
X#endif
X
X/* state information */
X
X#ifndef y1imp
Xextern int	nstate ;             /* number of states */
Xextern struct item *pstate[];   /* pointers to the descriptions of the states */
Xextern int	tystate[];   /* contains type information about the states */
X#ifndef y3imp
Xextern int	defact[];    /* the default action of the state */
X#endif
Xextern int	tstates[];   /* the states deriving each token */
Xextern int	ntstates[];  /* the states deriving each nonterminal */
Xextern int	mstates[];   /* the continuation of the chains begun in tstates and ntstates */
X#endif
X
X/* lookahead set information */
X
X#ifndef y1imp
Xextern struct looksets lkst[];
Xextern int	nolook;  /* flag to turn off lookahead computations */
X#endif
X
X/* working set information */
X
X#ifndef y1imp
Xextern struct wset wsets[];
Xextern struct wset *cwp;
X#endif
X
X/* storage for productions */
X#ifndef y2imp
Xextern int	mem0[];
Xextern int	*mem;
X#endif
X
X/* storage for action table */
X
X#ifndef y1imp
Xextern int	amem[];  /* action table storage */
Xextern int	*memp ;              /* next free action table position */
Xextern int	indgo[];             /* index to the stored goto table */
X
X/* temporary vector, indexable by states, terms, or ntokens */
X
Xextern int	temp1[];
Xextern int	lineno; /* current line number */
X
X/* statistics collection variables */
X
Xextern int	zzgoent ;
Xextern int	zzgobest ;
Xextern int	zzacent ;
Xextern int	zzexcp ;
Xextern int	zzclose ;
Xextern int	zzrrconf ;
Xextern int	zzsrconf ;
X#endif
X
X/* define functions with strange types... */
Xextern char	*cstash();
Xextern struct looksets *flset();
Xextern char	*symnam();
Xextern char	*writem();
X
X/* default settings for a number of macros */
X
X#define ISIZE 400       /* Specific for static in cpres() */
X
X/* name of yacc tempfiles */
X
X#ifndef TEMPNAME
X#define TEMPNAME "yacc.tmp"
X#endif
X
X#ifndef ACTNAME
X#define ACTNAME "yacc.act"
X#endif
X
X/* output file name */
X
X#ifndef OFILE
X#define OFILE "ytab.c"
X#endif
X
X/* user output file name */
X
X#ifndef FILEU
X#define FILEU "y.out"
X#endif
X
X/* output file for #defines */
X
X#ifndef FILED
X#define FILED "ytab.h"
X#endif
X
X/* Size of complete filespec */
X#ifndef FNAMESIZE
X#define FNAMESIZE 32
X#endif
X
X/* command to clobber tempfiles after use */
X
X#ifndef ZAPFILE
X#define ZAPFILE(x) unlink(x)
X#endif
SHAR_EOF
if test 6477 -ne "`wc -c < 'dtxtrn.h'`"
then
echo shar: error transmitting "'dtxtrn.h'" '(should have been 6477 characters)'
fi
chmod 644 dtxtrn.h
fi
if test -f 'yypars.c'
then
echo shar: will not over-write existing "'yypars.c'"
else
echo extracting "'yypars.c'"
sed 's/^X//' >yypars.c <<'SHAR_EOF'
X# define YYFLAG -1000
X# define YYERROR goto yyerrlab
X# define YYACCEPT return(0)
X# define YYABORT return(1)
X
X/*      parser for yacc output  */
X
Xint	yydebug = 0; /* 1 for debugging */
XYYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */
Xint	yychar = -1; /* current input token number */
Xint	yynerrs = 0;  /* number of errors */
Xshort	yyerrflag = 0;  /* error recovery flag */
X
Xyyparse()
X{
X
X	short	yys[YYMAXDEPTH];
X	short	yyj, yym;
X	register YYSTYPE *yypvt;
X	register short	yystate, *yyps, yyn;
X	register YYSTYPE *yypv;
X	register short	*yyxi;
X
X	yystate = 0;
X	yychar = -1;
X	yynerrs = 0;
X	yyerrflag = 0;
X	yyps = &yys[-1];
X	yypv = &yyv[-1];
X
Xyystack:    /* put a state and value onto the stack */
X
X	if ( yydebug  ) 
X		printf( "state %d, char 0%o\n", yystate, yychar );
X	if ( ++yyps > &yys[YYMAXDEPTH] ) {
X		yyerror( "yacc stack overflow" );
X		return(1);
X	}
X	*yyps = yystate;
X	++yypv;
X#ifdef UNION
X	yyunion(yypv, &yyval);
X#else
X	*yypv = yyval;
X#endif
Xyynewstate:
X
X	yyn = yypact[yystate];
X
X	if ( yyn <= YYFLAG ) 
X		goto yydefault; /* simple state */
X
X	if ( yychar < 0 ) 
X		if ( (yychar = yylex()) < 0 ) 
X			yychar = 0;
X	if ( (yyn += yychar) < 0 || yyn >= YYLAST ) 
X		goto yydefault;
X
X	if ( yychk[ yyn=yyact[ yyn ] ] == yychar ) {
X		/* valid shift */
X		yychar = -1;
X#ifdef UNION
X		yyunion(&yyval, &yylval);
X#else
X		yyval = yylval;
X#endif
X		yystate = yyn;
X		if ( yyerrflag > 0 ) 
X			--yyerrflag;
X		goto yystack;
X	}
Xyydefault:
X	/* default state action */
X
X	if ( (yyn = yydef[yystate]) == -2 ) {
X		if ( yychar < 0 ) 
X			if ( (yychar = yylex()) < 0 ) 
X				yychar = 0;
X		/* look through exception table */
X
X		for ( yyxi = yyexca; (*yyxi != (-1)) || (yyxi[1] != yystate) ; yyxi += 2 ) 
X			; /* VOID */
X
X		for (yyxi += 2; *yyxi >= 0; yyxi += 2) {
X			if ( *yyxi == yychar ) 
X				break;
X		}
X		if ( (yyn = yyxi[1]) < 0 ) 
X			return(0);   /* accept */
X	}
X
X	if ( yyn == 0 ) {
X		/* error */
X		/* error ... attempt to resume parsing */
X
X		switch ( yyerrflag ) {
X
X		case 0:   /* brand new error */
X
X			yyerror( "syntax error" );
Xyyerrlab:
X			++yynerrs;
X
X		case 1:
X		case 2: /* incompletely recovered error ... try again */
X
X			yyerrflag = 3;
X
X			/* find a state where "error" is a legal shift action */
X
X			while ( yyps >= yys ) {
X				yyn = yypact[*yyps] + YYERRCODE;
X				if ( yyn >= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ) {
X					yystate = yyact[yyn];  /* simulate a shift of "error" */
X					goto yystack;
X				}
X				yyn = yypact[*yyps];
X
X				/* the current yyps has no shift onn "error", pop stack */
X
X				if ( yydebug ) 
X					printf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] );
X				--yyps;
X				--yypv;
X			}
X
X			/* there is no state on the stack with an error shift ... abort */
X
Xyyabort:
X			return(1);
X
X
X		case 3:  /* no shift yet; clobber input char */
X			if ( yydebug ) 
X				printf( "error recovery discards char %d\n", yychar );
X
X			if ( yychar == 0 ) 
X				goto yyabort; /* don't discard EOF, quit */
X			yychar = -1;
X			goto yynewstate;   /* try again in the same state */
X
X		}
X
X	}
X
X	/* reduction by production yyn */
X
X	if ( yydebug ) 
X		printf("reduce %d\n", yyn);
X	yyps -= yyr2[yyn];
X	yypvt = yypv;
X	yypv -= yyr2[yyn];
X#ifdef UNION
X	yyunion(&yyval, &yypv[1]);
X#else
X	yyval = yypv[1];
X#endif
X	yym = yyn;
X	/* consult goto table to find next state */
X	yyn = yyr1[yyn];
X	yyj = yypgo[yyn] + *yyps + 1;
X	if ( yyj >= YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) 
X		yystate = yyact[yypgo[yyn]];
X	switch (yym) {
X		$A
X	}
X	goto yystack;  /* stack new state and value */
X
X}
X
X
SHAR_EOF
if test 3496 -ne "`wc -c < 'yypars.c'`"
then
echo shar: error transmitting "'yypars.c'" '(should have been 3496 characters)'
fi
chmod 644 yypars.c
fi
if test -f 'ygttok.c'
then
echo shar: will not over-write existing "'ygttok.c'"
else
echo extracting "'ygttok.c'"
sed 's/^X//' >ygttok.c <<'SHAR_EOF'
X/*
X * ygttok.c -
X *
X * HISTORY
X */
X
X#include <ctype.h>
X#include "y2.h"
X
Xextern int	peekline; /* number of '\n' seen in lookahead */
X
Xint	gettok()
X{
X	register i, base;
X	register c, match, reserve;
X
Xbegin:
X	reserve = 0;
X	lineno += peekline;
X	peekline = 0;
X	c = unix_getc(finput);
X	while (c == ' ' || c == '\n' || c == '\t' || c == '\f' || c == '\r') {
X		if (c == '\n')
X			++lineno;
X		c = unix_getc(finput);
X	}
X	if (c == '/') {
X		/* skip comment */
X		lineno += skipcom();
X		goto begin;
X	}
X	switch (c) {
X
X	case -1:		/* EOF */
X		return (ENDFILE);
X	case '{':
X		ungetc(c, finput);
X		return ('=');	/* action ... */
X	case '<':		/* get, and look up, a type name (union
X						 * member name) */
X		i = 0;
X		while ((c = unix_getc(finput)) != '>' && c >= 0 && c != '\n') {
X			tokname[i] = c;
X			if (++i >= NAMESIZE)
X				--i;
X		}
X		if (c != '>')
X			error("unterminated < ... > clause");
X		tokname[i] = '\0';
X		for (i = 1; i <= ntypes; ++i) {
X			if (!strcmp(typeset[i], tokname)) {
X				numbval = i;
X				return (TYPENAME);
X			}
X		}
X		typeset[numbval = ++ntypes] = cstash(tokname);
X		return (TYPENAME);
X
X	case '"':
X	case '\'':
X		match = c;
X		tokname[0] = ' ';
X		i = 1;
X		for (; ; ) {
X			c = unix_getc(finput);
X			if (c == '\n' || c == EOF)
X				error("illegal or missing ' or \"");
X			if (c == '\\') {
X				c = unix_getc(finput);
X				tokname[i] = '\\';
X				if (++i >= NAMESIZE)
X					--i;
X			} else if (c == match)
X				break;
X			tokname[i] = c;
X			if (++i >= NAMESIZE)
X				--i;
X		}
X		break;
X
X	case '%':
X	case '\\':
X
X		switch (c = unix_getc(finput)) {
X
X		case '0':
X			return (TERM);
X		case '<':
X			return (LEFT);
X		case '2':
X			return (BINARY);
X		case '>':
X			return (RIGHT);
X		case '%':
X		case '\\':
X			return (MARK);
X		case '=':
X			return (PREC);
X		case '{':
X			return (LCURLY);
X		default:
X			reserve = 1;
X		}
X
X	default:
X
X		if (isdigit(c)) {
X			/* number */
X			numbval = c - '0';
X			base = (c == '0') ? 8 : 10;
X			for (c = unix_getc(finput); isdigit(c); c = getc(finput)) {
X				numbval = numbval * base + c - '0';
X			}
X			ungetc(c, finput);
X			return (NUMBER);
X		} else if (islower(c) || isupper(c) || c == '_' || c == '.' || c == '$') {
X			i = 0;
X			while (islower(c) || isupper(c) || isdigit(c) || c == '_' || c == '.' || c == '$') {
X				tokname[i] = c;
X				if (reserve && isupper(c))
X					tokname[i] += 'a' - 'A';
X				if (++i >= NAMESIZE)
X					--i;
X				c = unix_getc(finput);
X			}
X		} else
X			return (c);
X
X		ungetc(c, finput);
X	}
X
X	tokname[i] = '\0';
X
X	if (reserve) {
X		/* find a reserved word */
X		if (!strcmp(tokname, "term"))
X			return (TERM);
X		if (!strcmp(tokname, "token"))
X			return (TERM);
X		if (!strcmp(tokname, "left"))
X			return (LEFT);
X		if (!strcmp(tokname, "nonassoc"))
X			return (BINARY);
X		if (!strcmp(tokname, "binary"))
X			return (BINARY);
X		if (!strcmp(tokname, "right"))
X			return (RIGHT);
X		if (!strcmp(tokname, "prec"))
X			return (PREC);
X		if (!strcmp(tokname, "start"))
X			return (START);
X		if (!strcmp(tokname, "type"))
X			return (TYPEDEF);
X		if (!strcmp(tokname, "union"))
X			return (UNION);
X		error("invalid escape, or illegal reserved word: %s", tokname);
X	}
X	/* look ahead to distinguish IDENTIFIER from C_IDENTIFIER */
X
X	c = unix_getc(finput);
X	while (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '/') {
X		if (c == '\n')
X			++peekline;
X		else if (c == '/') {
X			/* look for comments */
X			peekline += skipcom();
X		}
X		c = unix_getc(finput);
X	}
X	if (c == ':')
X		return (C_IDENTIFIER);
X	ungetc(c, finput);
X	return (IDENTIFIER);
X}
X
X
SHAR_EOF
if test 3453 -ne "`wc -c < 'ygttok.c'`"
then
echo shar: error transmitting "'ygttok.c'" '(should have been 3453 characters)'
fi
chmod 644 ygttok.c
fi
if test -f 'ycpact.c'
then
echo shar: will not over-write existing "'ycpact.c'"
else
echo extracting "'ycpact.c'"
sed 's/^X//' >ycpact.c <<'SHAR_EOF'
X/*
X * ycpact.c - copy C action to next ; or closing curly brace
X *
X * HISTORY
X */
X
X#include <stdio.h>
X#include <ctype.h>
X#include "y2.h"
X
Xint	cpyact(offset)
Xint	offset;
X{
X	int	brac, c, match, j, s, tok;
X
X	fprintf(faction, "\n# line %d\n", lineno);
X	brac = 0;
X
Xloop:
X	c = unix_getc(finput);
Xswt:
X	switch (c) {
X	case ';':
X		if (brac == 0) {
X			putc(c, faction);
X			return;
X		}
X		goto lcopy;
X
X	case '{':
X		brac++;
X		goto lcopy;
X
X	case '$':
X		s = 1;
X		tok = -1;
X		c = unix_getc(finput);
X		if (c == '<') {
X			/* type description */
X			ungetc(c, finput);
X			if (gettok() != TYPENAME)
X				error("bad syntax on $<ident> clause");
X			tok = numbval;
X			c = unix_getc(finput);
X		}
X		if (c == '$') {
X			fprintf(faction, "yyval");
X			if (ntypes) {
X				/* put out the proper tag... */
X				if (tok < 0)
X					tok = fdtype(*prdptr[nprod]);
X				fprintf(faction, ".%s", typeset[tok]);
X			}
X			goto loop;
X		}
X		if (c == '-') {
X			s = -s;
X			c = unix_getc(finput);
X		}
X		if (isdigit(c)) {
X			j = 0;
X			while (isdigit(c)) {
X				j = j * 10 + c - '0';
X				c = unix_getc(finput);
X			}
X
X			j = j * s - offset;
X			if (j > 0) {
X				error("Illegal use of $%d", j + offset);
X			}
X			fprintf(faction, "yypvt[-%d]", -j);
X			if (ntypes) {
X				/* put out the proper tag */
X				if (j + offset <= 0 && tok < 0)
X					error("must specify type of $%d", j + offset);
X				if (tok < 0)
X					tok = fdtype(prdptr[nprod][j + offset]);
X				fprintf(faction, ".%s", typeset[tok]);
X			}
X			goto swt;
X		}
X		putc('$', faction);
X		if (s < 0)
X			putc('-', faction);
X		goto swt;
X
X	case '}':
X		if (--brac)
X			goto lcopy;
X		putc(c, faction);
X		return;
X
X
X	case '/':		/* look for comments */
X		putc(c, faction);
X		c = unix_getc(finput);
X		if (c != '*')
X			goto swt;
X
X		/* it really is a comment */
X
X		putc(c, faction);
X		c = unix_getc(finput);
X		while (c != EOF) {
X			while (c == '*') {
X				putc(c, faction);
X				if ((c = unix_getc(finput)) == '/')
X					goto lcopy;
X			}
X			putc(c, faction);
X			if (c == '\n')
X				++lineno;
X			c = unix_getc(finput);
X		}
X		error("EOF inside comment");
X
X	case '\'':		/* character constant */
X		match = '\'';
X		goto string;
X
X	case '"':		/* character string */
X		match = '"';
X
Xstring:
X
X		putc(c, faction);
X		while (c = unix_getc(finput)) {
X
X			if (c == '\\') {
X				putc(c, faction);
X				c = unix_getc(finput);
X				if (c == '\n')
X					++lineno;
X			} else if (c == match)
X				goto lcopy;
X			else if (c == '\n')
X				error("newline in string or char. const.");
X			putc(c, faction);
X		}
X		error("EOF in string or character constant");
X
X	case -1:		/* EOF */
X		error("action does not terminate");
X
X	case '\n':
X		++lineno;
X		goto lcopy;
X
X	}
X
Xlcopy:
X	putc(c, faction);
X	goto loop;
X}
X
X
SHAR_EOF
if test 2648 -ne "`wc -c < 'ycpact.c'`"
then
echo shar: error transmitting "'ycpact.c'" '(should have been 2648 characters)'
fi
chmod 644 ycpact.c
fi
if test -f 'yclsur.c'
then
echo shar: will not over-write existing "'yclsur.c'"
else
echo extracting "'yclsur.c'"
sed 's/^X//' >yclsur.c <<'SHAR_EOF'
X/*
X * yclsur.c - generate closure of state i
X *
X * HISTORY
X * {1}	28-Aug-81  Bob Denny
X * 	Modified to make debug code conditionally compile.
X * 
X */
X
X#include "y1.h"
X
X
Xint	closure(i)
X{
X	int	c, ch, work, k;
X	register struct wset *u, *v;
X	int	*pi;
X	int	**s, **t;
X	struct item *q;
X	register struct item *p;
X
X	++zzclose;
X
X	/* first, copy kernel of state i to wsets */
X
X	cwp = wsets;
X	ITMLOOP(i, p, q) {
X		cwp->pitem = p->pitem;
X		cwp->flag = 1;	/* this item must get closed */
X		SETLOOP(k) cwp->ws.lset[k] = p->look->lset[k];
X		WSBUMP(cwp);
X	}
X
X	/* now, go through the loop, closing each item */
X
X	work = 1;
X	while (work) {
X		work = 0;
X		WSLOOP(wsets, u) {
X
X			if (u->flag == 0)
X				continue;
X			c = *(u->pitem);	/* dot is before c */
X
X			if (c < NTBASE) {
X				u->flag = 0;
X				continue;	/* only interesting case
X						 * is where . is before
X										 * nonterminal */
X			}
X			/* compute the lookahead */
X			aryfil(clset.lset, tbitset, 0);
X
X			/* find items involving c */
X			WSLOOP(u, v) {
X				if (v->flag == 1 && *(pi = v->pitem) == c) {
X					v->flag = 0;
X					if (nolook)
X						continue;
X					while ((ch = *++pi) > 0) {
X						if (ch < NTBASE) {
X							/* terminal symbol */
X							SETBIT(clset.lset, ch);
X							break;
X						}
X						/* nonterminal symbol */
X						setunion(clset.lset, pfirst[ch - NTBASE]->lset);
X						if (!pempty[ch - NTBASE])
X							break;
X					}
X					if (ch <= 0)
X						setunion(clset.lset, v->ws.lset);
X				}
X			}
X
X			/* now loop over productions derived from c */
X
X			c -= NTBASE;	/* c is now nonterminal number */
X
X			t = pres[c + 1];
X			for (s = pres[c]; s < t; ++s) {
X				/* put these items into the closure */
X				WSLOOP(wsets, v) {
X					/* is the item there */
X					if (v->pitem == *s) {
X						/* yes, it is there */
X						if (nolook)
X							goto nexts;
X						if (setunion(v->ws.lset, clset.lset))
X							v->flag = work = 1;
X						goto nexts;
X					}
X				}
X
X				/* not there; make a new entry */
X				if (cwp - wsets + 1 >= WSETSIZE)
X					error("working set overflow");
X				cwp->pitem = *s;
X				cwp->flag = 1;
X				if (!nolook) {
X					work = 1;
X					SETLOOP(k) cwp->ws.lset[k] = clset.lset[k];
X				}
X				WSBUMP(cwp);
Xnexts:
X				;
X			}
X
X		}
X	}
X
X	/* have computed closure; flags are reset; return */
X
X	if (cwp > zzcwp)
X		zzcwp = cwp;
X
X#ifdef debug
X	if (foutput != NULL) {
X		fprintf(foutput, "\nState %d, nolook = %d\n", i, nolook);
X		WSLOOP(wsets, u) {
X			if (u->flag)
X				fprintf(foutput, "flag set!\n");
X			u->flag = 0;
X			fprintf(foutput, "\t%s", writem(u->pitem));
X			prlook(&u->ws);
X			fprintf(foutput, "\n");
X		}
X	}
X#endif
X}
X
X
SHAR_EOF
if test 2557 -ne "`wc -c < 'yclsur.c'`"
then
echo shar: error transmitting "'yclsur.c'" '(should have been 2557 characters)'
fi
chmod 644 yclsur.c
fi
if test -f 'yclopt.c'
then
echo shar: will not over-write existing "'yclopt.c'"
else
echo extracting "'yclopt.c'"
sed 's/^X//' >yclopt.c <<'SHAR_EOF'
X/*
X * yclopt.c -
X *
X * HISTORY
X */
X
X#include "y4.h"
X
Xint	callopt()
X{
X
X	register i, *p, j, k, *q;
X
X	/* read the arrays from tempfile and set parameters */
X
X
X	if ((finput = fopen(TEMPNAME, "r")) == NULL)
X		error("optimizer cannot open tempfile");
X	pgo[0] = 0;
X	yypact[0] = 0;
X	nstate = 0;
X	nnonter = 0;
X	for (; ; ) {
X		switch (gtnm()) {
X		case '\n':
X			yypact[++nstate] = (--pmem) - mem0;
X		case ',':
X			continue;
X		case '$':
X			break;
X		default:
X			error("bad tempfile");
X		}
X		break;
X	}
X
X	yypact[nstate] = yypgo[0] = (--pmem) - mem0;
X
X	for (; ; ) {
X		switch (gtnm()) {
X		case '\n':
X			yypgo[++nnonter] = pmem - mem0;
X		case '\r':
X		case ',':
X			continue;
X		case -1:	/* EOF */
X			break;
X		default:
X			error("bad tempfile");
X		}
X		break;
X	}
X
X	yypgo[nnonter--] = (--pmem) - mem0;
X	for (i = 0; i < nstate; ++i) {
X
X		k = 32000;
X		j = 0;
X		q = mem0 + yypact[i + 1];
X		for (p = mem0 + yypact[i]; p < q; p += 2) {
X			if (*p > j)
X				j = *p;
X			if (*p < k)
X				k = *p;
X		}
X		if (k <= j) {
X			/* nontrivial situation */
X			/*
X			 * temporarily, kill this for compatibility j -=
X			 * k;  j is now the range 
X			 */
X			if (k > maxoff)
X				maxoff = k;
X		}
X		greed[i] = (yypact[i + 1] - yypact[i]) + 2 * j;
X		if (j > maxspr)
X			maxspr = j;
X	}
X
X	/* initialize ggreed table */
X
X	for (i = 1; i <= nnonter; ++i) {
X		ggreed[i] = 1;
X		j = 0;
X		/* minimum entry index is always 0 */
X		q = mem0 + yypgo[i + 1] - 1;
X		for (p = mem0 + yypgo[i]; p < q; p += 2) {
X			ggreed[i] += 2;
X			if (*p > j)
X				j = *p;
X		}
X		ggreed[i] = ggreed[i] + 2 * j;
X		if (j > maxoff)
X			maxoff = j;
X	}
X
X	/* now, prepare to put the shift actions into the a array */
X
X	for (i = 0; i < ACTSIZE; ++i)
X		a[i] = 0;
X	maxa = a;
X
X	for (i = 0; i < nstate; ++i) {
X		if (greed[i] == 0 && adb > 1)
X			fprintf(ftable, "State %d: null\n", i);
X		pa[i] = YYFLAG1;
X	}
X
X	while ((i = nxti()) != NOMORE) {
X		if (i >= 0)
X			stin(i);
X		else
X			gin(-i);
X	}
X
X	if (adb > 2) {
X		/* print a array */
X		for (p = a; p <= maxa; p += 10) {
X			fprintf(ftable, "%4d  ", p - a);
X			for (i = 0; i < 10; ++i)
X				fprintf(ftable, "%4d  ", p[i]);
X			fprintf(ftable, "\n");
X		}
X	}
X	/* write out the output appropriate to the language */
X
X	aoutput();
X
X	osummary();
X
X	fclose(finput);
X	ZAPFILE(TEMPNAME);
X}
X
X
SHAR_EOF
if test 2222 -ne "`wc -c < 'yclopt.c'`"
then
echo shar: error transmitting "'yclopt.c'" '(should have been 2222 characters)'
fi
chmod 644 yclopt.c
fi
if test -f 'y1imp.c'
then
echo shar: will not over-write existing "'y1imp.c'"
else
echo extracting "'y1imp.c'"
sed 's/^X//' >y1imp.c <<'SHAR_EOF'
X/*
X * y1imp.c - impure data used by modules originally in y1.c.
X *
X * HISTORY
X */
X
X#define y1imp yes
X
X#include "dtxtrn.h"
X
X
X/* lookahead computations */
X
Xint	tbitset;		/* size of lookahead sets */
Xstruct looksets lkst[LSETSIZE];
Xint	nlset = 0;		/* next lookahead set index */
Xint	nolook = 0;		/* flag to suppress lookahead computations */
Xstruct looksets clset;		/* temporary storage for lookahead */
X
X
X/* working set computations */
X
Xstruct wset wsets[WSETSIZE];
Xstruct wset *cwp;
X
X
X/* state information */
X
Xint	nstate = 0;		/* number of states */
Xstruct item *pstate[NSTATES+2]; /* pointers to descriptions of states */
Xint	tystate[NSTATES];	/* contains type information about states */
Xint	indgo[NSTATES];         /* index to the stored goto table */
Xint	tstates[NTERMS];	/* states generated by terminal gotos */
Xint	ntstates[NNONTERM];	/* states generated by nonterminal gotos */
Xint	mstates[NSTATES];	/* overflow of term/nonterm generation lists */
X
X
X/* storage for the actions in the parser */
X
Xint	amem[ACTSIZE];		/* action table storage */
Xint	*memp = amem;		/* next free action table position */
X
X
X/* other storage areas */
X
Xint	temp1[TEMPSIZE];	/* temporary storage, indexed by terms + ntokens or states */
Xint	lineno = 1;		/* current input line number */
Xint	fatfl = 1;		/* if on, error is fatal */
Xint	nerrors = 0;		/* number of errors */
X
X
X/* storage for information about the nonterminals */
X
Xint	**pres[NNONTERM+2];  /* vector of pointers to productions yielding each nonterminal */
Xstruct looksets *pfirst[NNONTERM+2];  /* vector of pointers to first sets for each nonterminal */
Xint	pempty[NNONTERM+1];  /* vector of nonterminals nontrivially deriving e */
X
X/* accumulators for statistics information */
X
Xstruct wset *zzcwp = wsets;
Xint	zzgoent = 0;
Xint	zzgobest = 0;
Xint	zzacent = 0;
Xint	zzexcp = 0;
Xint	zzclose = 0;
Xint	zzsrconf = 0;
Xint	*zzmemsz = mem0;
Xint	zzrrconf = 0;
X
X/* data pulled from internal static to here */
X/* declared external only in user module    */
X
Xint	*pyield[NPROD];             /* from ycpres */
Xchar	sarr[ISIZE];               /* from ywritm */
SHAR_EOF
if test 2088 -ne "`wc -c < 'y1imp.c'`"
then
echo shar: error transmitting "'y1imp.c'" '(should have been 2088 characters)'
fi
chmod 644 y1imp.c
fi
if test -f 'y2.h'
then
echo shar: will not over-write existing "'y2.h'"
else
echo extracting "'y2.h'"
sed 's/^X//' >y2.h <<'SHAR_EOF'
X/*****************************************************************************/
X/*                             *************                                 */
X/*                             *  Y 2 . H  *                                 */
X/*                             *************                                 */
X/*                                                                           */
X/* This file contains the external declarations needed to hook Yacc modules  */
X/* which were originally in Y2.C to their impure data in Y2IMP.2C. Also does */
X/* the include of the original data/external file DTXTRN.H.                  */
X/*                                                                           */
X/*****************************************************************************/
X
X# include "dtxtrn.h"
X
X# define IDENTIFIER 257
X# define MARK 258
X# define TERM 259
X# define LEFT 260
X# define RIGHT 261
X# define BINARY 262
X# define PREC 263
X# define LCURLY 264
X# define C_IDENTIFIER 265  /* name followed by colon */
X# define NUMBER 266
X# define START 267
X# define TYPEDEF 268
X# define TYPENAME 269
X# define UNION 270
X# define ENDFILE 0
X
X/* communication variables between various I/O routines */
X
Xextern char	*infile;            /* input file name */
Xextern int	numbval;             /* value of an input number */
Xextern char	tokname[ ];         /* input token name */
X
X/* storage of names */
X
Xextern char	cnames[ ];          /* place where token and nonterminal names are stored */
Xextern int	cnamsz;              /* size of cnames */
Xextern char	*cnamp;            /* place where next name is to be put in */
Xextern int	ndefout;             /* number of defined symbols output */
X
X/* storage of types */
Xextern int	ntypes;              /* number of types defined */
Xextern char	*typeset[ ];       /* pointers to type tags */
X
X/* symbol tables for tokens and nonterminals */
X
Xextern int	start;               /* start symbol */
X
X/* assigned token type values */
Xextern int	extval;
SHAR_EOF
if test 1999 -ne "`wc -c < 'y2.h'`"
then
echo shar: error transmitting "'y2.h'" '(should have been 1999 characters)'
fi
chmod 644 y2.h
fi
if test -f 'ystagn.c'
then
echo shar: will not over-write existing "'ystagn.c'"
else
echo extracting "'ystagn.c'"
sed 's/^X//' >ystagn.c <<'SHAR_EOF'
X#include "y1.h"
X
X/*
X * ystagn.1c
X *
X * Modified to make debug code conditionally compile.
X * 28-Aug-81
X * Bob Denny
X */
X
Xstagen()
X
X{
X	/* generate the states */
X
X	int	i, j;
X	register c;
X	register struct wset *p, *q;
X
X	/* initialize */
X
X	nstate = 0;
X	/* THIS IS FUNNY from the standpoint of portability */
X	/* it represents the magic moment when the mem0 array, which has
X        /* been holding the productions, starts to hold item pointers, of a
X        /* different type... */
X	/* someday, alloc should be used to allocate all this stuff... for now, we
X        /* accept that if pointers don't fit in integers, there is a problem... */
X
X	pstate[0] = pstate[1] = (struct item *)mem;
X	aryfil( clset.lset, tbitset, 0 );
X	putitem( prdptr[0] + 1, &clset );
X	tystate[0] = MUSTDO;
X	nstate = 1;
X	pstate[2] = pstate[1];
X
X	aryfil( amem, ACTSIZE, 0 );
X
X	/* now, the main state generation loop */
X
Xmore:
X	SLOOP(i)
X
X	 {
X		if ( tystate[i] != MUSTDO ) 
X			continue;
X		tystate[i] = DONE;
X		aryfil( temp1, nnonter + 1, 0 );
X		/* take state i, close it, and do gotos */
X		closure(i);
X		WSLOOP(wsets, p)
X
X		 {
X			/* generate goto's */
X			if ( p->flag ) 
X				continue;
X			p->flag = 1;
X			c = *(p->pitem);
X			if ( c <= 1 ) {
X
X				if ( pstate[i+1] - pstate[i] <= p - wsets ) 
X					tystate[i] = MUSTLOOKAHEAD;
X				continue;
X			}
X			/* do a goto on c */
X			WSLOOP(p, q)
X
X			 {
X				if ( c == *(q->pitem) ) {
X
X					/* this item contributes to the goto */
X					putitem( q->pitem + 1, &q->ws );
X					q->flag = 1;
X				}
X			}
X			if ( c < NTBASE ) {
X
X				state(c);  /* register new state */
X			} else
X			 {
X				temp1[c-NTBASE] = state(c);
X			}
X		}
X#ifdef debug
X		if ( foutput != NULL ) {
X
X			fprintf( foutput,  "%d: ", i );
X			NTLOOP(j)
X
X			 {
X				if ( temp1[j] ) 
X					fprintf( foutput,  "%s %d, ", nontrst[j].name, temp1[j] );
X			}
X			fprintf( foutput, "\n");
X		}
X#endif
X		indgo[i] = apack( &temp1[1], nnonter - 1 ) - 1;
X		goto more; /* we have done one goto; do some more */
X	}
X	/* no more to do... stop */
X}
X
X
SHAR_EOF
if test 1984 -ne "`wc -c < 'ystagn.c'`"
then
echo shar: error transmitting "'ystagn.c'" '(should have been 1984 characters)'
fi
chmod 644 ystagn.c
fi
if test -f 'ycemty.c'
then
echo shar: will not over-write existing "'ycemty.c'"
else
echo extracting "'ycemty.c'"
sed 's/^X//' >ycemty.c <<'SHAR_EOF'
X/*
X * ycemty.c - mark nonterminals which derive the empty string
X *
X * In addition to looking for empty nonterminals, look for nonterminals
X * which don't derive any token strings.  Both of these should be optimized
X * away.
X *
X * HISTORY
X * {1}	12-Apr-83  Bob Denny
X * 	Add symbolic exit status.
X * 
X */
X#include "y1.h"
X
X#define EMPTY		1
X#define WHOKNOWS	0
X#define OK		1
X
Xint	cempty()
X{
X	register i, *p;
X
X	/*
X	 * first, use the array pempty to detect productions that can
X	 * never be reduced 
X	 */
X
X	/* set pempty to WHONOWS */
X	aryfil(pempty, nnonter + 1, WHOKNOWS);
X
X	/*
X	 * now, look at productions, marking nonterminals which derive
X	 * something 
X	 */
X
Xmore:
X	PLOOP(0, i) {
X		if (pempty[*prdptr[i] - NTBASE])
X			continue;
X		for (p = prdptr[i] + 1; *p >= 0; ++p) {
X			if (*p >= NTBASE && pempty[*p - NTBASE] == WHOKNOWS)
X				break;
X		}
X		if (*p < 0) {
X			/* production can be derived */
X			pempty[*prdptr[i] - NTBASE] = OK;
X			goto more;
X		}
X	}
X
X	/* now, look at the nonterminals, to see if they are all OK */
X
X	NTLOOP(i) {
X		/*
X		 * the added production rises or falls as the start symbol
X		 * ... 
X		 */
X		if (i == 0)
X			continue;
X		if (pempty[i] != OK) {
X			fatfl = 0;
X			error("nonterminal %s never derives any token string", nontrst[i].name);
X		}
X	}
X
X	if (nerrors) {
X		summary();
X		exit(EX_ERR);
X	}
X
X	/*
X	 * now, compute the pempty array, to see which nonterminals derive
X	 * the empty string 
X	 */
X
X	/* set pempty to WHOKNOWS */
X
X	aryfil(pempty, nnonter + 1, WHOKNOWS);
X	/* loop as long as we keep finding empty nonterminals */
X
Xagain:
X	PLOOP(1, i) {
X		if (pempty[*prdptr[i] - NTBASE] == WHOKNOWS) {
X			/* not known to be empty */
X			for (p = prdptr[i] + 1; *p >= NTBASE && pempty[*p - NTBASE] == EMPTY; ++p)
X				;
X			if (*p < 0) {
X				/*
X				 * we have a nontrivially empty
X				 * nonterminal 
X				 */
X				pempty[*prdptr[i] - NTBASE] = EMPTY;
X				goto again;	/* got one ... try for
X										 * another */
X			}
X		}
X	}
X}
X
X
SHAR_EOF
if test 1935 -ne "`wc -c < 'ycemty.c'`"
then
echo shar: error transmitting "'ycemty.c'" '(should have been 1935 characters)'
fi
chmod 644 ycemty.c
fi
if test -f 'ystate.c'
then
echo shar: will not over-write existing "'ystate.c'"
else
echo extracting "'ystate.c'"
sed 's/^X//' >ystate.c <<'SHAR_EOF'
X#include "y1.h"
X
Xstate(c)
X{
X	/* sorts last state,and sees if it equals earlier ones. returns state number */
X	int	size1, size2;
X	register i;
X	int	*s;                                                              /*01*/
X	struct looksets *ss;                                         /*01*/
X	int	s__;                                                     /*01*/
X	struct item *p1, *p2, *k, *l, *q1, *q2;
X	p1 = pstate[nstate];
X	p2 = pstate[nstate+1];
X	if (p1 == p2) 
X		return(0); /* null state */
X	/* sort the items */
X	for (k = p2 - 1; k > p1; k--) {
X		/* make k the biggest */
X		for (l = k - 1; l >= p1; --l)
X			if ( l->pitem > k->pitem ) {
X				s = k->pitem;
X				k->pitem = l->pitem;
X				l->pitem = s;
X				ss = k->look;
X				k->look = l->look;
X				l->look = ss;
X			}
X	}
X	size1 = p2 - p1; /* size of state */
X
X	for ( i = (c >= NTBASE) ? ntstates[c-NTBASE] : tstates[c]; i != 0; i = mstates[i] ) {
X		/* get ith state */
X		q1 = pstate[i];
X		q2 = pstate[i+1];
X		size2 = q2 - q1;
X		if (size1 != size2) 
X			continue;
X		k = p1;
X		for (l = q1; l < q2; l++) {
X			if ( l->pitem != k->pitem ) 
X				break;
X			++k;
X		}
X		if (l != q2) 
X			continue;
X		/* found it */
X		pstate[nstate+1] = pstate[nstate]; /* delete last state */
X		/* fix up lookaheads */
X		if ( nolook ) 
X			return(i);
X		for ( l = q1, k = p1; l < q2; ++l, ++k ) {
X			SETLOOP(s__) clset.lset[s__] = l->look->lset[s__];
X			if ( setunion( clset.lset, k->look->lset ) ) {
X				tystate[i] = MUSTDO;
X				/* register the new set */
X				l->look = flset( &clset );
X			}
X		}
X		return (i);
X	}
X	/* state is new */
X	if ( nolook ) 
X		error( "yacc state/nolook error" );
X	pstate[nstate+2] = p2;
X	if (nstate + 1 >= NSTATES) 
X		error("too many states" );
X	if ( c >= NTBASE ) {
X		mstates[ nstate ] = ntstates[ c-NTBASE ];
X		ntstates[ c-NTBASE ] = nstate;
X	} else      {
X		mstates[ nstate ] = tstates[ c ];
X		tstates[ c ] = nstate;
X	}
X	tystate[nstate] = MUSTDO;
X	return(nstate++);
X}
X
X
SHAR_EOF
if test 1909 -ne "`wc -c < 'ystate.c'`"
then
echo shar: error transmitting "'ystate.c'" '(should have been 1909 characters)'
fi
chmod 644 ystate.c
fi
if test -f 'Makefile'
then
echo shar: will not over-write existing "'Makefile'"
else
echo extracting "'Makefile'"
sed 's/^X//' >Makefile <<'SHAR_EOF'
XCFLAGS   = -O
XLDFLAGS  = -s
XOBJECTS  = y1imp.o y2imp.o y3imp.o y4imp.o yaryfl.o ycemty.o ychcpy.o\
X           yclsur.o ycpfir.o ycpres.o yerror.o yflset.o ymain.o yothrs.o\
X           yprlok.o yptitm.o ysmnam.o ystagn.o ystate.o ystuni.o ysumry.o\
X           ywritm.o ychfnd.o ycpact.o ycpuni.o ycpycd.o ycstsh.o ydefin.o\
X           ydfout.o yfdtyp.o yfnact.o ygttok.o ysetup.o yskpcm.o yapack.o\
X           yg2gen.o yg2out.o yhdprd.o youtpt.o yprcft.o ywarry.o ywract.o\
X           ywstat.o yaoput.o yclopt.o ygin.o ygtnm.o ynxti.o yosmry.o\
X           ystin.o yarout.o
XPROGRAMS = yacc
X
Xall: ${PROGRAMS}
X
Xclean:
X	rm -f ${PROGRAMS}
X	rm -f ${OBJECTS}
X	rm -f a.out core
X
Xyacc: ${OBJECTS}
X	cc ${LDFLAGS} ${OBJECTS} -o yacc
X
X
Xdtxtrn.h: 	/usr/include/stdio.h system.h 
Xy1.h: 		dtxtrn.h 
Xy1imp.o: 	dtxtrn.h 
Xy2.h: 		dtxtrn.h 
Xy2imp.o: 	dtxtrn.h 
Xy3.h: 		dtxtrn.h 
Xy3imp.o: 	dtxtrn.h 
Xy4.h: 		dtxtrn.h 
Xy4imp.o: 	dtxtrn.h 
Xyaoput.o: 	y4.h 
Xyapack.o: 	y3.h 
Xyarout.o: 	y4.h 
Xyaryfl.o: 	y1.h 
Xycemty.o: 	y1.h 
Xychcpy.o: 	y1.h 
Xychfnd.o: 	y2.h 
Xyclopt.o: 	y4.h 
Xyclsur.o: 	y1.h 
Xycpact.o: 	/usr/include/stdio.h /usr/include/ctype.h y2.h 
Xycpfir.o: 	y1.h 
Xycpres.o: 	y1.h 
Xycpuni.o: 	y2.h 
Xycpycd.o: 	y2.h 
Xycstsh.o: 	y2.h 
Xydefin.o: 	y2.h 
Xydfout.o: 	/usr/include/ctype.h y2.h 
Xyerror.o: 	y1.h 
Xyfdtyp.o: 	y2.h 
Xyflset.o: 	y1.h 
Xyfnact.o: 	y2.h 
Xyg2gen.o: 	y3.h 
Xyg2out.o: 	y3.h 
Xygin.o: 	y4.h 
Xygtnm.o: 	/usr/include/ctype.h 	 y4.h 
Xygttok.o: 	/usr/include/ctype.h 	 y2.h 
Xyhdprd.o: 	y3.h 
Xymain.o: 	y1.h 
Xynxti.o: 	y4.h 
Xyosmry.o: 	y4.h 
Xyothrs.o: 	y1.h 
Xyoutpt.o: 	y3.h 
Xyprcft.o: 	y3.h 
Xyprlok.o: 	y1.h 
Xyptitm.o: 	y1.h 
Xysetup.o: 	y2.h 
Xyskpcm.o: 	y2.h 
Xysmnam.o: 	y1.h 
Xystagn.o: 	y1.h 
Xystate.o: 	y1.h 
Xystin.o: 	y4.h 
Xystuni.o: 	y1.h 
Xysumry.o: 	y1.h 
Xywarry.o: 	y3.h 
Xywract.o: 	y3.h 
Xywritm.o: 	y1.h 
Xywstat.o: 	y3.h 
SHAR_EOF
if test 1819 -ne "`wc -c < 'Makefile'`"
then
echo shar: error transmitting "'Makefile'" '(should have been 1819 characters)'
fi
chmod 644 Makefile
fi
if test -f 'y1.h'
then
echo shar: will not over-write existing "'y1.h'"
else
echo extracting "'y1.h'"
sed 's/^X//' >y1.h <<'SHAR_EOF'
X/*****************************************************************************/
X/*                           *************                                   */
X/*                           *  Y 1 . H  *                                   */
X/*                           *************                                   */
X/*                                                                           */
X/* This file contains the external declarations needed to hook Yacc modules  */
X/* which were originally in Y1.C to their impure data in Y1IMP.1C. Also does */
X/* the include of the original data/external file DTXTRN.H.                  */
X/*                                                                           */
X/*****************************************************************************/
X
X#include "dtxtrn.h"
X
X/* lookahead computations */
X
Xextern int	tbitset;  /* size of lookahead sets */
Xextern int	nlset; /* next lookahead set index */
Xextern struct looksets clset;  /* temporary storage for lookahead computations */
X
X/* other storage areas */
X
Xextern int	fatfl;               /* if on, error is fatal */
Xextern int	nerrors;             /* number of errors */
X
X/* storage for information about the nonterminals */
X
Xextern int	**pres[ ];           /* vector of pointers to productions yielding each nonterminal */
Xextern struct looksets *pfirst[ ]; /* vector of pointers to first sets for each nonterminal */
Xextern int	pempty[ ];           /* vector of nonterminals nontrivially deriving e */
X
X/* accumulators for statistics information */
X
Xextern struct wset *zzcwp;
Xextern int	*zzmemsz;
SHAR_EOF
if test 1605 -ne "`wc -c < 'y1.h'`"
then
echo shar: error transmitting "'y1.h'" '(should have been 1605 characters)'
fi
chmod 644 y1.h
fi
if test -f 'yywrap.c'
then
echo shar: will not over-write existing "'yywrap.c'"
else
echo extracting "'yywrap.c'"
sed 's/^X//' >yywrap.c <<'SHAR_EOF'
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
Xyywrap()
X
X{
X	return(1);
X}
X
X
SHAR_EOF
if test 94 -ne "`wc -c < 'yywrap.c'`"
then
echo shar: error transmitting "'yywrap.c'" '(should have been 94 characters)'
fi
chmod 644 yywrap.c
fi
# end of shell archive
exit 0

mark@ems.UUCP (02/01/87)

	Here is part two of the public domain yacc.

	Mark H. Colburn          mark@ems.uucp      
	EMS/McGraw-Hill          {rutgers|amdahl|ihnp4}!meccts!ems!mark
	9855 West 78th Street     
	Eden Prairie, MN 55344   (612) 829-8200 x235

--------------------------------- CUT HERE -----------------------------------
#! /bin/sh
# This is a shell archive (part 2 of 2), meaning:
# 1.  Remove everything above the #! /bin/sh line.
# 2.  Save the resulting text in a file.
# 3.  Execute the file with /bin/sh (not csh).
#
#     The following files will be created:
#		youtpt.c
#		y2imp.c
#		ydefin.c
#		ywract.c
#		yapack.c
#		yothrs.c
#		ywstat.c
#		ystin.c
#		system.h
#		ysumry.c
#		README
#		yg2gen.c
#		y4.h
#		ycpfir.c
#		yg2out.c
#		ycpres.c
#		y3.h
#		ygin.c
#		ymain.c
#		yprcft.c
#		ycpuni.c
#		ydfout.c
#		ywritm.c
#		yflset.c
#		yhdprd.c
#		yptitm.c
#		ycpycd.c
#		ygtnm.c
#		yskpcm.c
#		yosmry.c
#		y4imp.c
#		ynxti.c
#		ychfnd.c
#		yyless.c
#		yarout.c
#		yerror.c
#		ywarry.c
#		yfdtyp.c
#		yprlok.c
#		ystuni.c
#		yaoput.c
#		y3imp.c
#		ycstsh.c
#		ysmnam.c
#		yaryfl.c
#		ychcpy.c
#		yfnact.c
#
# Created by mark@ems (Mark H. Colburn) on Sun Feb  1 01:20:12 1987
#
if test -f 'youtpt.c'
then
echo shar: will not over-write existing "'youtpt.c'"
else
echo extracting "'youtpt.c'"
sed 's/^X//' >youtpt.c <<'SHAR_EOF'
X#include "y3.h"
X
Xoutput()
X{
X	/* print the output for the states */
X
X	int	i, k, c;
X	register struct wset *u, *v;
X
X	fprintf( ftable, "short yyexca[] ={\n" );
X
X	SLOOP(i)
X	 {
X		/* output the stuff for state i */
X		nolook = !(tystate[i] == MUSTLOOKAHEAD);
X		closure(i);
X		/* output actions */
X		nolook = 1;
X		aryfil( temp1, ntokens + nnonter + 1, 0 );
X		WSLOOP(wsets, u)
X		 {
X			c = *( u->pitem );
X			if ( c > 1 && c < NTBASE && temp1[c] == 0 ) {
X				WSLOOP(u, v)
X				 {
X					if ( c == *(v->pitem) ) 
X						putitem( v->pitem + 1, (struct looksets *)0 );
X				}
X				temp1[c] = state(c);
X			} else if ( c > NTBASE && temp1[ (c -= NTBASE) + ntokens ] == 0 ) {
X				temp1[ c+ntokens ] = amem[indgo[i]+c];
X			}
X		}
X
X		if ( i == 1 ) 
X			temp1[1] = ACCEPTCODE;
X
X		/* now, we have the shifts; look at the reductions */
X
X		lastred = 0;
X		WSLOOP(wsets, u)
X		 {
X			c = *( u->pitem );
X			if ( c <= 0 ) {
X				/* reduction */
X				lastred = -c;
X				TLOOP(k)
X				 {
X					if ( BIT(u->ws.lset, k) ) {
X						if ( temp1[k] == 0 ) 
X							temp1[k] = c;
X						else if ( temp1[k] < 0 ) {
X							/* reduce/reduce conflict */
X							if ( foutput != NULL )
X								fprintf( foutput,
X								    "\n%d: reduce/reduce conflict (red'ns %d and %d ) on %s",
X								                            i, -temp1[k], lastred, symnam(k) );
X							if ( -temp1[k] > lastred ) 
X								temp1[k] = -lastred;
X							++zzrrconf;
X						} else                     {
X							/* potential shift/reduce conflict */
X							precftn( lastred, k, i );
X						}
X					}
X				}
X			}
X		}
X		wract(i);
X	}
X
X	fprintf( ftable, "\t};\n" );
X
X	wdef( "YYNPROD", nprod );
X
X}
X
X
SHAR_EOF
if test 1597 -ne "`wc -c < 'youtpt.c'`"
then
echo shar: error transmitting "'youtpt.c'" '(should have been 1597 characters)'
fi
chmod 644 youtpt.c
fi
if test -f 'y2imp.c'
then
echo shar: will not over-write existing "'y2imp.c'"
else
echo extracting "'y2imp.c'"
sed 's/^X//' >y2imp.c <<'SHAR_EOF'
X/*
X * y2imp.c - impure date needed by routines pulled from y2.c
X *
X * HISTORY
X */
X
X#define y2imp YES
X#include "dtxtrn.h"
X
X
X/* communication variables between various I/O routines */
X
Xchar	*infile;			/* input file name */
Xint	numbval;		/* value of an input number */
Xchar	tokname[NAMESIZE];	/* input token name */
X
X
X/* storage of names */
X
Xchar	cnames[CNAMSZ];		/* token and nonterminal name storage */
Xint	cnamsz = CNAMSZ;	/* size of cnames */
Xchar	*cnamp = cnames;	/* place where next name is to be put in */
Xint	ndefout = 3;		/* number of defined symbols output */
X
X
X/* storage of types */
X
Xint	ntypes;			/* number of types defined */
Xchar	*typeset[NTYPES];	/* pointers to type tags */
X
X
X/* symbol tables for tokens and nonterminals */
X
Xint	ntokens = 0;
Xstruct toksymb tokset[NTERMS];
Xint	toklev[NTERMS];
Xint	nnonter = -1;
Xstruct ntsymb nontrst[NNONTERM];
Xint	start;			/* start symbol */
X
X
X/* assigned token type values */
X
Xint	extval = 0;
X
X
X/* input and output file descriptors */
X
XFILE   *finput;			/* yacc input file */
XFILE   *faction;		/* file for saving actions */
XFILE   *fdefine;		/* file for # defines */
XFILE   *ftable;			/* y.tab.c file */
XFILE   *ftemp;			/* tempfile to pass 2 */
XFILE   *foutput;		/* y.output file */
X
X
X/* storage for grammar rules */
X
Xint	mem0[MEMSIZE];		/* production storage */
Xint	*mem = mem0;
Xint	nprod = 1;		/* number of productions */
Xint	*prdptr[NPROD];		/* pointers to descriptions of productions */
Xint	levprd[NPROD];		/* precedence levels for the productions */
X
X
X/* Statics pulled from modules */
X
Xint	peekline;           /* from gettok() */
SHAR_EOF
if test 1586 -ne "`wc -c < 'y2imp.c'`"
then
echo shar: error transmitting "'y2imp.c'" '(should have been 1586 characters)'
fi
chmod 644 y2imp.c
fi
if test -f 'ydefin.c'
then
echo shar: will not over-write existing "'ydefin.c'"
else
echo extracting "'ydefin.c'"
sed 's/^X//' >ydefin.c <<'SHAR_EOF'
X#include "y2.h"
X
Xdefin( t, s ) 
Xregister char	*s;
X
X{
X	/*   define s to be a terminal if t=0
X        or a nonterminal if t=1         */
X
X	register val;
X
X	if (t) {
X		if ( ++nnonter >= NNONTERM ) 
X			error("too many nonterminals, limit %d", NNONTERM);
X		nontrst[nnonter].name = cstash(s);
X		return( NTBASE + nnonter );
X	}
X	/* must be a token */
X	if ( ++ntokens >= NTERMS ) 
X		error("too many terminals, limit %d", NTERMS );
X	tokset[ntokens].name = cstash(s);
X
X	/* establish value for token */
X
X	if ( s[0] == ' ' && s[2] == '\0' ) /* single character literal */
X		val = s[1];
X	else if ( s[0] == ' ' && s[1] == '\\' ) {
X		/* escape sequence */
X		if ( s[3] == '\0' ) {
X			/* single character escape sequence */
X			switch ( s[2] ) {
X				/* character which is escaped */
X			case 'n':
X				val = '\n';
X				break;
X			case 'r':
X				val = '\r';
X				break;
X			case 'b':
X				val = '\b';
X				break;
X			case 't':
X				val = '\t';
X				break;
X			case 'f':
X				val = '\f';
X				break;
X			case '\'':
X				val = '\'';
X				break;
X			case '"':
X				val = '"';
X				break;
X			case '\\':
X				val = '\\';
X				break;
X			default:
X				error( "invalid escape" );
X			}
X		} else if ( s[2] <= '7' && s[2] >= '0' ) {
X			/* \nnn sequence */
X			if ( s[3] < '0' || s[3] > '7' || s[4] < '0' || 
X			    s[4] > '7' || s[5] != '\0' ) 
X				error("illegal \\nnn construction" );
X			val = 64 * s[2] + 8 * s[3] + s[4] - 73 * '0';
X			if ( val == 0 ) 
X				error( "'\\000' is illegal" );
X		}
X	} else      {
X		val = extval++;
X	}
X	tokset[ntokens].value = val;
X	toklev[ntokens] = 0;
X	return( ntokens );
X}
X
X
SHAR_EOF
if test 1550 -ne "`wc -c < 'ydefin.c'`"
then
echo shar: error transmitting "'ydefin.c'" '(should have been 1550 characters)'
fi
chmod 644 ydefin.c
fi
if test -f 'ywract.c'
then
echo shar: will not over-write existing "'ywract.c'"
else
echo extracting "'ywract.c'"
sed 's/^X//' >ywract.c <<'SHAR_EOF'
X#include "y3.h"
X
Xwract(i)
X{
X	/* output state i */
X	/* temp1 has the actions, lastred the default */
X	int	p, p0, p1;
X	int	ntimes, tred, count, j;
X	int	flag;
X
X	/* find the best choice for lastred */
X
X	lastred = 0;
X	ntimes = 0;
X	TLOOP(j)
X	 {
X		if ( temp1[j] >= 0 ) 
X			continue;
X		if ( temp1[j] + lastred == 0 ) 
X			continue;
X		/* count the number of appearances of temp1[j] */
X		count = 0;
X		tred = -temp1[j];
X		levprd[tred] |= REDFLAG;
X		TLOOP(p)
X		 {
X			if ( temp1[p] + tred == 0 ) 
X				++count;
X		}
X		if ( count > ntimes ) {
X			lastred = tred;
X			ntimes = count;
X		}
X	}
X
X	/* for error recovery, arrange that, if there is a shift on the
X        /* error recovery token, `error', that the default be the error action */
X	if ( temp1[1] > 0 ) 
X		lastred = 0;
X
X	/* clear out entries in temp1 which equal lastred */
X	TLOOP(p) if ( temp1[p] + lastred == 0 )
X		temp1[p] = 0;
X
X	wrstate(i);
X	defact[i] = lastred;
X
X	flag = 0;
X	TLOOP(p0)
X	 {
X		if ( (p1 = temp1[p0]) != 0 ) {
X			if ( p1 < 0 ) {
X				p1 = -p1;
X				goto exc;
X			} else if ( p1 == ACCEPTCODE ) {
X				p1 = -1;
X				goto exc;
X			} else if ( p1 == ERRCODE ) {
X				p1 = 0;
X				goto exc;
Xexc:
X				if ( flag++ == 0 ) 
X					fprintf( ftable, "-1, %d,\n", i );
X				fprintf( ftable, "\t%d, %d,\n", tokset[p0].value, p1 );
X				++zzexcp;
X			} else            {
X				fprintf( ftemp, "%d,%d,", tokset[p0].value, p1 );
X				++zzacent;
X			}
X		}
X	}
X	if ( flag ) {
X		defact[i] = -2;
X		fprintf( ftable, "\t-2, %d,\n", lastred );
X	}
X	fprintf( ftemp, "\n" );
X	return;
X}
X
X
SHAR_EOF
if test 1499 -ne "`wc -c < 'ywract.c'`"
then
echo shar: error transmitting "'ywract.c'" '(should have been 1499 characters)'
fi
chmod 644 ywract.c
fi
if test -f 'yapack.c'
then
echo shar: will not over-write existing "'yapack.c'"
else
echo extracting "'yapack.c'"
sed 's/^X//' >yapack.c <<'SHAR_EOF'
X/*
X * yapack.c -
X *
X * HISTORY
X * {1}	28-Aug-81  Bob Denny
X * 	Modified to make debug code conditionally compile.
X */
X
X#include "y3.h"
X
X
Xint	apack(p, n )
Xint	*p;
X{
X	/* pack state i from temp1 into amem */
X	int	off;
X	register *pp, *qq, *rr;
X	int	*q, *r;
X
X	/*
X	 * we don't need to worry about checking because we we will only
X	 * look entries known to be there... 
X	 */
X
X	/* eliminate leading and trailing 0's */
X
X	q = p + n;
X	for (pp = p, off = 0; *pp == 0 && pp <= q; ++pp, --off)	
X		/* VOID */;
X	if (pp > q)
X		return (0);	/* no actions */
X	p = pp;
X
X	/* now, find a place for the elements from p to q, inclusive */
X
X	r = &amem[ACTSIZE - 1];
X	for (rr = amem; rr <= r; ++rr, ++off) {
X		/* try rr */
X		for (qq = rr, pp = p; pp <= q; ++pp, ++qq) {
X			if (*pp != 0) {
X				if (*pp != *qq && *qq != 0)
X					goto nextk;
X			}
X		}
X
X		/* we have found an acceptable k */
X
X#ifdef debug
X		if (foutput != NULL)
X			fprintf(foutput, "off = %d, k = %d\n", off, rr - amem);
X#endif
X		for (qq = rr, pp = p; pp <= q; ++pp, ++qq) {
X			if (*pp) {
X				if (qq > r)
X					error("action table overflow");
X				if (qq > memp)
X					memp = qq;
X				*qq = *pp;
X			}
X		}
X#ifdef debug
X		if (foutput != NULL) {
X			for (pp = amem; pp <= memp; pp += 10) {
X				fprintf(foutput, "\t");
X				for (qq = pp; qq <= pp + 9; ++qq)
X					fprintf(foutput, "%d ", *qq);
X				fprintf(foutput, "\n");
X			}
X		}
X#endif
X		return (off);
Xnextk:
X		;
X	}
X	error("no space in action table");
X	/* NOTREACHED */
X}
X
X
SHAR_EOF
if test 1450 -ne "`wc -c < 'yapack.c'`"
then
echo shar: error transmitting "'yapack.c'" '(should have been 1450 characters)'
fi
chmod 644 yapack.c
fi
if test -f 'yothrs.c'
then
echo shar: will not over-write existing "'yothrs.c'"
else
echo extracting "'yothrs.c'"
sed 's/^X//' >yothrs.c <<'SHAR_EOF'
X/* Edits:
X *      06-Dec-80 Original code broken out of y1.c.
X *      18-Dec-80 Add conditional code for Decus for tempfile deletion.
X */
X
X#include "y1.h"
X
Xint	others()
X{
X	/* put out other arrays, copy the parsers */
X	register c, i, j;
X
X	finput = (FILE * )fopen(PARSER, "r");
X	if (finput == (FILE * )NULL)
X		error("cannot find parser %s", PARSER);
X
X	warray("yyr1", levprd, nprod);
X
X	aryfil(temp1, nprod, 0);
X	PLOOP(1, i) temp1[i] = prdptr[i + 1] - prdptr[i] - 2;
X	warray("yyr2", temp1, nprod);
X
X	aryfil(temp1, nstate, -1000);
X	TLOOP(i) {
X		for (j = tstates[i]; j != 0; j = mstates[j]) {
X			temp1[j] = tokset[i].value;
X		}
X	}
X	NTLOOP(i) {
X		for (j = ntstates[i]; j != 0; j = mstates[j]) {
X			temp1[j] = -i;
X		}
X	}
X	warray("yychk", temp1, nstate);
X
X	warray("yydef", defact, nstate);
X
X	/* copy parser text */
X
X	while ((c = unix_getc(finput)) != EOF) {
X		if (c == '$') {
X			if ((c = unix_getc(finput)) != 'A')
X				putc('$', ftable);
X			else {
X				/* copy actions */
X				faction = fopen(ACTNAME, "r");
X				if (faction == NULL)
X					error("cannot reopen action tempfile");
X				while ((c = unix_getc(faction)) != EOF)
X					putc(c, ftable);
X				fclose(faction);
X				ZAPFILE(ACTNAME);
X				c = unix_getc(finput);
X			}
X		}
X		putc(c, ftable);
X	}
X	fclose(ftable);
X}
X
X
Xint	unix_getc(iop)
XFILE	*iop;
X{
X	int	c;
X
X	c = getc(iop);
X	/* Stop on Control-Z */
X	if (c == '\032')
X		return (EOF);
X	else
X		return (c);
X}
X
X
SHAR_EOF
if test 1395 -ne "`wc -c < 'yothrs.c'`"
then
echo shar: error transmitting "'yothrs.c'" '(should have been 1395 characters)'
fi
chmod 644 yothrs.c
fi
if test -f 'ywstat.c'
then
echo shar: will not over-write existing "'ywstat.c'"
else
echo extracting "'ywstat.c'"
sed 's/^X//' >ywstat.c <<'SHAR_EOF'
X#include "y3.h"
X
Xwrstate(i)
X{
X	/* writes state i */
X	register j0, j1;
X	register struct item *pp, *qq;
X	register struct wset *u;
X
X	if ( foutput == NULL ) 
X		return;
X	fprintf( foutput, "\nstate %d\n", i);
X	ITMLOOP(i, pp, qq) fprintf( foutput, "\t%s\n", writem(pp->pitem));
X	if ( tystate[i] == MUSTLOOKAHEAD ) {
X		/* print out empty productions in closure */
X		WSLOOP( wsets + (pstate[i+1] - pstate[i]), u )
X		 {
X			if ( *(u->pitem) < 0 ) 
X				fprintf( foutput, "\t%s\n", writem(u->pitem) );
X		}
X	}
X
X	/* check for state equal to another */
X
X	TLOOP(j0) if ( (j1 = temp1[j0]) != 0 ) {
X		fprintf( foutput, "\n\t%s  ", symnam(j0) );
X		if ( j1 > 0 ) {
X			/* shift, error, or accept */
X			if ( j1 == ACCEPTCODE ) 
X				fprintf( foutput,  "accept" );
X			else if ( j1 == ERRCODE ) 
X				fprintf( foutput, "error" );
X			else 
X				fprintf( foutput,  "shift %d", j1 );
X		} else 
X			fprintf( foutput, "reduce %d", -j1 );
X	}
X
X	/* output the final production */
X
X	if ( lastred ) 
X		fprintf( foutput, "\n\t.  reduce %d\n\n", lastred );
X	else 
X		fprintf( foutput, "\n\t.  error\n\n" );
X
X	/* now, output nonterminal actions */
X
X	j1 = ntokens;
X	for ( j0 = 1; j0 <= nnonter; ++j0 ) {
X		if ( temp1[++j1] ) 
X			fprintf( foutput, "\t%s  goto %d\n", symnam( j0 + NTBASE), temp1[j1] );
X	}
X
X}
X
X
Xwdef( s, n ) 
Xchar	*s;
X
X{
X	/* output a definition of s to the value n */
X	fprintf( ftable, "# define %s %d\n", s, n );
X}
X
X
SHAR_EOF
if test 1388 -ne "`wc -c < 'ywstat.c'`"
then
echo shar: error transmitting "'ywstat.c'" '(should have been 1388 characters)'
fi
chmod 644 ywstat.c
fi
if test -f 'ystin.c'
then
echo shar: will not over-write existing "'ystin.c'"
else
echo extracting "'ystin.c'"
sed 's/^X//' >ystin.c <<'SHAR_EOF'
X#include "y4.h"
X
Xstin(i)
X{
X	register *r, *s, n, flag, j, *q1, *q2;
X
X	greed[i] = 0;
X
X	/* enter state i into the a array */
X
X	q2 = mem0 + yypact[i+1];
X	q1 = mem0 + yypact[i];
X	/* find an acceptable place */
X
X	for ( n = -maxoff; n < ACTSIZE; ++n ) {
X
X		flag = 0;
X		for ( r = q1; r < q2; r += 2 ) {
X			if ( (s = *r + n + a ) < a ) 
X				goto nextn;
X			if ( *s == 0 ) 
X				++flag;
X			else if ( *s != r[1] ) 
X				goto nextn;
X		}
X
X		/* check that the position equals another only if the states are identical */
X
X		for ( j = 0; j < nstate; ++j ) {
X			if ( pa[j] == n ) {
X				if ( flag ) 
X					goto nextn;  /* we have some disagreement */
X				if ( yypact[j+1] + yypact[i] == yypact[j] + yypact[i+1] ) {
X					/* states are equal */
X					pa[i] = n;
X					if ( adb > 1 ) 
X						fprintf( ftable, "State %d: entry at %d equals state %d\n",
X						    i, n, j );
X					return;
X				}
X				goto nextn;  /* we have some disagreement */
X			}
X		}
X
X		for ( r = q1; r < q2; r += 2 ) {
X			if ( (s = *r + n + a ) >= &a[ACTSIZE] ) 
X				error( "out of space in optimizer a array" );
X			if ( s > maxa ) 
X				maxa = s;
X			if ( *s != 0 && *s != r[1] ) 
X				error( "clobber of a array, pos'n %d, by %d", s - a, r[1] );
X			*s = r[1];
X		}
X		pa[i] = n;
X		if ( adb > 1 ) 
X			fprintf( ftable, "State %d: entry at %d\n", i, pa[i] );
X		return;
X
Xnextn:
X		;
X	}
X
X	error( "Error; failure to place state %d\n", i );
X}
X
X
SHAR_EOF
if test 1373 -ne "`wc -c < 'ystin.c'`"
then
echo shar: error transmitting "'ystin.c'" '(should have been 1373 characters)'
fi
chmod 644 ystin.c
fi
if test -f 'system.h'
then
echo shar: will not over-write existing "'system.h'"
else
echo extracting "'system.h'"
sed 's/^X//' >system.h <<'SHAR_EOF'
X/*                             *********************
X *                             *  S Y S T E M . H  *
X *                             *********************
X *
X * This file replaces the original "files." header file. It defines, for
X * the IBM PC/XT version, the target parser function source file, overriding
X * file name string defines, and other system-specific definitions and
X * parameters. 
X *
X * Bob Denny    06-Dec-80
X *
X * Edits:
X *              18-Dec-80  ZAPFILE no longer used in Decus Yacc.
X *                         Parser file renamed yypars.c
X *
X *              28-Aug-81  Temp files for RSX have specific version
X *                         numbers of 1 to avoid multi-versions. Rename
X *                         parser info file ".i".
X *
X *              12-Apr-83  Add FNAMESIZE & EX_xxx parameters.
X *
X *Scott Guthery 23-Dec-83  Adapt for the IBM PC/XT & DeSmet C compiler.
X *
X */
X
X/* Define WORD32 if target machine is a 32 bitter */
X#define WORD32
X
X/*
X * Target parser source file
X */
X# define PARSER "yypars.c"
X
X/*
X * basic size of the Yacc implementation
X */
X# define MEDIUM
X
X/*
X * Table size for this Yacc
X */
X# define HUGETAB YES
X
X/*
X * Filespec definitions
X */
X# define ACTNAME "yacc2.tmp"
X# define TEMPNAME "yacc1.tmp"
X# define FNAMESIZE 24
X
X/*
X * Exit status values
X */
X#define EX_SUC 1
X#define EX_WAR 0
X#define EX_ERR 2
X#define EX_SEV 4
SHAR_EOF
if test 1368 -ne "`wc -c < 'system.h'`"
then
echo shar: error transmitting "'system.h'" '(should have been 1368 characters)'
fi
chmod 644 system.h
fi
if test -f 'ysumry.c'
then
echo shar: will not over-write existing "'ysumry.c'"
else
echo extracting "'ysumry.c'"
sed 's/^X//' >ysumry.c <<'SHAR_EOF'
X#include "y1.h"
X
Xsummary()
X{
X	/* output the summary on the tty */
X
X	if ( foutput != NULL ) {
X		fprintf( foutput, "\n%d/%d terminals, %d/%d nonterminals\n", ntokens, NTERMS,
X		    nnonter, NNONTERM );
X		fprintf( foutput, "%d/%d grammar rules, %d/%d states\n", nprod, NPROD, nstate, NSTATES );
X		fprintf( foutput, "%d shift/reduce, %d reduce/reduce conflicts reported\n", zzsrconf, zzrrconf );
X		fprintf( foutput, "%d/%d working sets used\n", zzcwp - wsets,  WSETSIZE );
X		fprintf( foutput, "memory: states,etc. %d/%d, parser %d/%d\n", zzmemsz - mem0, MEMSIZE,
X		    memp - amem, ACTSIZE );
X		fprintf( foutput, "%d/%d distinct lookahead sets\n", nlset, LSETSIZE );
X		fprintf( foutput, "%d extra closures\n", zzclose - 2 * nstate );
X		fprintf( foutput, "%d shift entries, %d exceptions\n", zzacent, zzexcp );
X		fprintf( foutput, "%d goto entries\n", zzgoent );
X		fprintf( foutput, "%d entries saved by goto default\n", zzgobest );
X	}
X	if ( zzsrconf != 0 || zzrrconf != 0 ) {
X		fprintf( stdout, "\nconflicts: ");
X		if ( zzsrconf )
X			fprintf( stdout, "%d shift/reduce" , zzsrconf );
X		if ( zzsrconf && zzrrconf )
X			fprintf( stdout, ", " );
X		if ( zzrrconf )
X			fprintf( stdout, "%d reduce/reduce" , zzrrconf );
X		fprintf( stdout, "\n" );
X	}
X
X	fclose( ftemp );
X	if ( fdefine != NULL ) 
X		fclose( fdefine );
X}
X
X
SHAR_EOF
if test 1307 -ne "`wc -c < 'ysumry.c'`"
then
echo shar: error transmitting "'ysumry.c'" '(should have been 1307 characters)'
fi
chmod 644 ysumry.c
fi
if test -f 'README'
then
echo shar: will not over-write existing "'README'"
else
echo extracting "'README'"
sed 's/^X//' >README <<'SHAR_EOF'
X                                                Sun Feb  1 00:52:01 CST 1987
X
X                                UNIX/MS-DOS YACC
X
X	Here is a copy of a public domain version of YACC.  This version
X	is a derivative of the DECUS yacc (at lease some where along the
X	it come from there anyways).  When I got it it had been modified
X	to run under MS-DOS on IBM-PC's.  I have modified it to, (once
X	again) run under UNIX, as well as PC-DOS.
X
X	It runs fine under System V.2 on an Arete 1200, as well as PC-DOS
X	3.1.  I do not have access to a Berkley machine, so I have not
X	been able to test it in that environment.
X
X	I will post updates and patches to this version of YACC as I work 
X	with it more, and as I get comments from other people who use it.
X	If you have any enhancements, portability problems or comments,
X	please let me know and I will put them in.
X
X	For those of you who have been wanting YACC on a PC, here it is.
X
X	In order to install the package, look at the #defines in system.h
X	and dtxtrn.h and modify them to match you machine configuration
X	and needs/desires.  Then type make.
X
X
X	Mark H. Colburn          mark@ems.uucp      
X	EMS/McGraw-Hill          {rutgers|amdahl|ihnp4}!meccts!ems!mark
X	9855 West 78th Street     
X	Eden Prairie, MN 55344   (612) 829-8200 x235
SHAR_EOF
if test 1277 -ne "`wc -c < 'README'`"
then
echo shar: error transmitting "'README'" '(should have been 1277 characters)'
fi
chmod 644 README
fi
if test -f 'yg2gen.c'
then
echo shar: will not over-write existing "'yg2gen.c'"
else
echo extracting "'yg2gen.c'"
sed 's/^X//' >yg2gen.c <<'SHAR_EOF'
X#include "y3.h"
X
X/*
X * yg2gen.3c
X *
X * Modified to make debug code conditionally compile.
X * 28-Aug-81
X * Bob Denny
X */
X
Xgo2gen(c)
X
X{
X	/* output the gotos for nonterminal c */
X
X	int	i, work, cc;
X	struct item *p, *q;
X
X
X	/* first, find nonterminals with gotos on c */
X
X	aryfil( temp1, nnonter + 1, 0 );
X	temp1[c] = 1;
X
X	work = 1;
X	while ( work ) {
X
X		work = 0;
X		PLOOP(0, i)
X
X		 {
X			if ( (cc = prdptr[i][1] - NTBASE) >= 0 ) {
X
X				/* cc is a nonterminal */
X				if ( temp1[cc] != 0 ) {
X
X					/* cc has a goto on c */
X					cc = *prdptr[i] - NTBASE; /* thus, the left side of production i does too */
X					if ( temp1[cc] == 0 ) {
X
X						work = 1;
X						temp1[cc] = 1;
X					}
X				}
X			}
X		}
X	}
X
X	/* now, we have temp1[c] = 1 if a goto on c in closure of cc */
X
X#ifdef debug
X	if ( foutput != NULL ) {
X
X		fprintf( foutput, "%s: gotos on ", nontrst[c].name );
X		NTLOOP(i) if ( temp1[i] ) 
X			fprintf( foutput, "%s ", nontrst[i].name);
X		fprintf( foutput, "\n");
X	}
X#endif
X	/* now, go through and put gotos into tystate */
X
X	aryfil( tystate, nstate, 0 );
X	SLOOP(i)
X
X	 {
X		ITMLOOP(i, p, q)
X
X		 {
X			if ( (cc = *p->pitem) >= NTBASE ) {
X
X				if ( temp1[cc -= NTBASE] ) {
X
X					/* goto on c is possible */
X					tystate[i] = amem[indgo[i]+c];
X					break;
X				}
X			}
X		}
X	}
X}
X
X
SHAR_EOF
if test 1263 -ne "`wc -c < 'yg2gen.c'`"
then
echo shar: error transmitting "'yg2gen.c'" '(should have been 1263 characters)'
fi
chmod 644 yg2gen.c
fi
if test -f 'y4.h'
then
echo shar: will not over-write existing "'y4.h'"
else
echo extracting "'y4.h'"
sed 's/^X//' >y4.h <<'SHAR_EOF'
X/*****************************************************************************/
X/*                             *************                                 */
X/*                             *  Y 4 . H  *                                 */
X/*                             *************                                 */
X/*                                                                           */
X/* This file contains the external declarations needed to hook Yacc modules  */
X/* which were originally in Y4.C to their impure data in Y4IMP.4C. Also does */
X/* the include of the original data/external file DTXTRN.H.                  */
X/*                                                                           */
X/*****************************************************************************/
X
X# include "dtxtrn.h"
X
X# define a amem
X# define pa indgo
X# define yypact temp1
X# define greed tystate
X
X# define NOMORE -1000
X
Xextern int	*ggreed;
Xextern int	*pgo;
Xextern int	*yypgo;
X
Xextern int	maxspr;              /* maximum spread of any entry */
Xextern int	maxoff;              /* maximum offset into a array */
Xextern int	*pmem;
Xextern int	*maxa;
Xextern int	nxdb;
Xextern int	adb;
SHAR_EOF
if test 1184 -ne "`wc -c < 'y4.h'`"
then
echo shar: error transmitting "'y4.h'" '(should have been 1184 characters)'
fi
chmod 644 y4.h
fi
if test -f 'ycpfir.c'
then
echo shar: will not over-write existing "'ycpfir.c'"
else
echo extracting "'ycpfir.c'"
sed 's/^X//' >ycpfir.c <<'SHAR_EOF'
X/*
X * ycpfir.c - compute an array with the first of nonterminals
X *
X * HISTORY
X * {1}	28-Aug-81  Bob Denny
X * 	Modified to make debug code conditionally compile.
X * 
X */
X
X#include "y1.h"
X
X
X
Xint	cpfir()
X{
X	/* compute an array with the first of nonterminals */
X	register *p, **s, i, **t, ch, changes;
X
X	zzcwp = &wsets[nnonter];
X	NTLOOP(i) {
X		aryfil(wsets[i].ws.lset, tbitset, 0);
X		t = pres[i + 1];
X		for (s = pres[i]; s < t; ++s) {
X			/* initially fill the sets */
X			for (p = *s; (ch = *p) > 0; ++p) {
X				if (ch < NTBASE) {
X					SETBIT(wsets[i].ws.lset, ch);
X					break;
X				} else if (!pempty[ch - NTBASE])
X					break;
X			}
X		}
X	}
X
X	/* now, reflect transitivity */
X
X	changes = 1;
X	while (changes) {
X		changes = 0;
X		NTLOOP(i) {
X			t = pres[i + 1];
X			for (s = pres[i]; s < t; ++s) {
X				for (p = *s; (ch = (*p - NTBASE)) >= 0; ++p) {
X					changes |= setunion(wsets[i].ws.lset, wsets[ch].ws.lset);
X					if (!pempty[ch])
X						break;
X				}
X			}
X		}
X	}
X
X	NTLOOP(i) pfirst[i] = flset(&wsets[i].ws);
X#ifdef debug
X	if ((foutput != NULL)) {
X		NTLOOP(i) {
X			fprintf(foutput, "\n%s: ", nontrst[i].name);
X			prlook(pfirst[i]);
X			fprintf(foutput, " %d\n", pempty[i]);
X		}
X	}
X#endif
X}
X
X
SHAR_EOF
if test 1180 -ne "`wc -c < 'ycpfir.c'`"
then
echo shar: error transmitting "'ycpfir.c'" '(should have been 1180 characters)'
fi
chmod 644 ycpfir.c
fi
if test -f 'yg2out.c'
then
echo shar: will not over-write existing "'yg2out.c'"
else
echo extracting "'yg2out.c'"
sed 's/^X//' >yg2out.c <<'SHAR_EOF'
X#include "y3.h"
X
Xgo2out()
X{
X	/* output the gotos for the nontermninals */
X	int	i, j, k, best, count, cbest, times;
X
X	fprintf( ftemp, "$\n" );  /* mark begining of gotos */
X
X	for ( i = 1; i <= nnonter; ++i ) {
X		go2gen(i);
X
X		/* find the best one to make default */
X
X		best = -1;
X		times = 0;
X
X		for ( j = 0; j <= nstate; ++j ) {
X			/* is j the most frequent */
X			if ( tystate[j] == 0 ) 
X				continue;
X			if ( tystate[j] == best ) 
X				continue;
X
X			/* is tystate[j] the most frequent */
X
X			count = 0;
X			cbest = tystate[j];
X
X			for ( k = j; k <= nstate; ++k ) 
X				if ( tystate[k] == cbest ) 
X					++count;
X
X			if ( count > times ) {
X				best = cbest;
X				times = count;
X			}
X		}
X
X		/* best is now the default entry */
X
X		zzgobest += (times - 1);
X		for ( j = 0; j <= nstate; ++j ) {
X			if ( tystate[j] != 0 && tystate[j] != best ) {
X				fprintf( ftemp, "%d,%d,", j, tystate[j] );
X				zzgoent += 1;
X			}
X		}
X
X		/* now, the default */
X
X		zzgoent += 1;
X		fprintf( ftemp, "%d\n", best );
X
X	}
X}
X
X
SHAR_EOF
if test 994 -ne "`wc -c < 'yg2out.c'`"
then
echo shar: error transmitting "'yg2out.c'" '(should have been 994 characters)'
fi
chmod 644 yg2out.c
fi
if test -f 'ycpres.c'
then
echo shar: will not over-write existing "'ycpres.c'"
else
echo extracting "'ycpres.c'"
sed 's/^X//' >ycpres.c <<'SHAR_EOF'
X/*
X * ycpres.c - compute an array with the beginnings of productions
X *
X * compute an array with the beginnings of productions yielding given
X * nonterminals The array pres points to these lists the array pyield has
X * the lists:  the total size is only NPROD+1 
X *
X * HISTORY 
X * {1}  12-Apr-83 Bob Denny 
X *      Add symbol exit status.
X * 
X */
X
X#include "y1.h"
X
X
Xextern int	*pyield[NPROD];
X
X
Xint	cpres()
X{
X	register **pmem;
X	register c, j, i;
X
X	pmem = pyield;
X
X	NTLOOP(i) {
X		c = i + NTBASE;
X		pres[i] = pmem;
X		fatfl = 0;	/* make undefined  symbols  nonfatal */
X		PLOOP(0, j) {
X			if (*prdptr[j] == c)
X				*pmem++ = prdptr[j] + 1;
X		}
X		if (pres[i] == pmem) {
X			error("nonterminal %s not defined!", nontrst[i].name);
X		}
X	}
X	pres[i] = pmem;
X	fatfl = 1;
X	if (nerrors) {
X		summary();
X		exit(EX_ERR);
X	}
X	if (pmem != &pyield[nprod])
X		error("internal Yacc error: pyield %d", pmem - &pyield[nprod]);
X}
X
X
SHAR_EOF
if test 905 -ne "`wc -c < 'ycpres.c'`"
then
echo shar: error transmitting "'ycpres.c'" '(should have been 905 characters)'
fi
chmod 644 ycpres.c
fi
if test -f 'y3.h'
then
echo shar: will not over-write existing "'y3.h'"
else
echo extracting "'y3.h'"
sed 's/^X//' >y3.h <<'SHAR_EOF'
X/*****************************************************************************/
X/*                             *************                                 */
X/*                             *  Y 3 . H  *                                 */
X/*                             *************                                 */
X/*                                                                           */
X/* This file contains the external declarations needed to hook Yacc modules  */
X/* which were originally in Y3.C to their impure data in Y3IMP.3C. Also does */
X/* the include of the original data/external file DTXTRN.H.                  */
X/*                                                                           */
X/*****************************************************************************/
X
X#include "dtxtrn.h"
X
Xextern int	lastred;   /* the number of the last reduction of a state */
SHAR_EOF
if test 894 -ne "`wc -c < 'y3.h'`"
then
echo shar: error transmitting "'y3.h'" '(should have been 894 characters)'
fi
chmod 644 y3.h
fi
if test -f 'ygin.c'
then
echo shar: will not over-write existing "'ygin.c'"
else
echo extracting "'ygin.c'"
sed 's/^X//' >ygin.c <<'SHAR_EOF'
X#include "y4.h"
X
Xgin(i)
X{
X
X	register *p, *r, *s, *q1, *q2;
X
X	/* enter gotos on nonterminal i into array a */
X
X	ggreed[i] = 0;
X
X	q2 = mem0 + yypgo[i+1] - 1;
X	q1 = mem0 + yypgo[i];
X
X	/* now, find a place for it */
X
X	for ( p = a; p < &a[ACTSIZE]; ++p ) {
X		if ( *p ) 
X			continue;
X		for ( r = q1; r < q2; r += 2 ) {
X			s = p + *r + 1;
X			if ( *s ) 
X				goto nextgp;
X			if ( s > maxa ) {
X				if ( (maxa = s) > &a[ACTSIZE] ) 
X					error( "a array overflow" );
X			}
X		}
X		/* we have found a spot */
X
X		*p = *q2;
X		if ( p > maxa ) {
X			if ( (maxa = p) > &a[ACTSIZE] ) 
X				error( "a array overflow" );
X		}
X		for ( r = q1; r < q2; r += 2 ) {
X			s = p + *r + 1;
X			*s = r[1];
X		}
X
X		pgo[i] = p - a;
X		if ( adb > 1 ) 
X			fprintf( ftable, "Nonterminal %d, entry at %d\n" , i, pgo[i] );
X		goto nextgi;
X
Xnextgp:
X		;
X	}
X
X	error( "cannot place goto %d\n", i );
X
Xnextgi:
X	;
X}
X
X
SHAR_EOF
if test 862 -ne "`wc -c < 'ygin.c'`"
then
echo shar: error transmitting "'ygin.c'" '(should have been 862 characters)'
fi
chmod 644 ygin.c
fi
if test -f 'ymain.c'
then
echo shar: will not over-write existing "'ymain.c'"
else
echo extracting "'ymain.c'"
sed 's/^X//' >ymain.c <<'SHAR_EOF'
X#include "y1.h"
X/*
X * 12-Apr-83 (RBD) Add symbolic exit status
X */
Xmain(argc, argv) 
Xint	argc;
Xchar	*argv[];
X
X{
X
X	puts("Setup...");
X	setup(argc, argv); /* initialize and read productions */
X	puts("cpres ...");
X	tbitset = NWORDS(ntokens);
X	cpres(); /* make table of which productions yield a given nonterminal */
X	puts("cempty ...");
X	cempty(); /* make a table of which nonterminals can match the empty string */
X	puts("cpfir ...");
X	cpfir(); /* make a table of firsts of nonterminals */
X	puts("stagen ...");
X	stagen(); /* generate the states */
X	puts("output ...");
X	output();  /* write the states and the tables */
X	puts("go2out ...");
X	go2out();
X	puts("hideprod ...");
X	hideprod();
X	puts("summary ...");
X	summary();
X	puts("callopt ...");
X	callopt();
X	puts("others ...");
X	others();
X	puts("DONE !!!");
X	exit(EX_SUC);
X}
X
X
SHAR_EOF
if test 822 -ne "`wc -c < 'ymain.c'`"
then
echo shar: error transmitting "'ymain.c'" '(should have been 822 characters)'
fi
chmod 644 ymain.c
fi
if test -f 'yprcft.c'
then
echo shar: will not over-write existing "'yprcft.c'"
else
echo extracting "'yprcft.c'"
sed 's/^X//' >yprcft.c <<'SHAR_EOF'
X#include "y3.h"
X
Xprecftn(r, t, s)
X{
X	/* decide a shift/reduce conflict by precedence.*/
X	/* r is a rule number, t a token number */
X	/* the conflict is in state s */
X	/* temp1[t] is changed to reflect the action */
X
X	int	lp, lt, action;
X
X	lp = levprd[r];
X	lt = toklev[t];
X	if ( PLEVEL(lt) == 0 || PLEVEL(lp) == 0 ) {
X		/* conflict */
X		if ( foutput != NULL ) 
X			fprintf( foutput, "\n%d: shift/reduce conflict (shift %d, red'n %d) on %s",
X			    s, temp1[t], r, symnam(t) );
X		++zzsrconf;
X		return;
X	}
X	if ( PLEVEL(lt) == PLEVEL(lp) ) 
X		action = ASSOC(lt);
X	else if ( PLEVEL(lt) > PLEVEL(lp) ) 
X		action = RASC;  /* shift */
X	else 
X		action = LASC;  /* reduce */
X
X	switch ( action ) {
X
X	case BASC:  /* error action */
X		temp1[t] = ERRCODE;
X		return;
X
X	case LASC:  /* reduce */
X		temp1[t] = -r;
X		return;
X
X	}
X}
X
X
SHAR_EOF
if test 813 -ne "`wc -c < 'yprcft.c'`"
then
echo shar: error transmitting "'yprcft.c'" '(should have been 813 characters)'
fi
chmod 644 yprcft.c
fi
if test -f 'ycpuni.c'
then
echo shar: will not over-write existing "'ycpuni.c'"
else
echo extracting "'ycpuni.c'"
sed 's/^X//' >ycpuni.c <<'SHAR_EOF'
X/*
X * ycpuni.c - copy the union declaration & define file (if present) to output
X *
X * HISTORY
X */
X
X#include "y2.h"
X
Xint	cpyunion()
X{
X	int	level, c;
X	fprintf(ftable, "\n# line %d\n", lineno);
X	fprintf(ftable, "\n#define UNION 1\n");
X	fprintf(ftable, "typedef union ");
X	if (fdefine)
X		fprintf(fdefine, "\ntypedef union ");
X
X	level = 0;
X	for (; ; ) {
X		if ((c = unix_getc(finput)) < 0)
X			error("EOF encountered while processing %%union");
X		putc(c, ftable);
X		if (fdefine)
X			putc(c, fdefine);
X
X		switch (c) {
X
X		case '\n':
X			++lineno;
X			break;
X
X		case '{':
X			++level;
X			break;
X
X		case '}':
X			--level;
X			if (level == 0) {
X				/* we are finished copying */
X				fprintf(ftable, " YYSTYPE;\n");
X				if (fdefine)
X					fprintf(fdefine, " YYSTYPE;\nextern YYSTYPE yylval;\n");
X				return;
X			}
X		}
X	}
X}
X
X
SHAR_EOF
if test 805 -ne "`wc -c < 'ycpuni.c'`"
then
echo shar: error transmitting "'ycpuni.c'" '(should have been 805 characters)'
fi
chmod 644 ycpuni.c
fi
if test -f 'ydfout.c'
then
echo shar: will not over-write existing "'ydfout.c'"
else
echo extracting "'ydfout.c'"
sed 's/^X//' >ydfout.c <<'SHAR_EOF'
X/*
X * ydfout.c -
X *
X * HISTORY
X */
X
X#include <ctype.h>
X#include "y2.h"
X
Xint	defout()
X{
X	/* write out the defines (at the end of the declaration section) */
X
X	register int	i, c;
X	register char	*cp;
X
X	for (i = ndefout; i <= ntokens; ++i) {
X
X		cp = tokset[i].name;
X		if (*cp == ' ')
X			++cp;	/* literals */
X
X		for (; (c = *cp) != '\0'; ++cp) {
X
X			if (islower(c) || isupper(c) || isdigit(c) || c == '_')
X				;	/* VOID */
X			else
X				goto nodef;
X		}
X
X		fprintf(ftable, "# define %s %d\n", tokset[i].name, tokset[i].value);
X		if (fdefine != NULL)
X			fprintf(fdefine, "# define %s %d\n", tokset[i].name, tokset[i].value);
X
Xnodef:
X		;
X	}
X
X	ndefout = ntokens + 1;
X
X}
X
X
SHAR_EOF
if test 661 -ne "`wc -c < 'ydfout.c'`"
then
echo shar: error transmitting "'ydfout.c'" '(should have been 661 characters)'
fi
chmod 644 ydfout.c
fi
if test -f 'ywritm.c'
then
echo shar: will not over-write existing "'ywritm.c'"
else
echo extracting "'ywritm.c'"
sed 's/^X//' >ywritm.c <<'SHAR_EOF'
X/*
X * ywritm.c -
X *
X * HISTORY
X */
X
X#include "y1.h"
X
Xextern char	sarr[ISIZE];
X
Xchar	*chcopy();
X
Xchar	*writem(pp)
Xint	*pp;
X{
X	/* creates output string for item pointed to by pp */
X	int	i, *p;
X	char	*q;
X
X	for (p = pp; *p > 0; ++p)
X		;
X	p = prdptr[-*p];
X	q = chcopy(sarr, nontrst[*p - NTBASE].name);
X	q = chcopy(q, " : ");
X
X	for (; ; ) {
X		*q++ = ++p == pp ? '_' : ' ';
X		*q = '\0';
X		if ((i = *p) <= 0)
X			break;
X		q = chcopy(q, symnam(i));
X		if (q > &sarr[ISIZE - 30])
X			error("item too big");
X	}
X
X	if ((i = *pp) < 0) {
X		/* an item calling for a reduction */
X		q = chcopy(q, "    (");
X		sprintf(q, "%d)", -i);
X	}
X	return (sarr);
X}
X
X
SHAR_EOF
if test 634 -ne "`wc -c < 'ywritm.c'`"
then
echo shar: error transmitting "'ywritm.c'" '(should have been 634 characters)'
fi
chmod 644 ywritm.c
fi
if test -f 'yflset.c'
then
echo shar: will not over-write existing "'yflset.c'"
else
echo extracting "'yflset.c'"
sed 's/^X//' >yflset.c <<'SHAR_EOF'
X#include "y1.h"
X
Xstruct looksets *flset( p )   
Xstruct looksets *p;
X
X{
X	/* decide if the lookahead set pointed to by p is known */
X	/* return pointer to a perminent location for the set */
X
X	register struct looksets *q;
X	int	j, *w;
X	register *u, *v;
X
X	for ( q = &lkst[nlset]; q-- > lkst; ) {
X		u = p->lset;
X		v = q->lset;
X		w = &v[tbitset];
X		while ( v < w) 
X			if ( *u++ != *v++) 
X				goto more;
X		/* we have matched */
X		return( q );
Xmore:
X		;
X	}
X	/* add a new one */
X	q = &lkst[nlset++];
X	if ( nlset >= LSETSIZE )
X		error("too many lookahead sets" );
X	SETLOOP(j)
X	 {
X		q->lset[j] = p->lset[j];
X	}
X	return( q );
X}
X
X
SHAR_EOF
if test 618 -ne "`wc -c < 'yflset.c'`"
then
echo shar: error transmitting "'yflset.c'" '(should have been 618 characters)'
fi
chmod 644 yflset.c
fi
if test -f 'yhdprd.c'
then
echo shar: will not over-write existing "'yhdprd.c'"
else
echo extracting "'yhdprd.c'"
sed 's/^X//' >yhdprd.c <<'SHAR_EOF'
X#include "y3.h"
X
Xhideprod()
X{
X	/* in order to free up the mem and amem arrays for the optimizer,
X        /* and still be able to output yyr1, etc., after the sizes of
X        /* the action array is known, we hide the nonterminals
X        /* derived by productions in levprd.
X        */
X
X	register i, j;
X
X	j = 0;
X	levprd[0] = 0;
X	PLOOP(1, i)
X	 {
X		if ( !(levprd[i] & REDFLAG) ) {
X			++j;
X			if ( foutput != NULL ) {
X				fprintf( foutput, "Rule not reduced:   %s\n", writem( prdptr[i] ) );
X			}
X		}
X		levprd[i] = *prdptr[i] - NTBASE;
X	}
X	if ( j ) 
X		fprintf( stdout, "%d rules never reduced\n", j );
X}
X
X
SHAR_EOF
if test 602 -ne "`wc -c < 'yhdprd.c'`"
then
echo shar: error transmitting "'yhdprd.c'" '(should have been 602 characters)'
fi
chmod 644 yhdprd.c
fi
if test -f 'yptitm.c'
then
echo shar: will not over-write existing "'yptitm.c'"
else
echo extracting "'yptitm.c'"
sed 's/^X//' >yptitm.c <<'SHAR_EOF'
X#include "y1.h"
X
X/*
X * yptitm.1c
X *
X * Modified to make debug code conditionally compile.
X * 28-Aug-81
X * Bob Denny
X */
X
Xputitem( ptr, lptr )  
Xint	*ptr;
Xstruct looksets *lptr;
X
X
X{
X	register struct item *j;
X
X#ifdef debug
X	if ( foutput != NULL ) {
X
X		fprintf( foutput, "putitem(%s), state %d\n", writem(ptr), nstate );
X	}
X#endif
X	j = pstate[nstate+1];
X	j->pitem = ptr;
X	if ( !nolook ) 
X		j->look = flset( lptr );
X	pstate[nstate+1] = ++j;
X	if ( (int *)j > zzmemsz ) {
X
X		zzmemsz = (int *)j;
X		if ( zzmemsz >=  &mem0[MEMSIZE] ) 
X			error( "out of state space" );
X	}
X}
X
X
SHAR_EOF
if test 567 -ne "`wc -c < 'yptitm.c'`"
then
echo shar: error transmitting "'yptitm.c'" '(should have been 567 characters)'
fi
chmod 644 yptitm.c
fi
if test -f 'ycpycd.c'
then
echo shar: will not over-write existing "'ycpycd.c'"
else
echo extracting "'ycpycd.c'"
sed 's/^X//' >ycpycd.c <<'SHAR_EOF'
X/*
X * ycpycd.c - copies code between \{ and \}
X *
X * HISTORY
X */
X
X#include "y2.h"
X
X
Xint	cpycode()
X{
X	int	c;
X
X	c = unix_getc(finput);
X	if (c == '\n') {
X		c = unix_getc(finput);
X		lineno++;
X	}
X	fprintf(ftable, "\n# line %d\n", lineno);
X	while (c >= 0) {
X		if (c == '\\')
X			if ((c = unix_getc(finput)) == '}')
X				return;
X			else
X				putc('\\', ftable);
X		if (c == '%')
X			if ((c = unix_getc(finput)) == '}')
X				return;
X			else
X				putc('%', ftable);
X		putc(c, ftable);
X		if (c == '\n')
X			++lineno;
X		c = unix_getc(finput);
X	}
X	error("eof before %%}");
X}
X
X
SHAR_EOF
if test 557 -ne "`wc -c < 'ycpycd.c'`"
then
echo shar: error transmitting "'ycpycd.c'" '(should have been 557 characters)'
fi
chmod 644 ycpycd.c
fi
if test -f 'ygtnm.c'
then
echo shar: will not over-write existing "'ygtnm.c'"
else
echo extracting "'ygtnm.c'"
sed 's/^X//' >ygtnm.c <<'SHAR_EOF'
X/*
X * ygtnm.c -
X *
X * HISTORY
X */
X
X#include <ctype.h>
X#include "y4.h"
X
Xint	gtnm()
X{
X
X	register s, val, c;
X
X	/* read and convert an integer from the standard input */
X	/* return the terminating character */
X	/* blanks, tabs, and newlines are ignored */
X
X	s = 1;
X	val = 0;
X
X	while ((c = unix_getc(finput)) != EOF) {
X		if (isdigit(c)) {
X			val = val * 10 + c - '0';
X		} else if (c == '-')
X			s = -1;
X		else if (c == '\r')
X			continue;
X		else
X			break;
X	}
X	*pmem++ = s * val;
X	if (pmem > &mem0[MEMSIZE])
X		error("out of space");
X	return (c);
X}
X
X
SHAR_EOF
if test 542 -ne "`wc -c < 'ygtnm.c'`"
then
echo shar: error transmitting "'ygtnm.c'" '(should have been 542 characters)'
fi
chmod 644 ygtnm.c
fi
if test -f 'yskpcm.c'
then
echo shar: will not over-write existing "'yskpcm.c'"
else
echo extracting "'yskpcm.c'"
sed 's/^X//' >yskpcm.c <<'SHAR_EOF'
X#include "y2.h"
X
Xskipcom()
X{
X	/* skip over comments */
X	register c, i;  /* i is the number of lines skipped */
X	i = 0;                                                         /*01*/
X	/* skipcom is called after reading a / */
X
X	if ( unix_getc(finput) != '*' ) 
X		error( "illegal comment" );
X	c = unix_getc(finput);
X	while ( c != EOF ) {
X		while ( c == '*' ) {
X			if ( (c = unix_getc(finput)) == '/' ) 
X				return( i );
X		}
X		if ( c == '\n' ) 
X			++i;
X		c = unix_getc(finput);
X	}
X	error( "EOF inside comment" );
X	/* NOTREACHED */
X}
X
X
SHAR_EOF
if test 532 -ne "`wc -c < 'yskpcm.c'`"
then
echo shar: error transmitting "'yskpcm.c'" '(should have been 532 characters)'
fi
chmod 644 yskpcm.c
fi
if test -f 'yosmry.c'
then
echo shar: will not over-write existing "'yosmry.c'"
else
echo extracting "'yosmry.c'"
sed 's/^X//' >yosmry.c <<'SHAR_EOF'
X#include "y4.h"
X
X/*
X * Write summary.
X */
X
Xosummary()
X
X{
X	register int	i, *p;
X
X	if (foutput == NULL) 
X		return;
X
X	i = 0;
X	for (p = maxa; p >= a; --p) {
X
X		if (*p == 0) 
X			++i;
X	}
X	fprintf(foutput, "Optimizer space used: input %d/%d, output %d/%d\n",
X	    pmem - mem0 + 1, MEMSIZE, maxa - a + 1, ACTSIZE);
X	fprintf(foutput, "%d table entries, %d zero\n", (maxa - a) + 1, i);
X	fprintf(foutput, "maximum spread: %d, maximum offset: %d\n", maxspr, maxoff);
X	fclose(foutput);
X}
X
X
SHAR_EOF
if test 476 -ne "`wc -c < 'yosmry.c'`"
then
echo shar: error transmitting "'yosmry.c'" '(should have been 476 characters)'
fi
chmod 644 yosmry.c
fi
if test -f 'y4imp.c'
then
echo shar: will not over-write existing "'y4imp.c'"
else
echo extracting "'y4imp.c'"
sed 's/^X//' >y4imp.c <<'SHAR_EOF'
X/* 
X * y4imp.c - impure data from y4.c modules
X *
X * HISTORY
X */
X
X# include "dtxtrn.h"
X
X# define a amem
X# define pa indgo
X# define yypact temp1
X# define greed tystate
X
X# define NOMORE -1000
X
Xint	*ggreed = lkst[0].lset;
Xint	*pgo = wsets[0].ws.lset;
Xint	*yypgo = &nontrst[0].tvalue;
X
Xint	maxspr = 0;		/* maximum spread of any entry */
Xint	maxoff = 0;		/* maximum offset into a array */
Xint	*pmem = mem0;
Xint	*maxa;
Xint	nxdb = 0;
Xint	adb = 0;
SHAR_EOF
if test 440 -ne "`wc -c < 'y4imp.c'`"
then
echo shar: error transmitting "'y4imp.c'" '(should have been 440 characters)'
fi
chmod 644 y4imp.c
fi
if test -f 'ynxti.c'
then
echo shar: will not over-write existing "'ynxti.c'"
else
echo extracting "'ynxti.c'"
sed 's/^X//' >ynxti.c <<'SHAR_EOF'
X#include "y4.h"
X
Xnxti()
X{
X	/* finds the next i */
X	register i, max, maxi;
X
X	max = 0;
X
X	for ( i = 1; i <= nnonter; ++i ) 
X		if ( ggreed[i] >= max ) {
X			max = ggreed[i];
X			maxi = -i;
X		}
X
X	for ( i = 0; i < nstate; ++i ) 
X		if ( greed[i] >= max ) {
X			max = greed[i];
X			maxi = i;
X		}
X
X	if ( nxdb ) 
X		fprintf( ftable, "nxti = %d, max = %d\n", maxi, max );
X	if ( max == 0 ) 
X		return( NOMORE );
X	else 
X		return( maxi );
X}
X
X
SHAR_EOF
if test 423 -ne "`wc -c < 'ynxti.c'`"
then
echo shar: error transmitting "'ynxti.c'" '(should have been 423 characters)'
fi
chmod 644 ynxti.c
fi
if test -f 'ychfnd.c'
then
echo shar: will not over-write existing "'ychfnd.c'"
else
echo extracting "'ychfnd.c'"
sed 's/^X//' >ychfnd.c <<'SHAR_EOF'
X/*
X * ychfnd.c -
X *
X * HISTORY
X */
X
X#include "y2.h"
X
X
Xint	chfind( t, s )
Xregister char	*s;
X{
X	int	i;
X
X	if (s[0] == ' ')
X		t = 0;
X	TLOOP(i) {
X		if (!strcmp(s, tokset[i].name)) {
X			return (i);
X		}
X	}
X	NTLOOP(i) {
X		if (!strcmp(s, nontrst[i].name)) {
X			return (i + NTBASE);
X		}
X	}
X	/* cannot find name */
X	if (t > 1)
X		error("%s should have been defined earlier", s);
X	return (defin(t, s));
X}
X
X
SHAR_EOF
if test 394 -ne "`wc -c < 'ychfnd.c'`"
then
echo shar: error transmitting "'ychfnd.c'" '(should have been 394 characters)'
fi
chmod 644 ychfnd.c
fi
if test -f 'yyless.c'
then
echo shar: will not over-write existing "'yyless.c'"
else
echo extracting "'yyless.c'"
sed 's/^X//' >yyless.c <<'SHAR_EOF'
Xyyless(x)
X
X{
X	extern char	yytext[];
X	register char	*lastch, *ptr;
X	extern int	yyleng;
X	extern int	yyprevious;
X	lastch = yytext + yyleng;
X	if (x >= 0 && x <= yyleng)
X		ptr = x + yytext;
X	else
X		ptr = x;
X	while (lastch > ptr)
X		yyunput(*--lastch);
X	*lastch = 0;
X	if (ptr > yytext)
X		yyprevious = *--lastch;
X	yyleng = ptr - yytext;
X}
X
X
SHAR_EOF
if test 333 -ne "`wc -c < 'yyless.c'`"
then
echo shar: error transmitting "'yyless.c'" '(should have been 333 characters)'
fi
chmod 644 yyless.c
fi
if test -f 'yarout.c'
then
echo shar: will not over-write existing "'yarout.c'"
else
echo extracting "'yarout.c'"
sed 's/^X//' >yarout.c <<'SHAR_EOF'
X/*
X * yarout.c - 
X *
X * HISTORY
X */
X
X#include "y4.h"
X
Xint	arout(s, v, n)
Xchar	*s;
Xint	*v, n;
X{
X	register i;
X
X	fprintf(ftable, "short %s[]={\n", s);
X	for (i = 0; i < n; ) {
X		if (i % 10 == 0)
X			fprintf(ftable, "\n");
X		fprintf(ftable, "%4d", v[i]);
X		if (++i == n)
X			fprintf(ftable, " };\n");
X		else
X			fprintf(ftable, ",");
X	}
X}
X
X
SHAR_EOF
if test 333 -ne "`wc -c < 'yarout.c'`"
then
echo shar: error transmitting "'yarout.c'" '(should have been 333 characters)'
fi
chmod 644 yarout.c
fi
if test -f 'yerror.c'
then
echo shar: will not over-write existing "'yerror.c'"
else
echo extracting "'yerror.c'"
sed 's/^X//' >yerror.c <<'SHAR_EOF'
X#include "y1.h"
X
X/*
X * 12-Apr-83 (RBD) Add symbolic exit status
X */
X/* VARARGS1 */
Xerror(s, a1) 
Xchar	*s;
X
X{
X	/* write out error comment */
X
X	++nerrors;
X	fprintf( stderr, "\n fatal error: ");
X	fprintf( stderr, s, a1);
X	fprintf( stderr, ", line %d\n", lineno );
X	if ( !fatfl ) 
X		return;
X	summary();
X	exit(EX_ERR);
X}
X
X
SHAR_EOF
if test 318 -ne "`wc -c < 'yerror.c'`"
then
echo shar: error transmitting "'yerror.c'" '(should have been 318 characters)'
fi
chmod 644 yerror.c
fi
if test -f 'ywarry.c'
then
echo shar: will not over-write existing "'ywarry.c'"
else
echo extracting "'ywarry.c'"
sed 's/^X//' >ywarry.c <<'SHAR_EOF'
X#include "y3.h"
X
Xwarray( s, v, n ) 
Xchar	*s;
Xint	*v, n;
X
X{
X
X	register i;
X
X	fprintf( ftable, "short %s[]={\n", s );
X	for ( i = 0; i < n; ) {
X		if ( i % 10 == 0 ) 
X			fprintf( ftable, "\n" );
X		fprintf( ftable, "%4d", v[i] );
X		if ( ++i == n ) 
X			fprintf( ftable, " };\n" );
X		else 
X			fprintf( ftable, "," );
X	}
X}
X
X
SHAR_EOF
if test 316 -ne "`wc -c < 'ywarry.c'`"
then
echo shar: error transmitting "'ywarry.c'" '(should have been 316 characters)'
fi
chmod 644 ywarry.c
fi
if test -f 'yfdtyp.c'
then
echo shar: will not over-write existing "'yfdtyp.c'"
else
echo extracting "'yfdtyp.c'"
sed 's/^X//' >yfdtyp.c <<'SHAR_EOF'
X#include "y2.h"
X
Xfdtype( t )
X{
X	/* determine the type of a symbol */
X	register v;
X	if ( t >= NTBASE ) 
X		v = nontrst[t-NTBASE].tvalue;
X	else 
X		v = TYPE( toklev[t] );
X	if ( v <= 0 ) 
X		error( "must specify type for %s", (t >= NTBASE) ? nontrst[t-NTBASE].name : 
X		    tokset[t].name );
X	return( v );
X}
X
X
SHAR_EOF
if test 304 -ne "`wc -c < 'yfdtyp.c'`"
then
echo shar: error transmitting "'yfdtyp.c'" '(should have been 304 characters)'
fi
chmod 644 yfdtyp.c
fi
if test -f 'yprlok.c'
then
echo shar: will not over-write existing "'yprlok.c'"
else
echo extracting "'yprlok.c'"
sed 's/^X//' >yprlok.c <<'SHAR_EOF'
X#include "y1.h"
X
Xprlook( p ) 
Xstruct looksets *p;
X
X{
X	register j, *pp;
X	pp = p->lset;
X	if ( pp == 0 ) 
X		fprintf( foutput, "\tNULL");
X	else      {
X		fprintf( foutput, " { " );
X		TLOOP(j)
X		 {
X			if ( BIT(pp, j) ) 
X				fprintf( foutput,  "%s ", symnam(j) );
X		}
X		fprintf( foutput,  "}" );
X	}
X}
X
X
SHAR_EOF
if test 296 -ne "`wc -c < 'yprlok.c'`"
then
echo shar: error transmitting "'yprlok.c'" '(should have been 296 characters)'
fi
chmod 644 yprlok.c
fi
if test -f 'ystuni.c'
then
echo shar: will not over-write existing "'ystuni.c'"
else
echo extracting "'ystuni.c'"
sed 's/^X//' >ystuni.c <<'SHAR_EOF'
X#include "y1.h"
X
Xsetunion( a, b ) 
Xregister *a, *b;
X
X{
X	/* set a to the union of a and b */
X	/* return 1 if b is not a subset of a, 0 otherwise */
X	register i, x, sub;
X
X	sub = 0;
X	SETLOOP(i)
X	 {
X		*a = (x = *a) | *b++;
X		if ( *a++ != x ) 
X			sub = 1;
X	}
X	return( sub );
X}
X
X
SHAR_EOF
if test 274 -ne "`wc -c < 'ystuni.c'`"
then
echo shar: error transmitting "'ystuni.c'" '(should have been 274 characters)'
fi
chmod 644 ystuni.c
fi
if test -f 'yaoput.c'
then
echo shar: will not over-write existing "'yaoput.c'"
else
echo extracting "'yaoput.c'"
sed 's/^X//' >yaoput.c <<'SHAR_EOF'
X/*
X * yaoput.c - write out the optimized parser
X *
X * HISTORY
X */
X
X#include "y4.h"
X
Xint	aoutput()
X{
X	fprintf(ftable, "# define YYLAST %d\n", maxa - a + 1);
X	arout("yyact", a, (maxa - a) + 1);
X	arout("yypact", pa, nstate);
X	arout("yypgo", pgo, nnonter + 1);
X}
X
X
SHAR_EOF
if test 261 -ne "`wc -c < 'yaoput.c'`"
then
echo shar: error transmitting "'yaoput.c'" '(should have been 261 characters)'
fi
chmod 644 yaoput.c
fi
if test -f 'y3imp.c'
then
echo shar: will not over-write existing "'y3imp.c'"
else
echo extracting "'y3imp.c'"
sed 's/^X//' >y3imp.c <<'SHAR_EOF'
X/* 
X * y3imp.c - impure data from modules split from y3.c 
X *
X * HISTORY
X */
X
X#define y3imp YES
X
X#include "dtxtrn.h"
X
Xint	lastred;            /* the number of the last reduction of a state */
X
Xint	defact[NSTATES];    /* the default actions of states */
SHAR_EOF
if test 253 -ne "`wc -c < 'y3imp.c'`"
then
echo shar: error transmitting "'y3imp.c'" '(should have been 253 characters)'
fi
chmod 644 y3imp.c
fi
if test -f 'ycstsh.c'
then
echo shar: will not over-write existing "'ycstsh.c'"
else
echo extracting "'ycstsh.c'"
sed 's/^X//' >ycstsh.c <<'SHAR_EOF'
X#include "y2.h"
Xchar	*
Xcstash( s ) 
Xregister char	*s;
X
X{
X	char	*temp;
X
X	temp = cnamp;
X	do 
X	 {
X		if ( cnamp >= &cnames[cnamsz] ) 
X			error("too many characters in id's and literals" );
X		else 
X			*cnamp++ = *s;
X	} while ( *s++);
X	return( temp );
X}
X
X
SHAR_EOF
if test 250 -ne "`wc -c < 'ycstsh.c'`"
then
echo shar: error transmitting "'ycstsh.c'" '(should have been 250 characters)'
fi
chmod 644 ycstsh.c
fi
if test -f 'ysmnam.c'
then
echo shar: will not over-write existing "'ysmnam.c'"
else
echo extracting "'ysmnam.c'"
sed 's/^X//' >ysmnam.c <<'SHAR_EOF'
X#include "y1.h"
X
Xchar	*symnam(i)
X{
X	/* return a pointer to the name of symbol i */
X	char	*cp;
X
X	cp = (i >= NTBASE) ? nontrst[i-NTBASE].name : tokset[i].name ;
X	if ( *cp == ' ' ) 
X		++cp;
X	return( cp );
X}
X
X
SHAR_EOF
if test 206 -ne "`wc -c < 'ysmnam.c'`"
then
echo shar: error transmitting "'ysmnam.c'" '(should have been 206 characters)'
fi
chmod 644 ysmnam.c
fi
if test -f 'yaryfl.c'
then
echo shar: will not over-write existing "'yaryfl.c'"
else
echo extracting "'yaryfl.c'"
sed 's/^X//' >yaryfl.c <<'SHAR_EOF'
X/*
X * yaryfl.c  - set elements 0 through n-1 to c
X *
X * HISTORY
X */
X
X#include "y1.h"
X
X
Xint	aryfil(v, n, c)
Xint	*v, n, c;
X{
X	register int	i;
X
X	for (i = 0; i < n; ++i)
X		v[i] = c;
X}
X
X
SHAR_EOF
if test 182 -ne "`wc -c < 'yaryfl.c'`"
then
echo shar: error transmitting "'yaryfl.c'" '(should have been 182 characters)'
fi
chmod 644 yaryfl.c
fi
if test -f 'ychcpy.c'
then
echo shar: will not over-write existing "'ychcpy.c'"
else
echo extracting "'ychcpy.c'"
sed 's/^X//' >ychcpy.c <<'SHAR_EOF'
X/*
X * ychcpy.c - copies string q into p, return next free char ptr
X *
X * HISTORY
X */
X
X#include "y1.h"
X
Xchar	*chcopy(p, q)
Xchar	*p, *q;
X{
X	while (*p = *q++)
X		++p;
X	return (p);
X}
X
X
SHAR_EOF
if test 180 -ne "`wc -c < 'ychcpy.c'`"
then
echo shar: error transmitting "'ychcpy.c'" '(should have been 180 characters)'
fi
chmod 644 ychcpy.c
fi
if test -f 'yfnact.c'
then
echo shar: will not over-write existing "'yfnact.c'"
else
echo extracting "'yfnact.c'"
sed 's/^X//' >yfnact.c <<'SHAR_EOF'
X#include "y2.h"
X
Xfinact()
X{
X	/* finish action routine */
X
X	fclose(faction);
X
X	fprintf( ftable, "# define YYERRCODE %d\n", tokset[2].value );
X
X}
X
X
SHAR_EOF
if test 146 -ne "`wc -c < 'yfnact.c'`"
then
echo shar: error transmitting "'yfnact.c'" '(should have been 146 characters)'
fi
chmod 644 yfnact.c
fi
# end of shell archive
exit 0