---------------------------------- 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
#
#
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