Post-ansification changes for usr.bin/yacc
authorNick Downing <downing.nick@gmail.com>
Tue, 31 Jan 2017 10:36:37 +0000 (21:36 +1100)
committerNick Downing <downing.nick@gmail.com>
Tue, 31 Jan 2017 11:15:46 +0000 (22:15 +1100)
.gitignore
n.sh
usr.bin/yacc/dextern.h
usr.bin/yacc/files.h
usr.bin/yacc/y1.c
usr.bin/yacc/y2.c
usr.bin/yacc/y3.c
usr.bin/yacc/y4.c

index c5fc9dd..ebab920 100644 (file)
@@ -145,6 +145,7 @@ usr.bin/tsort
 usr.bin/tty
 usr.bin/uniq
 usr.bin/units
+usr.bin/yacc/yacc
 xify/cc
 xify/ld
 xify/xify
diff --git a/n.sh b/n.sh
index 864ca88..5d080c0 100755 (executable)
--- a/n.sh
+++ b/n.sh
@@ -28,6 +28,6 @@ mkdir -p lib/libc/stdio/profiled
 mkdir -p lib/libc/sys/profiled
 (cd lib/libc && make.sh clean && make.sh && make.sh install)
 (cd bin && make.sh clean && make.sh SUBDIR="as csh diff sed sh tp" NSTD= KMEM= && make.sh SUBDIR="as csh diff sed sh tp" NSTD= KMEM= install)
-(cd usr.bin && make.sh clean && make.sh SUBDIR=find NSTD= KMEM= && make.sh SUBDIR=find NSTD= KMEM= install)
+(cd usr.bin && make.sh clean && make.sh SUBDIR="find yacc" NSTD= KMEM= && make.sh SUBDIR="find yacc" NSTD= KMEM= install)
 
 #(cd test && make clean && make)
index 4bc613b..7c3ebe1 100644 (file)
 
        /* sizes and limits */
 
+/* Nick changed memory size to reflect that some words allocated are pointers */
 # ifdef HUGE
 # define ACTSIZE 12000
-# define MEMSIZE 24000
+# define MEMSIZE (24000 * sizeof(char *) / sizeof(int))
 # define NSTATES 750
 # define NTERMS 300
 # define NPROD 600
@@ -39,7 +40,7 @@
 
 # ifdef MEDIUM
 # define ACTSIZE 4000
-# define MEMSIZE 5200
+# define MEMSIZE (5200 * sizeof(char *) / sizeof(int))
 # define NSTATES 600
 # define NTERMS 127
 # define NPROD 400
@@ -278,58 +279,58 @@ extern int zzsrconf ;
 
 /* y1.c */
 int main __P((int argc, char *argv[]));
-int others __P((void));
+void 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));
+void summary __P((void));
+void error __P((char *s, ...));
+void 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));
+void prlook __P((struct looksets *p));
+void cpres __P((void));
+void 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));
+void putitem __P((int *ptr, struct looksets *lptr));
+void cempty __P((void));
+void stagen __P((void));
+void closure __P((int i));
 struct looksets *flset __P((struct looksets *p));
 
 /* y2.c */
-int setup __P((int argc, char *argv[]));
-int finact __P((void));
+void setup __P((int argc, char *argv[]));
+void finact __P((void));
 int defin __P((int t, register char *s));
-int defout __P((void));
+void 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));
+void cpyunion __P((void));
+void cpycode __P((void));
 int skipcom __P((void));
-int cpyact __P((int offset));
+void cpyact __P((int offset));
 
 /* y3.c */
-int output __P((void));
+void 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));
+void go2out __P((void));
+void go2gen __P((int c));
+void precftn __P((int r, int t, int s));
+void wract __P((int i));
+void wrstate __P((int i));
+void wdef __P((char *s, int n));
+void warray __P((char *s, int *v, int n));
+void hideprod __P((void));
 
 /* y4.c */
-int callopt __P((void));
-int gin __P((int i));
-int stin __P((int i));
+void callopt __P((void));
+void gin __P((int i));
+void 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));
+void osummary __P((void));
+void aoutput __P((void));
+void arout __P((char *s, int *v, int n));
 int gtnm __P((void));
 
 #endif
