Ansified usr.bin/yacc
authorNick Downing <downing.nick@gmail.com>
Tue, 31 Jan 2017 10:22:25 +0000 (21:22 +1100)
committerNick Downing <downing.nick@gmail.com>
Tue, 31 Jan 2017 10:22:25 +0000 (21:22 +1100)
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 29421cf..4bc613b 100644 (file)
@@ -1,9 +1,16 @@
+#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 */
 
@@ -220,10 +227,10 @@ extern int zzrrconf ;
 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 */
 
@@ -260,3 +267,69 @@ extern char *writem();
 # 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
index a5641ef..807eaaf 100644 (file)
@@ -1,3 +1,6 @@
+#ifndef _FILES_H_
+#define _FILES_H_
+
 /*
  *     @(#)files       4.1     (Berkeley)      83/02/11
  */
@@ -15,3 +18,5 @@
 
        /* basic size of the Yacc implementation */
 # define HUGE
+
+#endif
index a8e1054..a621598 100644 (file)
@@ -1,9 +1,20 @@
-#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 */
 
@@ -48,7 +59,7 @@ int **pres[NNONTERM+2];  /* vector of pointers to productions yielding each nont
 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);
@@ -65,7 +76,7 @@ main(argc,argv) int argc; char *argv[]; {
        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" );
@@ -112,7 +123,7 @@ others(){ /* put out other arrays, copy the parsers */
        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 );
@@ -145,7 +156,7 @@ char *writem(pp) int *pp; { /* creates output string for item pointed to by pp *
        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 ;
@@ -163,7 +174,7 @@ int zzsrconf = 0;
 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,
@@ -191,12 +202,17 @@ summary(){ /* output the summary on the tty */
        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 );
