Commit | Line | Data |
---|---|---|
b54a2a5a BJ |
1 | |
2 | # include <stdio.h> | |
3 | /* manifest constant file for the lex/yacc interface */ | |
4 | ||
5 | # define ERROR 1 | |
6 | # define NAME 2 | |
7 | # define STRING 3 | |
8 | # define ICON 4 | |
9 | # define FCON 5 | |
10 | # define PLUS 6 | |
11 | # define MINUS 8 | |
12 | # define MUL 11 | |
13 | # define AND 14 | |
14 | # define OR 17 | |
15 | # define ER 19 | |
16 | # define QUEST 21 | |
17 | # define COLON 22 | |
18 | # define ANDAND 23 | |
19 | # define OROR 24 | |
20 | ||
21 | /* the defines for ASOP, RELOP, EQUOP, DIVOP, | |
22 | SHIFTOP, ICOP, UNOP, and STROP have been | |
23 | moved to mfile1 */ | |
24 | /* reserved words, etc */ | |
25 | # define TYPE 33 | |
26 | # define CLASS 34 | |
27 | # define STRUCT 35 | |
28 | # define RETURN 36 | |
29 | # define GOTO 37 | |
30 | # define IF 38 | |
31 | # define ELSE 39 | |
32 | # define SWITCH 40 | |
33 | # define BREAK 41 | |
34 | # define CONTINUE 42 | |
35 | # define WHILE 43 | |
36 | # define DO 44 | |
37 | # define FOR 45 | |
38 | # define DEFAULT 46 | |
39 | # define CASE 47 | |
40 | # define SIZEOF 48 | |
41 | # define ENUM 49 | |
42 | ||
43 | ||
44 | /* little symbols, etc. */ | |
45 | /* namely, | |
46 | ||
47 | LP ( | |
48 | RP ) | |
49 | ||
50 | LC { | |
51 | RC } | |
52 | ||
53 | LB [ | |
54 | RB ] | |
55 | ||
56 | CM , | |
57 | SM ; | |
58 | ||
59 | */ | |
60 | ||
61 | /* These defines are being moved to mfile1 | |
62 | to alleviate preprocessor problems with | |
63 | second pass files. | |
64 | # define LP 50 | |
65 | # define RP 51 | |
66 | # define LC 52 | |
67 | # define RC 53 | |
68 | */ | |
69 | # define LB 54 | |
70 | # define RB 55 | |
71 | # define CM 56 | |
72 | # define SM 57 | |
73 | # define ASSIGN 58 | |
74 | ||
75 | /* END OF YACC */ | |
76 | ||
77 | /* left over tree building operators */ | |
78 | # define COMOP 59 | |
79 | # define DIV 60 | |
80 | # define MOD 62 | |
81 | # define LS 64 | |
82 | # define RS 66 | |
83 | # define DOT 68 | |
84 | # define STREF 69 | |
85 | # define CALL 70 | |
86 | # define FORTCALL 73 | |
87 | # define NOT 76 | |
88 | # define COMPL 77 | |
89 | # define INCR 78 | |
90 | # define DECR 79 | |
91 | # define EQ 80 | |
92 | # define NE 81 | |
93 | # define LE 82 | |
94 | # define LT 83 | |
95 | # define GE 84 | |
96 | # define GT 85 | |
97 | # define ULE 86 | |
98 | # define ULT 87 | |
99 | # define UGE 88 | |
100 | # define UGT 89 | |
101 | # define SETBIT 90 | |
102 | # define TESTBIT 91 | |
103 | # define RESETBIT 92 | |
104 | # define ARS 93 | |
105 | # define REG 94 | |
106 | # define OREG 95 | |
107 | # define CCODES 96 | |
108 | # define FREE 97 | |
109 | # define STASG 98 | |
110 | # define STARG 99 | |
111 | # define STCALL 100 | |
112 | ||
113 | /* some conversion operators */ | |
114 | # define FLD 103 | |
115 | # define SCONV 104 | |
116 | # define PCONV 105 | |
117 | # define PMCONV 106 | |
118 | # define PVCONV 107 | |
119 | ||
120 | /* special node operators, used for special contexts */ | |
121 | # define FORCE 108 | |
122 | # define CBRANCH 109 | |
123 | # define INIT 110 | |
124 | # define CAST 111 | |
125 | ||
126 | /* node types */ | |
127 | # define LTYPE 02 | |
128 | # define UTYPE 04 | |
129 | # define BITYPE 010 | |
130 | ||
131 | /* DSIZE is the size of the dope array */ | |
132 | # define DSIZE CAST+1 | |
133 | ||
134 | /* type names, used in symbol table building */ | |
135 | # define TNULL PTR /* pointer to UNDEF */ | |
136 | # define TVOID FTN /* function returning UNDEF (for void) */ | |
137 | # define UNDEF 0 | |
138 | # define FARG 1 | |
139 | # define CHAR 2 | |
140 | # define SHORT 3 | |
141 | # define INT 4 | |
142 | # define LONG 5 | |
143 | # define FLOAT 6 | |
144 | # define DOUBLE 7 | |
145 | # define STRTY 8 | |
146 | # define UNIONTY 9 | |
147 | # define ENUMTY 10 | |
148 | # define MOETY 11 | |
149 | # define UCHAR 12 | |
150 | # define USHORT 13 | |
151 | # define UNSIGNED 14 | |
152 | # define ULONG 15 | |
153 | ||
154 | # define ASG 1+ | |
155 | # define UNARY 2+ | |
156 | # define NOASG (-1)+ | |
157 | # define NOUNARY (-2)+ | |
158 | ||
159 | /* various flags */ | |
160 | # define NOLAB (-1) | |
161 | ||
162 | /* type modifiers */ | |
163 | ||
164 | # define PTR 020 | |
165 | # define FTN 040 | |
166 | # define ARY 060 | |
167 | ||
168 | /* type packing constants */ | |
169 | ||
170 | # define TMASK 060 | |
171 | # define TMASK1 0300 | |
172 | # define TMASK2 0360 | |
173 | # define BTMASK 017 | |
174 | # define BTSHIFT 4 | |
175 | # define TSHIFT 2 | |
176 | ||
177 | /* macros */ | |
178 | ||
179 | # define MODTYPE(x,y) x = ( (x)&(~BTMASK))|(y) /* set basic type of x to y */ | |
180 | # define BTYPE(x) ( (x)&BTMASK) /* basic type of x */ | |
181 | # define ISUNSIGNED(x) ((x)<=ULONG&&(x)>=UCHAR) | |
182 | # define UNSIGNABLE(x) ((x)<=LONG&&(x)>=CHAR) | |
183 | # define ENUNSIGN(x) ((x)+(UNSIGNED-INT)) | |
184 | # define DEUNSIGN(x) ((x)+(INT-UNSIGNED)) | |
185 | # define ISPTR(x) (( (x)&TMASK)==PTR) | |
186 | # define ISFTN(x) (( (x)&TMASK)==FTN) /* is x a function type */ | |
187 | # define ISARY(x) (( (x)&TMASK)==ARY) /* is x an array type */ | |
188 | # define INCREF(x) ((( (x)&~BTMASK)<<TSHIFT)|PTR|( (x)&BTMASK)) | |
189 | # define DECREF(x) ((( (x)>>TSHIFT)&~BTMASK)|( (x)&BTMASK)) | |
190 | # define SETOFF(x,y) if( (x)%(y) != 0 ) (x) = ( ((x)/(y) + 1) * (y)) | |
191 | /* advance x to a multiple of y */ | |
192 | # define NOFIT(x,y,z) ( ( (x)%(z) + (y) ) > (z) ) | |
193 | /* can y bits be added to x without overflowing z */ | |
194 | /* pack and unpack field descriptors (size and offset) */ | |
195 | # define PKFIELD(s,o) (( (o)<<6)| (s) ) | |
196 | # define UPKFSZ(v) ( (v) &077) | |
197 | # define UPKFOFF(v) ( (v) >>6) | |
198 | ||
199 | /* operator information */ | |
200 | ||
201 | # define TYFLG 016 | |
202 | # define ASGFLG 01 | |
203 | # define LOGFLG 020 | |
204 | ||
205 | # define SIMPFLG 040 | |
206 | # define COMMFLG 0100 | |
207 | # define DIVFLG 0200 | |
208 | # define FLOFLG 0400 | |
209 | # define LTYFLG 01000 | |
210 | # define CALLFLG 02000 | |
211 | # define MULFLG 04000 | |
212 | # define SHFFLG 010000 | |
213 | # define ASGOPFLG 020000 | |
214 | ||
215 | # define SPFLG 040000 | |
216 | ||
217 | #define optype(o) (dope[o]&TYFLG) | |
218 | #define asgop(o) (dope[o]&ASGFLG) | |
219 | #define logop(o) (dope[o]&LOGFLG) | |
220 | #define callop(o) (dope[o]&CALLFLG) | |
221 | ||
222 | /* table sizes */ | |
223 | ||
224 | # ifndef FORT | |
225 | # define TREESZ 350 /* space for building parse tree */ | |
226 | # else | |
227 | # define TREESZ 1000 | |
228 | # endif | |
229 | ||
230 | #ifndef FLEXNAMES | |
231 | # define NCHNAM 8 /* number of characters in a name */ | |
232 | #else | |
233 | char *hash(); | |
234 | char *savestr(); | |
235 | char *tstr(); | |
236 | int tstrused; | |
237 | char *tstrbuf[], **curtstr; | |
238 | #define freetstr() curtstr = tstrbuf, tstrused = 0 | |
239 | #endif | |
240 | ||
241 | /* common defined variables */ | |
242 | ||
243 | extern int nerrors; /* number of errors seen so far */ | |
244 | ||
245 | typedef union ndu NODE; | |
246 | typedef unsigned int TWORD; | |
247 | # define NIL (NODE *)0 | |
248 | extern int dope[]; /* a vector containing operator information */ | |
249 | extern char *opst[]; /* a vector containing names for ops */ | |
250 | ||
251 | # ifdef ONEPASS | |
252 | /* in one-pass operation, define the tree nodes */ | |
253 | ||
254 | union ndu { | |
255 | ||
256 | struct { | |
257 | int op; | |
258 | int rall; | |
259 | TWORD type; | |
260 | int su; | |
261 | #ifndef FLEXNAMES | |
262 | char name[NCHNAM]; | |
263 | #else | |
264 | char *name; | |
265 | int stalign; | |
266 | #endif | |
267 | NODE *left; | |
268 | NODE *right; | |
269 | }in; /* interior node */ | |
270 | ||
271 | struct { | |
272 | int op; | |
273 | int rall; | |
274 | TWORD type; | |
275 | int su; | |
276 | #ifndef FLEXNAMES | |
277 | char name[NCHNAM]; | |
278 | #else | |
279 | char *name; | |
280 | int stalign; | |
281 | #endif | |
282 | CONSZ lval; | |
283 | int rval; | |
284 | }tn; /* terminal node */ | |
285 | ||
286 | struct { | |
287 | int op, rall; | |
288 | TWORD type; | |
289 | int su; | |
290 | int label; /* for use with branching */ | |
291 | }bn; /* branch node */ | |
292 | ||
293 | struct { | |
294 | int op, rall; | |
295 | TWORD type; | |
296 | int su; | |
297 | int stsize; /* sizes of structure objects */ | |
298 | int stalign; /* alignment of structure objects */ | |
299 | }stn; /* structure node */ | |
300 | ||
301 | struct { | |
302 | int op; | |
303 | int cdim; | |
304 | TWORD type; | |
305 | int csiz; | |
306 | }fn; /* front node */ | |
307 | ||
308 | struct { | |
309 | /* this structure is used when a floating point constant | |
310 | is being computed */ | |
311 | int op; | |
312 | int cdim; | |
313 | TWORD type; | |
314 | int csiz; | |
315 | double dval; | |
316 | }fpn; /* floating point node */ | |
317 | ||
318 | }; | |
319 | # endif | |
320 | # ifdef BUG2 | |
321 | # define BUG1 | |
322 | # endif | |
323 | # ifdef BUG3 | |
324 | # define BUG2 | |
325 | # define BUG1 | |
326 | # endif | |
327 | # ifdef BUG4 | |
328 | # define BUG1 | |
329 | # define BUG2 | |
330 | # define BUG3 | |
331 | # endif | |
332 | # ifndef ONEPASS | |
333 | ||
334 | # ifndef EXPR | |
335 | # define EXPR '.' | |
336 | # endif | |
337 | # ifndef BBEG | |
338 | # define BBEG '[' | |
339 | # endif | |
340 | # ifndef BEND | |
341 | # define BEND ']' | |
342 | # endif | |
343 | ||
344 | # endif |