index 807eaaf..5c95a14 100644 (file)
@@ -6,9 +6,9 @@
  */
        /* this file has the location of the parser, and the size of the progam desired */
        /* It may also contain definitions to override various defaults: for example,
-       /* WORD32 tells yacc that there are at least 32 bits per int */
+        * WORD32 tells yacc that there are at least 32 bits per int */
        /* on some systems, notably IBM, the names for the output files and tempfiles must
-       /* also be changed  */
+        * also be changed  */
 
 #ifndef WORD32
 #define WORD32
index a621598..56b9bfe 100644 (file)
@@ -76,7 +76,7 @@ int main(argc, argv) int argc; char *argv[]; {
        exit(0);
        }
 
-int others() { /* put out other arrays, copy the parsers */
+void others() { /* put out other arrays, copy the parsers */
        register c, i, j;
 
        finput = fopen( PARSER, "r" );
@@ -174,15 +174,15 @@ int zzsrconf = 0;
 int * zzmemsz = mem0;
 int zzrrconf = 0;
 
-int summary() { /* output the summary on the tty */
+void summary() { /* output the summary on the tty */
 
        if( foutput!=NULL ){
                fprintf( foutput, "\n%d/%d terminals, %d/%d nonterminals\n", ntokens, NTERMS,
                            nnonter, NNONTERM );
                fprintf( foutput, "%d/%d grammar rules, %d/%d states\n", nprod, NPROD, nstate, NSTATES );
                fprintf( foutput, "%d shift/reduce, %d reduce/reduce conflicts reported\n", zzsrconf, zzrrconf );
-               fprintf( foutput, "%d/%d working sets used\n", zzcwp-wsets,  WSETSIZE );
-               fprintf( foutput, "memory: states,etc. %d/%d, parser %d/%d\n", zzmemsz-mem0, MEMSIZE,
+               fprintf( foutput, "%d/%d working sets used\n", (int)(zzcwp-wsets),  WSETSIZE );
+               fprintf( foutput, "memory: states,etc. %d/%d, parser %d/%d\n", (int)(zzmemsz-mem0), MEMSIZE,
                            memp-amem, ACTSIZE );
                fprintf( foutput, "%d/%d distinct lookahead sets\n", nlset, LSETSIZE );
                fprintf( foutput, "%d extra closures\n", zzclose - 2*nstate );
@@ -203,16 +203,16 @@ int summary() { /* output the summary on the tty */
        }
 
 #ifdef __STDC__
-int error(char *s, ...)
+void error(char *s, ...)
 #else
-int error(s, va_alist) char *s; va_dcl
+void 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, fmt);
+       _va_start(argp, s);
        vfprintf( stderr, s, argp);
        va_end(argp);
        fprintf( stderr, ", line %d\n", lineno );
@@ -221,7 +221,7 @@ int error(s, va_alist) char *s; va_dcl
        exit(1);
        }
 
-int aryfil(v, n, c) int *v; int n; int c; { /* set elements 0 through n-1 to c */
+void 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;
        }
@@ -239,7 +239,7 @@ int setunion(a, b) register *a; register *b; {
        return( sub );
        }
 
-int prlook(p) struct looksets *p; {
+void prlook(p) struct looksets *p; {
        register j, *pp;
        pp = p->lset;
        if( pp == 0 ) fprintf( foutput, "\tNULL");
@@ -252,7 +252,7 @@ int prlook(p) struct looksets *p; {
                }
        }
 
-int cpres() { /* compute an array with the beginnings of  productions yielding given nonterminals
+void 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;
@@ -282,7 +282,7 @@ int cpres() { /* compute an array with the beginnings of  productions yielding g
        }
 
 int indebug = 0;
-int cpfir() {
+void cpfir() {
        /* compute an array with the first of nonterminals */
        register *p, **s, i, **t, ch, changes;
 
@@ -394,7 +394,7 @@ int state(c) int c; { /* sorts last state,and sees if it equals earlier ones. re
        }
 
 int pidebug = 0; /* debugging flag for putitem */
-int putitem(ptr, lptr) int *ptr; struct looksets *lptr; {
+void putitem(ptr, lptr) int *ptr; struct looksets *lptr; {
        register struct item *j;
 
        if( pidebug && (foutput!=NULL) ) {
@@ -410,7 +410,7 @@ int putitem(ptr, lptr) int *ptr; struct looksets *lptr; {
                }
        }
 
-int cempty() { /* mark nonterminals which derive the empty string */
+void cempty() { /* mark nonterminals which derive the empty string */
        /* also, look for nonterminals which don't derive any token strings */
 
 # define EMPTY 1
@@ -475,7 +475,7 @@ again:
        }
 
 int gsdebug = 0;
-int stagen() { /* generate the states */
+void stagen() { /* generate the states */
 
        int i, j;
        register c;
@@ -486,10 +486,10 @@ int stagen() { /* generate the states */
        nstate = 0;
        /* THIS IS FUNNY from the standpoint of portability */
        /* it represents the magic moment when the mem0 array, which has
-       /* been holding the productions, starts to hold item pointers, of a
-       /* different type... */
+        * been holding the productions, starts to hold item pointers, of a
+        * different type... */
        /* someday, alloc should be used to allocate all this stuff... for now, we
-       /* accept that if pointers don't fit in integers, there is a problem... */
+        * accept that if pointers don't fit in integers, there is a problem... */
 
        pstate[0] = pstate[1] = (struct item *)mem;
        aryfil( clset.lset, tbitset, 0 );
@@ -545,7 +545,7 @@ int stagen() { /* generate the states */
        }
 
 int cldebug = 0; /* debugging flag for closure */
-int closure(i) int i; { /* generate the closure of state i */
+void closure(i) int i; { /* generate the closure of state i */
 
        int c, ch, work, k;
        register struct wset *u, *v;
index 96ef365..9c6dc62 100644 (file)
@@ -70,7 +70,7 @@ int nprod= 1; /* number of productions */
 int *prdptr[NPROD];    /* pointers to descriptions of productions */
 int levprd[NPROD] ;    /* precedence levels for the productions */
 
-int setup(argc, argv) int argc; char *argv[]; {        int i,j,lev,t, ty;
+void setup(argc, argv) int argc; char *argv[]; {       int i,j,lev,t, ty;
        int c;
        int *p;
        char actname[8];
@@ -396,7 +396,7 @@ int setup(argc, argv) int argc; char *argv[]; {     int i,j,lev,t, ty;
        fclose( finput );
        }
 
-int finact() {
+void finact() {
        /* finish action routine */
 
        fclose(faction);
@@ -454,7 +454,7 @@ int defin(t, s) int t; register char *s; {
        return( ntokens );
        }
 
-int defout() { /* write out the defines (at the end of the declaration section) */
+void defout() { /* write out the defines (at the end of the declaration section) */
 
        register int i, c;
        register char *cp;
@@ -655,7 +655,7 @@ int chfind(t, s) int t; register char *s; {
        return( defin( t, s ) );
        }
 
-int cpyunion() {
+void cpyunion() {
        /* copy the union declaration to the output, and the define file if present */
 
        int level, c;
@@ -690,7 +690,7 @@ int cpyunion() {
                }
        }
 
-int cpycode() { /* copies code between \{ and \} */
+void cpycode() { /* copies code between \{ and \} */
 
        int c;
        c = getc(finput);
@@ -729,9 +729,12 @@ int skipcom() { /* skip over comments */
                }
        error( "EOF inside comment" );
        /* NOTREACHED */
+#ifdef __GNUC__
+       return 0;
+#endif
        }
 
-int cpyact(offset) int offset; { /* copy C action to the next ; or closing } */
+void 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 );
index b695237..2d93e77 100644 (file)
@@ -11,7 +11,7 @@ static char sccsid[] = "@(#)y3.c      4.1     (Berkeley)      2/11/83";
 int lastred;  /* the number of the last reduction of a state */
 int defact[NSTATES];  /* the default actions of states */
 
-int output() { /* print the output for the states */
+void output() { /* print the output for the states */
 
        int i, k, c;
        register struct wset *u, *v;
@@ -123,9 +123,12 @@ int apack(p, n) int *p; int n; { /* pack state i from temp1 into amem */
                }
        error("no space in action table" );
        /* NOTREACHED */
+#ifdef __GNUC__
+       return 0;
+#endif
        }
 
-int go2out() { /* output the gotos for the nontermninals */
+void go2out() { /* output the gotos for the nontermninals */
        int i, j, k, best, count, cbest, times;
 
        fprintf( ftemp, "$\n" );  /* mark begining of gotos */
@@ -175,7 +178,7 @@ int go2out() { /* output the gotos for the nontermninals */
        }
 
 int g2debug = 0;
-int go2gen(c) int c; { /* output the gotos for nonterminal c */
+void go2gen(c) int c; { /* output the gotos for nonterminal c */
 
        int i, work, cc;
        struct item *p, *q;
@@ -224,8 +227,8 @@ int go2gen(c) int c; { /* output the gotos for nonterminal c */
                }
        }
 
-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 */
+void 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 */
 
@@ -257,7 +260,7 @@ int precftn(r, t, s) int r; int t; int s; { /* decide a shift/reduce conflict by
                }
        }
 
-int wract(i) int i; { /* output state i */
+void wract(i) int i; { /* output state i */
        /* temp1 has the actions, lastred the default */
        int p, p0, p1;
        int ntimes, tred, count, j;
@@ -284,7 +287,7 @@ int wract(i) int i; { /* output state i */
                }
 
        /* for error recovery, arrange that, if there is a shift on the
-       /* error recovery token, `error', that the default be the error action */
+        * error recovery token, `error', that the default be the error action */
        if( temp1[1] > 0 ) lastred = 0;
 
        /* clear out entries in temp1 which equal lastred */
@@ -326,7 +329,7 @@ int wract(i) int i; { /* output state i */
        return;
        }
 
-int wrstate(i) int i; { /* writes state i */
+void wrstate(i) int i; { /* writes state i */
        register j0,j1;
        register struct item *pp, *qq;
        register struct wset *u;
@@ -367,11 +370,11 @@ int wrstate(i) int i; { /* writes state i */
 
        }
 
-int wdef(s, n) char *s; int n; { /* output a definition of s to the value n */
+void wdef(s, n) char *s; int n; { /* output a definition of s to the value n */
        fprintf( ftable, "# define %s %d\n", s, n );
        }
 
-int warray(s, v, n) char *s; int *v; int n; {
+void warray(s, v, n) char *s; int *v; int n; {
 
        register i;
 
@@ -384,12 +387,12 @@ int warray(s, v, n) char *s; int *v; int n; {
                }
        }
 
-int hideprod() {
+void 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
-       /* derived by productions in levprd.
-       */
+        * and still be able to output yyr1, etc., after the sizes of
+        * the action array is known, we hide the nonterminals
+        * derived by productions in levprd.
+        */
 
        register i, j;
 
index a49da08..48f1ac0 100644 (file)
@@ -27,7 +27,7 @@ int *maxa;
 int nxdb = 0;
 int adb = 0;
 
-int callopt() {
+void callopt() {
 
        register i, *p, j, k, *q;
 
@@ -87,8 +87,8 @@ int callopt() {
                        if( *p < k ) k = *p;
                        }
                if( k <= j ){ /* nontrivial situation */
-                       /* temporarily, kill this for compatibility
-                       j -= k;  /* j is now the range */
+                       /* temporarily, kill this for compatibility */
+                       /*j -= k;*/  /* j is now the range */
                        if( k > maxoff ) maxoff = k;
                        }
                greed[i] = (yypact[i+1]-yypact[i]) + 2*j;
@@ -141,7 +141,7 @@ int callopt() {
        ZAPFILE(TEMPNAME);
        }
 
-int gin(i) int i; {
+void gin(i) int i; {
 
        register *p, *r, *s, *q1, *q2;
 
@@ -186,7 +186,7 @@ int gin(i) int i; {
        nextgi:  ;
        }
 
-int stin(i) int i; {
+void stin(i) int i; {
        register *r, *s, n, flag, j, *q1, *q2;
 
        greed[i] = 0;
@@ -259,7 +259,7 @@ int nxti() { /* finds the next i */
        else return( maxi );
        }
 
-int osummary() {
+void osummary() {
        /* write summary */
 
        register i, *p;
@@ -277,7 +277,7 @@ int osummary() {
 
        }
 
-int aoutput() { /* this version is for C */
+void aoutput() { /* this version is for C */
 
        /* write out the optimized parser */
 
@@ -289,7 +289,7 @@ int aoutput() { /* this version is for C */
 
        }
 
-int arout(s, v, n) char *s; int *v; int n; {
+void arout(s, v, n) char *s; int *v; int n; {
 
        register i;