@@ -205,12 +221,12 @@ error(s,va_alist) char *s; va_dcl { /* write out error comment */
        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;
@@ -223,7 +239,7 @@ setunion( a, b ) register *a, *b; {
        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");
@@ -236,7 +252,7 @@ prlook( p ) struct looksets *p;{
                }
        }
 
-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;
@@ -266,7 +282,7 @@ cpres(){ /* compute an array with the beginnings of  productions yielding given
        }
 
 int indebug = 0;
-cpfir() {
+int cpfir() {
        /* compute an array with the first of nonterminals */
        register *p, **s, i, **t, ch, changes;
 
@@ -312,7 +328,7 @@ cpfir() {
                }
        }
 
-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;
@@ -378,7 +394,7 @@ state(c){ /* sorts last state,and sees if it equals earlier ones. returns state
        }
 
 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) ) {
@@ -394,7 +410,7 @@ putitem( ptr, lptr )  int *ptr;  struct looksets *lptr; {
                }
        }
 
-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
@@ -459,7 +475,7 @@ again:
        }
 
 int gsdebug = 0;
-stagen(){ /* generate the states */
+int stagen() { /* generate the states */
 
        int i, j;
        register c;
@@ -529,7 +545,7 @@ stagen(){ /* generate the states */
        }
 
 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;
@@ -633,7 +649,7 @@ closure(i){ /* generate the closure of state i */
                }
        }
 
-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 */
 
index 3436cca..96ef365 100644 (file)
@@ -1,8 +1,13 @@
-#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
@@ -65,9 +70,7 @@ int nprod= 1; /* number of productions */
 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];
@@ -300,7 +303,6 @@ setup(argc,argv) int argc; char *argv[];
 
                /* read rule body */
 
-
                t = gettok();
        more_rule:
                while( t == IDENTIFIER ) {
@@ -310,7 +312,6 @@ setup(argc,argv) int argc; char *argv[];
                        t = gettok();
                        }
 
-
                if( t == PREC ){
                        if( gettok()!=IDENTIFIER) error( "illegal %%prec syntax" );
                        j = chfind(2,tokname);
@@ -395,7 +396,7 @@ setup(argc,argv) int argc; char *argv[];
        fclose( finput );
        }
 
-finact(){
+int finact() {
        /* finish action routine */
 
        fclose(faction);
@@ -404,7 +405,7 @@ finact(){
 
        }
 
-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         */
 
@@ -453,7 +454,7 @@ defin( t, s ) register char  *s; {
        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;
@@ -479,8 +480,7 @@ defout(){ /* write out the defines (at the end of the declaration section) */
 
        }
 
-char *
-cstash( s ) register char *s; {
+char *cstash(s) register char *s; {
        char *temp;
 
        temp = cnamp;
@@ -491,7 +491,7 @@ cstash( s ) register char *s; {
        return( temp );
        }
 
-gettok() {
+int gettok() {
        register i, base;
        static int peekline; /* number of '\n' seen in lookahead */
        register c, match, reserve;
@@ -626,7 +626,7 @@ begin:
        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] );
@@ -635,7 +635,7 @@ fdtype( t ){ /* determine the type of a symbol */
        return( v );
        }
 
-chfind( t, s ) register char *s; {
+int chfind(t, s) int t; register char *s; {
        int i;
 
        if (s[0]==' ')t=0;
@@ -655,7 +655,7 @@ chfind( t, s ) register char *s; {
        return( defin( t, s ) );
        }
 
-cpyunion(){
+int cpyunion() {
        /* copy the union declaration to the output, and the define file if present */
 
        int level, c;
@@ -690,7 +690,7 @@ cpyunion(){
                }
        }
 
-cpycode(){ /* copies code between \{ and \} */
+int cpycode() { /* copies code between \{ and \} */
 
        int c;
        c = getc(finput);
@@ -713,7 +713,7 @@ cpycode(){ /* copies code between \{ and \} */
        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 / */
@@ -731,7 +731,7 @@ skipcom(){ /* skip over comments */
        /* 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 );
@@ -805,7 +805,6 @@ case '}':
                putc( c, faction );
                return;
 
-
 case '/':      /* look for comments */
                putc( c , faction );
                c = getc(finput);
index f472677..b695237 100644 (file)
@@ -1,14 +1,17 @@
-#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;
@@ -71,7 +74,7 @@ output(){ /* print the output for the states */
        }
 
 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;
@@ -122,7 +125,7 @@ apack(p, n ) int *p;{ /* pack state i from temp1 into amem */
        /* 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 */
@@ -169,17 +172,14 @@ go2out(){ /* output the gotos for the nontermninals */
 
                }
 
-
-
        }
 
 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 );
@@ -224,7 +224,7 @@ go2gen(c){ /* output the gotos for nonterminal c */
                }
        }
 
-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 */
@@ -257,7 +257,7 @@ precftn(r,t,s){ /* decide a shift/reduce conflict by precedence.
                }
        }
 
-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;
@@ -326,7 +326,7 @@ wract(i){ /* output state i */
        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;
@@ -367,11 +367,11 @@ wrstate(i){ /* writes state i */
 
        }
 
-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;
 
@@ -384,7 +384,7 @@ warray( s, v, n ) char *s; int *v, n; {
                }
        }
 
-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
index 8777b03..a49da08 100644 (file)
@@ -1,8 +1,12 @@
-#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
@@ -23,7 +27,7 @@ int *maxa;
 int nxdb = 0;
 int adb = 0;
 
-callopt(){
+int callopt() {
 
        register i, *p, j, k, *q;
 
@@ -73,8 +77,6 @@ callopt(){
 
        yypgo[nnonter--] = (--pmem) - mem;
 
-
-
        for( i=0; i<nstate; ++i ){
 
                k = 32000;
@@ -108,7 +110,6 @@ callopt(){
                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;
@@ -140,7 +141,7 @@ callopt(){
        ZAPFILE(TEMPNAME);
        }
 
-gin(i){
+int gin(i) int i; {
 
        register *p, *r, *s, *q1, *q2;
 
@@ -185,7 +186,7 @@ gin(i){
        nextgi:  ;
        }
 
-stin(i){
+int stin(i) int i; {
        register *r, *s, n, flag, j, *q1, *q2;
 
        greed[i] = 0;
@@ -238,7 +239,7 @@ stin(i){
 
        }
 
-nxti(){ /* finds the next i */
+int nxti() { /* finds the next i */
        register i, max, maxi;
 
        max = 0;
@@ -258,7 +259,7 @@ nxti(){ /* finds the next i */
        else return( maxi );
        }
 
-osummary(){
+int osummary() {
        /* write summary */
 
        register i, *p;
@@ -276,8 +277,7 @@ osummary(){
 
        }
 
-aoutput(){ /* this version is for C */
-
+int aoutput() { /* this version is for C */
 
        /* write out the optimized parser */
 
@@ -289,7 +289,7 @@ aoutput(){ /* this version is for C */
 
        }
 
-arout( s, v, n ) char *s; int *v, n; {
+int arout(s, v, n) char *s; int *v; int n; {
 
        register i;
 
@@ -302,8 +302,7 @@ arout( s, v, n ) char *s; int *v, n; {
                }
        }
 
-
-gtnm(){
+int gtnm() {
 
        register s, val, c;