1*10930Srrh/* 2*10930Srrh * @(#)dextern 4.1 (Berkeley) 02/11/83 3*10930Srrh */ 4*10930Srrh# include <stdio.h> 5*10930Srrh# include <ctype.h> 6*10930Srrh# include "files" 7*10930Srrh 8*10930Srrh /* MANIFEST CONSTANT DEFINITIONS */ 9*10930Srrh 10*10930Srrh /* base of nonterminal internal numbers */ 11*10930Srrh# define NTBASE 010000 12*10930Srrh 13*10930Srrh /* internal codes for error and accept actions */ 14*10930Srrh 15*10930Srrh# define ERRCODE 8190 16*10930Srrh# define ACCEPTCODE 8191 17*10930Srrh 18*10930Srrh /* sizes and limits */ 19*10930Srrh 20*10930Srrh# ifdef HUGE 21*10930Srrh# define ACTSIZE 12000 22*10930Srrh# define MEMSIZE 12000 23*10930Srrh# define NSTATES 750 24*10930Srrh# define NTERMS 127 25*10930Srrh# define NPROD 600 26*10930Srrh# define NNONTERM 300 27*10930Srrh# define TEMPSIZE 1200 28*10930Srrh# define CNAMSZ 5000 29*10930Srrh# define LSETSIZE 600 30*10930Srrh# define WSETSIZE 350 31*10930Srrh# endif 32*10930Srrh 33*10930Srrh# ifdef MEDIUM 34*10930Srrh# define ACTSIZE 4000 35*10930Srrh# define MEMSIZE 5200 36*10930Srrh# define NSTATES 600 37*10930Srrh# define NTERMS 127 38*10930Srrh# define NPROD 400 39*10930Srrh# define NNONTERM 200 40*10930Srrh# define TEMPSIZE 800 41*10930Srrh# define CNAMSZ 4000 42*10930Srrh# define LSETSIZE 450 43*10930Srrh# define WSETSIZE 250 44*10930Srrh# endif 45*10930Srrh 46*10930Srrh# define NAMESIZE 50 47*10930Srrh# define NTYPES 63 48*10930Srrh 49*10930Srrh# ifdef WORD32 50*10930Srrh# define TBITSET ((32+NTERMS)/32) 51*10930Srrh 52*10930Srrh /* bit packing macros (may be machine dependent) */ 53*10930Srrh# define BIT(a,i) ((a)[(i)>>5] & (1<<((i)&037))) 54*10930Srrh# define SETBIT(a,i) ((a)[(i)>>5] |= (1<<((i)&037))) 55*10930Srrh 56*10930Srrh /* number of words needed to hold n+1 bits */ 57*10930Srrh# define NWORDS(n) (((n)+32)/32) 58*10930Srrh 59*10930Srrh# else 60*10930Srrh 61*10930Srrh# define TBITSET ((16+NTERMS)/16) 62*10930Srrh 63*10930Srrh /* bit packing macros (may be machine dependent) */ 64*10930Srrh# define BIT(a,i) ((a)[(i)>>4] & (1<<((i)&017))) 65*10930Srrh# define SETBIT(a,i) ((a)[(i)>>4] |= (1<<((i)&017))) 66*10930Srrh 67*10930Srrh /* number of words needed to hold n+1 bits */ 68*10930Srrh# define NWORDS(n) (((n)+16)/16) 69*10930Srrh# endif 70*10930Srrh 71*10930Srrh /* relationships which must hold: 72*10930Srrh TBITSET ints must hold NTERMS+1 bits... 73*10930Srrh WSETSIZE >= NNONTERM 74*10930Srrh LSETSIZE >= NNONTERM 75*10930Srrh TEMPSIZE >= NTERMS + NNONTERMs + 1 76*10930Srrh TEMPSIZE >= NSTATES 77*10930Srrh */ 78*10930Srrh 79*10930Srrh /* associativities */ 80*10930Srrh 81*10930Srrh# define NOASC 0 /* no assoc. */ 82*10930Srrh# define LASC 1 /* left assoc. */ 83*10930Srrh# define RASC 2 /* right assoc. */ 84*10930Srrh# define BASC 3 /* binary assoc. */ 85*10930Srrh 86*10930Srrh /* flags for state generation */ 87*10930Srrh 88*10930Srrh# define DONE 0 89*10930Srrh# define MUSTDO 1 90*10930Srrh# define MUSTLOOKAHEAD 2 91*10930Srrh 92*10930Srrh /* flags for a rule having an action, and being reduced */ 93*10930Srrh 94*10930Srrh# define ACTFLAG 04 95*10930Srrh# define REDFLAG 010 96*10930Srrh 97*10930Srrh /* output parser flags */ 98*10930Srrh# define YYFLAG1 (-1000) 99*10930Srrh 100*10930Srrh /* macros for getting associativity and precedence levels */ 101*10930Srrh 102*10930Srrh# define ASSOC(i) ((i)&03) 103*10930Srrh# define PLEVEL(i) (((i)>>4)&077) 104*10930Srrh# define TYPE(i) ((i>>10)&077) 105*10930Srrh 106*10930Srrh /* macros for setting associativity and precedence levels */ 107*10930Srrh 108*10930Srrh# define SETASC(i,j) i|=j 109*10930Srrh# define SETPLEV(i,j) i |= (j<<4) 110*10930Srrh# define SETTYPE(i,j) i |= (j<<10) 111*10930Srrh 112*10930Srrh /* looping macros */ 113*10930Srrh 114*10930Srrh# define TLOOP(i) for(i=1;i<=ntokens;++i) 115*10930Srrh# define NTLOOP(i) for(i=0;i<=nnonter;++i) 116*10930Srrh# define PLOOP(s,i) for(i=s;i<nprod;++i) 117*10930Srrh# define SLOOP(i) for(i=0;i<nstate;++i) 118*10930Srrh# define WSBUMP(x) ++x 119*10930Srrh# define WSLOOP(s,j) for(j=s;j<cwp;++j) 120*10930Srrh# define ITMLOOP(i,p,q) q=pstate[i+1];for(p=pstate[i];p<q;++p) 121*10930Srrh# define SETLOOP(i) for(i=0;i<tbitset;++i) 122*10930Srrh 123*10930Srrh /* I/O descriptors */ 124*10930Srrh 125*10930Srrhextern FILE * finput; /* input file */ 126*10930Srrhextern FILE * faction; /* file for saving actions */ 127*10930Srrhextern FILE *fdefine; /* file for # defines */ 128*10930Srrhextern FILE * ftable; /* y.tab.c file */ 129*10930Srrhextern FILE * ftemp; /* tempfile to pass 2 */ 130*10930Srrhextern FILE * foutput; /* y.output file */ 131*10930Srrh 132*10930Srrh /* structure declarations */ 133*10930Srrh 134*10930Srrhstruct looksets { 135*10930Srrh int lset[TBITSET]; 136*10930Srrh }; 137*10930Srrh 138*10930Srrhstruct item { 139*10930Srrh int *pitem; 140*10930Srrh struct looksets *look; 141*10930Srrh }; 142*10930Srrh 143*10930Srrhstruct toksymb { 144*10930Srrh char *name; 145*10930Srrh int value; 146*10930Srrh }; 147*10930Srrh 148*10930Srrhstruct ntsymb { 149*10930Srrh char *name; 150*10930Srrh int tvalue; 151*10930Srrh }; 152*10930Srrh 153*10930Srrhstruct wset { 154*10930Srrh int *pitem; 155*10930Srrh int flag; 156*10930Srrh struct looksets ws; 157*10930Srrh }; 158*10930Srrh 159*10930Srrh /* token information */ 160*10930Srrh 161*10930Srrhextern int ntokens ; /* number of tokens */ 162*10930Srrhextern struct toksymb tokset[]; 163*10930Srrhextern int toklev[]; /* vector with the precedence of the terminals */ 164*10930Srrh 165*10930Srrh /* nonterminal information */ 166*10930Srrh 167*10930Srrhextern int nnonter ; /* the number of nonterminals */ 168*10930Srrhextern struct ntsymb nontrst[]; 169*10930Srrh 170*10930Srrh /* grammar rule information */ 171*10930Srrh 172*10930Srrhextern int nprod ; /* number of productions */ 173*10930Srrhextern int *prdptr[]; /* pointers to descriptions of productions */ 174*10930Srrhextern int levprd[] ; /* contains production levels to break conflicts */ 175*10930Srrh 176*10930Srrh /* state information */ 177*10930Srrh 178*10930Srrhextern int nstate ; /* number of states */ 179*10930Srrhextern struct item *pstate[]; /* pointers to the descriptions of the states */ 180*10930Srrhextern int tystate[]; /* contains type information about the states */ 181*10930Srrhextern int defact[]; /* the default action of the state */ 182*10930Srrhextern int tstates[]; /* the states deriving each token */ 183*10930Srrhextern int ntstates[]; /* the states deriving each nonterminal */ 184*10930Srrhextern int mstates[]; /* the continuation of the chains begun in tstates and ntstates */ 185*10930Srrh 186*10930Srrh /* lookahead set information */ 187*10930Srrh 188*10930Srrhextern struct looksets lkst[]; 189*10930Srrhextern int nolook; /* flag to turn off lookahead computations */ 190*10930Srrh 191*10930Srrh /* working set information */ 192*10930Srrh 193*10930Srrhextern struct wset wsets[]; 194*10930Srrhextern struct wset *cwp; 195*10930Srrh 196*10930Srrh /* storage for productions */ 197*10930Srrh 198*10930Srrhextern int mem0[]; 199*10930Srrhextern int *mem; 200*10930Srrh 201*10930Srrh /* storage for action table */ 202*10930Srrh 203*10930Srrhextern int amem[]; /* action table storage */ 204*10930Srrhextern int *memp ; /* next free action table position */ 205*10930Srrhextern int indgo[]; /* index to the stored goto table */ 206*10930Srrh 207*10930Srrh /* temporary vector, indexable by states, terms, or ntokens */ 208*10930Srrh 209*10930Srrhextern int temp1[]; 210*10930Srrhextern int lineno; /* current line number */ 211*10930Srrh 212*10930Srrh /* statistics collection variables */ 213*10930Srrh 214*10930Srrhextern int zzgoent ; 215*10930Srrhextern int zzgobest ; 216*10930Srrhextern int zzacent ; 217*10930Srrhextern int zzexcp ; 218*10930Srrhextern int zzclose ; 219*10930Srrhextern int zzrrconf ; 220*10930Srrhextern int zzsrconf ; 221*10930Srrh /* define functions with strange types... */ 222*10930Srrh 223*10930Srrhextern char *cstash(); 224*10930Srrhextern struct looksets *flset(); 225*10930Srrhextern char *symnam(); 226*10930Srrhextern char *writem(); 227*10930Srrh 228*10930Srrh /* default settings for a number of macros */ 229*10930Srrh 230*10930Srrh /* name of yacc tempfiles */ 231*10930Srrh 232*10930Srrh# ifndef TEMPNAME 233*10930Srrh# define TEMPNAME "yacc.tmp" 234*10930Srrh# endif 235*10930Srrh 236*10930Srrh# ifndef ACTNAME 237*10930Srrh# define ACTNAME "yacc.acts" 238*10930Srrh# endif 239*10930Srrh 240*10930Srrh /* output file name */ 241*10930Srrh 242*10930Srrh# ifndef OFILE 243*10930Srrh# define OFILE "y.tab.c" 244*10930Srrh# endif 245*10930Srrh 246*10930Srrh /* user output file name */ 247*10930Srrh 248*10930Srrh# ifndef FILEU 249*10930Srrh# define FILEU "y.output" 250*10930Srrh# endif 251*10930Srrh 252*10930Srrh /* output file for # defines */ 253*10930Srrh 254*10930Srrh# ifndef FILED 255*10930Srrh# define FILED "y.tab.h" 256*10930Srrh# endif 257*10930Srrh 258*10930Srrh /* command to clobber tempfiles after use */ 259*10930Srrh 260*10930Srrh# ifndef ZAPFILE 261*10930Srrh# define ZAPFILE(x) unlink(x) 262*10930Srrh# endif 263