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