+#ifndef _DEXTERN_H_
+#define _DEXTERN_H_
+
+#include <stdio.h>
+#include <sys/file.h>
+#include "files.h"
+
/*
* @(#)dextern 4.2 (Berkeley) 3/21/86
*/
-# include <stdio.h>
-# include <ctype.h>
-# include "files.h"
+/*# include <stdio.h>*/
+/*# include <ctype.h>*/
+/*# include "files.h"*/
/* MANIFEST CONSTANT DEFINITIONS */
extern int zzsrconf ;
/* define functions with strange types... */
-extern char *cstash();
-extern struct looksets *flset();
-extern char *symnam();
-extern char *writem();
+/*extern char *cstash();*/
+/*extern struct looksets *flset();*/
+/*extern char *symnam();*/
+/*extern char *writem();*/
/* default settings for a number of macros */
# ifndef ZAPFILE
# define ZAPFILE(x) unlink(x)
# endif
+
+#ifndef __P
+#ifdef __STDC__
+#define __P(args) args
+#else
+#define __P(args) ()
+#endif
+#endif
+
+/* y1.c */
+int main __P((int argc, char *argv[]));
+int others __P((void));
+char *chcopy __P((char *p, char *q));
+char *writem __P((int *pp));
+char *symnam __P((int i));
+int summary __P((void));
+int error __P((char *s, ...));
+int aryfil __P((int *v, int n, int c));
+int setunion __P((register *a, register *b));
+int prlook __P((struct looksets *p));
+int cpres __P((void));
+int cpfir __P((void));
+int state __P((int c));
+int putitem __P((int *ptr, struct looksets *lptr));
+int cempty __P((void));
+int stagen __P((void));
+int closure __P((int i));
+struct looksets *flset __P((struct looksets *p));
+
+/* y2.c */
+int setup __P((int argc, char *argv[]));
+int finact __P((void));
+int defin __P((int t, register char *s));
+int defout __P((void));
+char *cstash __P((register char *s));
+int gettok __P((void));
+int fdtype __P((int t));
+int chfind __P((int t, register char *s));
+int cpyunion __P((void));
+int cpycode __P((void));
+int skipcom __P((void));
+int cpyact __P((int offset));
+
+/* y3.c */
+int output __P((void));
+int apack __P((int *p, int n));
+int go2out __P((void));
+int go2gen __P((int c));
+int precftn __P((int r, int t, int s));
+int wract __P((int i));
+int wrstate __P((int i));
+int wdef __P((char *s, int n));
+int warray __P((char *s, int *v, int n));
+int hideprod __P((void));
+
+/* y4.c */
+int callopt __P((void));
+int gin __P((int i));
+int stin __P((int i));
+int nxti __P((void));
+int osummary __P((void));
+int aoutput __P((void));
+int arout __P((char *s, int *v, int n));
+int gtnm __P((void));
+
+#endif
+#ifndef _FILES_H_
+#define _FILES_H_
+
/*
* @(#)files 4.1 (Berkeley) 83/02/11
*/
/* basic size of the Yacc implementation */
# define HUGE
+
+#endif
-#ifndef lint
+/*#include <stdio.h> dextern.h*/
+#ifdef __STDC__
+#include <stdarg.h>
+#define _va_start(argp, arg) va_start(argp, arg)
+#else
+#include <varargs.h>
+#define _va_start(argp, arg) va_start(argp)
+#endif
+#include "dextern.h"
+/*#include "files.h" dextern.h*/
+
+#if defined(DOSCCS) && !defined(lint)
static char sccsid[] = "@(#)y1.c 4.1 (Berkeley) 2/11/83";
-#endif not lint
+#endif
-# include <varargs.h>
-# include "dextern.h"
+/*# include <varargs.h>*/
+/*# include "dextern.h"*/
/* variables used locally */
struct looksets *pfirst[NNONTERM+2]; /* vector of pointers to first sets for each nonterminal */
int pempty[NNONTERM+1]; /* vector of nonterminals nontrivially deriving e */
-main(argc,argv) int argc; char *argv[]; {
+int main(argc, argv) int argc; char *argv[]; {
setup(argc,argv); /* initialize and read productions */
tbitset = NWORDS(ntokens);
exit(0);
}
-others(){ /* put out other arrays, copy the parsers */
+int others() { /* put out other arrays, copy the parsers */
register c, i, j;
finput = fopen( PARSER, "r" );
fclose( ftable );
}
-char *chcopy( p, q ) char *p, *q; {
+char *chcopy(p, q) char *p; char *q; {
/* copies string q into p, returning next free char ptr */
while( *p = *q++ ) ++p;
return( p );
return( sarr );
}
-char *symnam(i){ /* return a pointer to the name of symbol i */
+char *symnam(i) int i; { /* return a pointer to the name of symbol i */
char *cp;
cp = (i>=NTBASE) ? nontrst[i-NTBASE].name : tokset[i].name ;
int * zzmemsz = mem0;
int zzrrconf = 0;
-summary(){ /* output the summary on the tty */
+int summary() { /* output the summary on the tty */
if( foutput!=NULL ){
fprintf( foutput, "\n%d/%d terminals, %d/%d nonterminals\n", ntokens, NTERMS,
if( fdefine != NULL ) fclose( fdefine );
}
-error(s,va_alist) char *s; va_dcl { /* write out error comment */
+#ifdef __STDC__
+int error(char *s, ...)
+#else
+int error(s, va_alist) char *s; va_dcl
+#endif
+{ /* write out error comment */
va_list argp;
++nerrors;
fprintf( stderr, "\n fatal error: ");
- va_start(argp);
+ _va_start(argp, fmt);
vfprintf( stderr, s, argp);
va_end(argp);
fprintf( stderr, ", line %d\n", lineno );
exit(1);
}
-aryfil( v, n, c ) int *v,n,c; { /* set elements 0 through n-1 to c */
+int aryfil(v, n, c) int *v; int n; int c; { /* set elements 0 through n-1 to c */
int i;
for( i=0; i<n; ++i ) v[i] = c;
}
-setunion( a, b ) register *a, *b; {
+int setunion(a, b) register *a; register *b; {
/* set a to the union of a and b */
/* return 1 if b is not a subset of a, 0 otherwise */
register i, x, sub;
return( sub );
}
-prlook( p ) struct looksets *p;{
+int prlook(p) struct looksets *p; {
register j, *pp;
pp = p->lset;
if( pp == 0 ) fprintf( foutput, "\tNULL");
}
}
-cpres(){ /* compute an array with the beginnings of productions yielding given nonterminals
+int cpres() { /* compute an array with the beginnings of productions yielding given nonterminals
The array pres points to these lists */
/* the array pyield has the lists: the total size is only NPROD+1 */
register **pmem;
}
int indebug = 0;
-cpfir() {
+int cpfir() {
/* compute an array with the first of nonterminals */
register *p, **s, i, **t, ch, changes;
}
}
-state(c){ /* sorts last state,and sees if it equals earlier ones. returns state number */
+int state(c) int c; { /* sorts last state,and sees if it equals earlier ones. returns state number */
int size1,size2;
register i;
struct item *p1, *p2, *k, *l, *q1, *q2;
}
int pidebug = 0; /* debugging flag for putitem */
-putitem( ptr, lptr ) int *ptr; struct looksets *lptr; {
+int putitem(ptr, lptr) int *ptr; struct looksets *lptr; {
register struct item *j;
if( pidebug && (foutput!=NULL) ) {
}
}
-cempty(){ /* mark nonterminals which derive the empty string */
+int cempty() { /* mark nonterminals which derive the empty string */
/* also, look for nonterminals which don't derive any token strings */
# define EMPTY 1
}
int gsdebug = 0;
-stagen(){ /* generate the states */
+int stagen() { /* generate the states */
int i, j;
register c;
}
int cldebug = 0; /* debugging flag for closure */
-closure(i){ /* generate the closure of state i */
+int closure(i) int i; { /* generate the closure of state i */
int c, ch, work, k;
register struct wset *u, *v;
}
}
-struct looksets *flset( p ) struct looksets *p; {
+struct looksets *flset(p) struct looksets *p; {
/* decide if the lookahead set pointed to by p is known */
/* return pointer to a perminent location for the set */
-#ifndef lint
+#include <ctype.h>
+/*#include <stdio.h> dextern.h*/
+#include <strings.h>
+#include "dextern.h"
+
+#if defined(DOSCCS) && !defined(lint)
static char sccsid[] = "@(#)y2.c 4.1 (Berkeley) 2/11/83";
-#endif not lint
+#endif
-# include "dextern.h"
+/*# include "dextern.h"*/
# define IDENTIFIER 257
# define MARK 258
# define TERM 259
int *prdptr[NPROD]; /* pointers to descriptions of productions */
int levprd[NPROD] ; /* precedence levels for the productions */
-
-setup(argc,argv) int argc; char *argv[];
-{ int i,j,lev,t, ty;
+int setup(argc, argv) int argc; char *argv[]; { int i,j,lev,t, ty;
int c;
int *p;
char actname[8];
/* read rule body */
-
t = gettok();
more_rule:
while( t == IDENTIFIER ) {
t = gettok();
}
-
if( t == PREC ){
if( gettok()!=IDENTIFIER) error( "illegal %%prec syntax" );
j = chfind(2,tokname);
fclose( finput );
}
-finact(){
+int finact() {
/* finish action routine */
fclose(faction);
}
-defin( t, s ) register char *s; {
+int defin(t, s) int t; register char *s; {
/* define s to be a terminal if t=0
or a nonterminal if t=1 */
return( ntokens );
}
-defout(){ /* write out the defines (at the end of the declaration section) */
+int defout() { /* write out the defines (at the end of the declaration section) */
register int i, c;
register char *cp;
}
-char *
-cstash( s ) register char *s; {
+char *cstash(s) register char *s; {
char *temp;
temp = cnamp;
return( temp );
}
-gettok() {
+int gettok() {
register i, base;
static int peekline; /* number of '\n' seen in lookahead */
register c, match, reserve;
return( IDENTIFIER );
}
-fdtype( t ){ /* determine the type of a symbol */
+int fdtype(t) int t; { /* determine the type of a symbol */
register v;
if( t >= NTBASE ) v = nontrst[t-NTBASE].tvalue;
else v = TYPE( toklev[t] );
return( v );
}
-chfind( t, s ) register char *s; {
+int chfind(t, s) int t; register char *s; {
int i;
if (s[0]==' ')t=0;
return( defin( t, s ) );
}
-cpyunion(){
+int cpyunion() {
/* copy the union declaration to the output, and the define file if present */
int level, c;
}
}
-cpycode(){ /* copies code between \{ and \} */
+int cpycode() { /* copies code between \{ and \} */
int c;
c = getc(finput);
error("eof before %%}" );
}
-skipcom(){ /* skip over comments */
+int skipcom() { /* skip over comments */
register c, i=0; /* i is the number of lines skipped */
/* skipcom is called after reading a / */
/* NOTREACHED */
}
-cpyact(offset){ /* copy C action to the next ; or closing } */
+int cpyact(offset) int offset; { /* copy C action to the next ; or closing } */
int brac, c, match, j, s, tok;
fprintf( faction, "\n# line %d \"%s\"\n", lineno, infile );
putc( c, faction );
return;
-
case '/': /* look for comments */
putc( c , faction );
c = getc(finput);
-#ifndef lint
+/*#include <stdio.h> dextern.h*/
+#include "dextern.h"
+
+#if defined(DOSCCS) && !defined(lint)
static char sccsid[] = "@(#)y3.c 4.1 (Berkeley) 2/11/83";
-#endif not lint
+#endif
-# include "dextern.h"
+/*# include "dextern.h"*/
/* important local variables */
int lastred; /* the number of the last reduction of a state */
int defact[NSTATES]; /* the default actions of states */
-output(){ /* print the output for the states */
+int output() { /* print the output for the states */
int i, k, c;
register struct wset *u, *v;
}
int pkdebug = 0;
-apack(p, n ) int *p;{ /* pack state i from temp1 into amem */
+int apack(p, n) int *p; int n; { /* pack state i from temp1 into amem */
int off;
register *pp, *qq, *rr;
int *q, *r;
/* NOTREACHED */
}
-go2out(){ /* output the gotos for the nontermninals */
+int go2out() { /* output the gotos for the nontermninals */
int i, j, k, best, count, cbest, times;
fprintf( ftemp, "$\n" ); /* mark begining of gotos */
}
-
-
}
int g2debug = 0;
-go2gen(c){ /* output the gotos for nonterminal c */
+int go2gen(c) int c; { /* output the gotos for nonterminal c */
int i, work, cc;
struct item *p, *q;
-
/* first, find nonterminals with gotos on c */
aryfil( temp1, nnonter+1, 0 );
}
}
-precftn(r,t,s){ /* decide a shift/reduce conflict by precedence.
+int precftn(r, t, s) int r; int t; int s; { /* decide a shift/reduce conflict by precedence.
/* r is a rule number, t a token number */
/* the conflict is in state s */
/* temp1[t] is changed to reflect the action */
}
}
-wract(i){ /* output state i */
+int wract(i) int i; { /* output state i */
/* temp1 has the actions, lastred the default */
int p, p0, p1;
int ntimes, tred, count, j;
return;
}
-wrstate(i){ /* writes state i */
+int wrstate(i) int i; { /* writes state i */
register j0,j1;
register struct item *pp, *qq;
register struct wset *u;
}
-wdef( s, n ) char *s; { /* output a definition of s to the value n */
+int wdef(s, n) char *s; int n; { /* output a definition of s to the value n */
fprintf( ftable, "# define %s %d\n", s, n );
}
-warray( s, v, n ) char *s; int *v, n; {
+int warray(s, v, n) char *s; int *v; int n; {
register i;
}
}
-hideprod(){
+int hideprod() {
/* in order to free up the mem and amem arrays for the optimizer,
/* and still be able to output yyr1, etc., after the sizes of
/* the action array is known, we hide the nonterminals
-#ifndef lint
+#include <ctype.h>
+/*#include <stdio.h> dextern.h*/
+#include "dextern.h"
+
+#if defined(DOSCCS) && !defined(lint)
static char sccsid[] = "@(#)y4.c 4.1 (Berkeley) 2/11/83";
-#endif not lint
+#endif
-# include "dextern.h"
+/*# include "dextern.h"*/
# define a amem
# define mem mem0
int nxdb = 0;
int adb = 0;
-callopt(){
+int callopt() {
register i, *p, j, k, *q;
yypgo[nnonter--] = (--pmem) - mem;
-
-
for( i=0; i<nstate; ++i ){
k = 32000;
if( j > maxoff ) maxoff = j;
}
-
/* now, prepare to put the shift actions into the a array */
for( i=0; i<ACTSIZE; ++i ) a[i] = 0;
ZAPFILE(TEMPNAME);
}
-gin(i){
+int gin(i) int i; {
register *p, *r, *s, *q1, *q2;
nextgi: ;
}
-stin(i){
+int stin(i) int i; {
register *r, *s, n, flag, j, *q1, *q2;
greed[i] = 0;
}
-nxti(){ /* finds the next i */
+int nxti() { /* finds the next i */
register i, max, maxi;
max = 0;
else return( maxi );
}
-osummary(){
+int osummary() {
/* write summary */
register i, *p;
}
-aoutput(){ /* this version is for C */
-
+int aoutput() { /* this version is for C */
/* write out the optimized parser */
}
-arout( s, v, n ) char *s; int *v, n; {
+int arout(s, v, n) char *s; int *v; int n; {
register i;
}
}
-
-gtnm(){
+int gtnm() {
register s, val, c;