110930Srrh/* 2*26925Ssam * @(#)dextern 4.2 (Berkeley) 03/21/86 310930Srrh */ 410930Srrh# include <stdio.h> 510930Srrh# include <ctype.h> 610930Srrh# include "files" 710930Srrh 810930Srrh /* MANIFEST CONSTANT DEFINITIONS */ 910930Srrh 1010930Srrh /* base of nonterminal internal numbers */ 1110930Srrh# define NTBASE 010000 1210930Srrh 1310930Srrh /* internal codes for error and accept actions */ 1410930Srrh 1510930Srrh# define ERRCODE 8190 1610930Srrh# define ACCEPTCODE 8191 1710930Srrh 1810930Srrh /* sizes and limits */ 1910930Srrh 2010930Srrh# ifdef HUGE 2110930Srrh# define ACTSIZE 12000 22*26925Ssam# define MEMSIZE 24000 2310930Srrh# define NSTATES 750 24*26925Ssam# define NTERMS 300 2510930Srrh# define NPROD 600 2610930Srrh# define NNONTERM 300 2710930Srrh# define TEMPSIZE 1200 2810930Srrh# define CNAMSZ 5000 2910930Srrh# define LSETSIZE 600 3010930Srrh# define WSETSIZE 350 3110930Srrh# endif 3210930Srrh 3310930Srrh# ifdef MEDIUM 3410930Srrh# define ACTSIZE 4000 3510930Srrh# define MEMSIZE 5200 3610930Srrh# define NSTATES 600 3710930Srrh# define NTERMS 127 3810930Srrh# define NPROD 400 3910930Srrh# define NNONTERM 200 4010930Srrh# define TEMPSIZE 800 4110930Srrh# define CNAMSZ 4000 4210930Srrh# define LSETSIZE 450 4310930Srrh# define WSETSIZE 250 4410930Srrh# endif 4510930Srrh 4610930Srrh# define NAMESIZE 50 4710930Srrh# define NTYPES 63 4810930Srrh 4910930Srrh# ifdef WORD32 5010930Srrh# define TBITSET ((32+NTERMS)/32) 5110930Srrh 5210930Srrh /* bit packing macros (may be machine dependent) */ 5310930Srrh# define BIT(a,i) ((a)[(i)>>5] & (1<<((i)&037))) 5410930Srrh# define SETBIT(a,i) ((a)[(i)>>5] |= (1<<((i)&037))) 5510930Srrh 5610930Srrh /* number of words needed to hold n+1 bits */ 5710930Srrh# define NWORDS(n) (((n)+32)/32) 5810930Srrh 5910930Srrh# else 6010930Srrh 6110930Srrh# define TBITSET ((16+NTERMS)/16) 6210930Srrh 6310930Srrh /* bit packing macros (may be machine dependent) */ 6410930Srrh# define BIT(a,i) ((a)[(i)>>4] & (1<<((i)&017))) 6510930Srrh# define SETBIT(a,i) ((a)[(i)>>4] |= (1<<((i)&017))) 6610930Srrh 6710930Srrh /* number of words needed to hold n+1 bits */ 6810930Srrh# define NWORDS(n) (((n)+16)/16) 6910930Srrh# endif 7010930Srrh 7110930Srrh /* relationships which must hold: 7210930Srrh TBITSET ints must hold NTERMS+1 bits... 7310930Srrh WSETSIZE >= NNONTERM 7410930Srrh LSETSIZE >= NNONTERM 7510930Srrh TEMPSIZE >= NTERMS + NNONTERMs + 1 7610930Srrh TEMPSIZE >= NSTATES 7710930Srrh */ 7810930Srrh 7910930Srrh /* associativities */ 8010930Srrh 8110930Srrh# define NOASC 0 /* no assoc. */ 8210930Srrh# define LASC 1 /* left assoc. */ 8310930Srrh# define RASC 2 /* right assoc. */ 8410930Srrh# define BASC 3 /* binary assoc. */ 8510930Srrh 8610930Srrh /* flags for state generation */ 8710930Srrh 8810930Srrh# define DONE 0 8910930Srrh# define MUSTDO 1 9010930Srrh# define MUSTLOOKAHEAD 2 9110930Srrh 9210930Srrh /* flags for a rule having an action, and being reduced */ 9310930Srrh 9410930Srrh# define ACTFLAG 04 9510930Srrh# define REDFLAG 010 9610930Srrh 9710930Srrh /* output parser flags */ 9810930Srrh# define YYFLAG1 (-1000) 9910930Srrh 10010930Srrh /* macros for getting associativity and precedence levels */ 10110930Srrh 10210930Srrh# define ASSOC(i) ((i)&03) 10310930Srrh# define PLEVEL(i) (((i)>>4)&077) 10410930Srrh# define TYPE(i) ((i>>10)&077) 10510930Srrh 10610930Srrh /* macros for setting associativity and precedence levels */ 10710930Srrh 10810930Srrh# define SETASC(i,j) i|=j 10910930Srrh# define SETPLEV(i,j) i |= (j<<4) 11010930Srrh# define SETTYPE(i,j) i |= (j<<10) 11110930Srrh 11210930Srrh /* looping macros */ 11310930Srrh 11410930Srrh# define TLOOP(i) for(i=1;i<=ntokens;++i) 11510930Srrh# define NTLOOP(i) for(i=0;i<=nnonter;++i) 11610930Srrh# define PLOOP(s,i) for(i=s;i<nprod;++i) 11710930Srrh# define SLOOP(i) for(i=0;i<nstate;++i) 11810930Srrh# define WSBUMP(x) ++x 11910930Srrh# define WSLOOP(s,j) for(j=s;j<cwp;++j) 12010930Srrh# define ITMLOOP(i,p,q) q=pstate[i+1];for(p=pstate[i];p<q;++p) 12110930Srrh# define SETLOOP(i) for(i=0;i<tbitset;++i) 12210930Srrh 12310930Srrh /* I/O descriptors */ 12410930Srrh 12510930Srrhextern FILE * finput; /* input file */ 12610930Srrhextern FILE * faction; /* file for saving actions */ 12710930Srrhextern FILE *fdefine; /* file for # defines */ 12810930Srrhextern FILE * ftable; /* y.tab.c file */ 12910930Srrhextern FILE * ftemp; /* tempfile to pass 2 */ 13010930Srrhextern FILE * foutput; /* y.output file */ 13110930Srrh 13210930Srrh /* structure declarations */ 13310930Srrh 13410930Srrhstruct looksets { 13510930Srrh int lset[TBITSET]; 13610930Srrh }; 13710930Srrh 13810930Srrhstruct item { 13910930Srrh int *pitem; 14010930Srrh struct looksets *look; 14110930Srrh }; 14210930Srrh 14310930Srrhstruct toksymb { 14410930Srrh char *name; 14510930Srrh int value; 14610930Srrh }; 14710930Srrh 14810930Srrhstruct ntsymb { 14910930Srrh char *name; 15010930Srrh int tvalue; 15110930Srrh }; 15210930Srrh 15310930Srrhstruct wset { 15410930Srrh int *pitem; 15510930Srrh int flag; 15610930Srrh struct looksets ws; 15710930Srrh }; 15810930Srrh 15910930Srrh /* token information */ 16010930Srrh 16110930Srrhextern int ntokens ; /* number of tokens */ 16210930Srrhextern struct toksymb tokset[]; 16310930Srrhextern int toklev[]; /* vector with the precedence of the terminals */ 16410930Srrh 16510930Srrh /* nonterminal information */ 16610930Srrh 16710930Srrhextern int nnonter ; /* the number of nonterminals */ 16810930Srrhextern struct ntsymb nontrst[]; 16910930Srrh 17010930Srrh /* grammar rule information */ 17110930Srrh 17210930Srrhextern int nprod ; /* number of productions */ 17310930Srrhextern int *prdptr[]; /* pointers to descriptions of productions */ 17410930Srrhextern int levprd[] ; /* contains production levels to break conflicts */ 17510930Srrh 17610930Srrh /* state information */ 17710930Srrh 17810930Srrhextern int nstate ; /* number of states */ 17910930Srrhextern struct item *pstate[]; /* pointers to the descriptions of the states */ 18010930Srrhextern int tystate[]; /* contains type information about the states */ 18110930Srrhextern int defact[]; /* the default action of the state */ 18210930Srrhextern int tstates[]; /* the states deriving each token */ 18310930Srrhextern int ntstates[]; /* the states deriving each nonterminal */ 18410930Srrhextern int mstates[]; /* the continuation of the chains begun in tstates and ntstates */ 18510930Srrh 18610930Srrh /* lookahead set information */ 18710930Srrh 18810930Srrhextern struct looksets lkst[]; 18910930Srrhextern int nolook; /* flag to turn off lookahead computations */ 19010930Srrh 19110930Srrh /* working set information */ 19210930Srrh 19310930Srrhextern struct wset wsets[]; 19410930Srrhextern struct wset *cwp; 19510930Srrh 19610930Srrh /* storage for productions */ 19710930Srrh 19810930Srrhextern int mem0[]; 19910930Srrhextern int *mem; 20010930Srrh 20110930Srrh /* storage for action table */ 20210930Srrh 20310930Srrhextern int amem[]; /* action table storage */ 20410930Srrhextern int *memp ; /* next free action table position */ 20510930Srrhextern int indgo[]; /* index to the stored goto table */ 20610930Srrh 20710930Srrh /* temporary vector, indexable by states, terms, or ntokens */ 20810930Srrh 20910930Srrhextern int temp1[]; 21010930Srrhextern int lineno; /* current line number */ 21110930Srrh 21210930Srrh /* statistics collection variables */ 21310930Srrh 21410930Srrhextern int zzgoent ; 21510930Srrhextern int zzgobest ; 21610930Srrhextern int zzacent ; 21710930Srrhextern int zzexcp ; 21810930Srrhextern int zzclose ; 21910930Srrhextern int zzrrconf ; 22010930Srrhextern int zzsrconf ; 22110930Srrh /* define functions with strange types... */ 22210930Srrh 22310930Srrhextern char *cstash(); 22410930Srrhextern struct looksets *flset(); 22510930Srrhextern char *symnam(); 22610930Srrhextern char *writem(); 22710930Srrh 22810930Srrh /* default settings for a number of macros */ 22910930Srrh 23010930Srrh /* name of yacc tempfiles */ 23110930Srrh 23210930Srrh# ifndef TEMPNAME 23310930Srrh# define TEMPNAME "yacc.tmp" 23410930Srrh# endif 23510930Srrh 23610930Srrh# ifndef ACTNAME 23710930Srrh# define ACTNAME "yacc.acts" 23810930Srrh# endif 23910930Srrh 24010930Srrh /* output file name */ 24110930Srrh 24210930Srrh# ifndef OFILE 24310930Srrh# define OFILE "y.tab.c" 24410930Srrh# endif 24510930Srrh 24610930Srrh /* user output file name */ 24710930Srrh 24810930Srrh# ifndef FILEU 24910930Srrh# define FILEU "y.output" 25010930Srrh# endif 25110930Srrh 25210930Srrh /* output file for # defines */ 25310930Srrh 25410930Srrh# ifndef FILED 25510930Srrh# define FILED "y.tab.h" 25610930Srrh# endif 25710930Srrh 25810930Srrh /* command to clobber tempfiles after use */ 25910930Srrh 26010930Srrh# ifndef ZAPFILE 26110930Srrh# define ZAPFILE(x) unlink(x) 26210930Srrh# endif 263