2 /* A Bison parser, made from expread.y */
12 #define NAME_OR_INT 266
13 #define NAME_OR_UINT 267
19 #define COLONCOLON 273
24 #define INT_KEYWORD 278
28 #define ASSIGN_MODIFY 282
30 #define ABOVE_COMMA 284
51 #include "expression.h"
55 static struct expression *expout;
56 static int expout_size;
57 static int expout_ptr;
60 static void yyerror ();
61 static void write_exp_elt ();
62 static void write_exp_elt_opcode ();
63 static void write_exp_elt_sym ();
64 static void write_exp_elt_longcst ();
65 static void write_exp_elt_dblcst ();
66 static void write_exp_elt_type ();
67 static void write_exp_elt_intern ();
68 static void write_exp_string ();
69 static void start_arglist ();
70 static int end_arglist ();
71 static void free_funcalls ();
72 static char *copy_name ();
73 static int parse_number ();
75 /* If this is nonzero, this block is used as the lexical context
78 static struct block *expression_context_block;
80 /* The innermost context required by the stack and register variables
81 we've encountered so far. */
82 struct block *innermost_block;
84 /* The block in which the most recently discovered symbol was found. */
85 struct block *block_found;
87 /* Number of arguments seen so far in innermost function call. */
88 static int arglist_len;
90 /* Data structure for saving values of arglist_len
91 for function calls whose arguments contain other function calls. */
99 struct funcall *funcall_chain;
101 /* This kind of datum is used to represent the name
102 of a symbol token. */
112 struct stoken stoken;
118 struct stoken stoken;
120 int is_a_field_of_this;
123 /* For parsing of complicated types.
124 An array should be preceded in the list by the size of the array. */
126 {tp_end = -1, tp_pointer, tp_reference, tp_array, tp_function};
127 static enum type_pieces *type_stack;
128 static int type_stack_depth, type_stack_size;
130 static void push_type ();
131 static enum type_pieces pop_type ();
133 /* Allow debugging of parsing. */
136 #line 125 "expread.y"
140 unsigned LONGEST ulval;
146 struct symtoken ssym;
149 enum exp_opcode opcode;
150 struct internalvar *ivar;
169 #define YYLTYPE yyltype
181 #define YYFLAG -32768
184 #define YYTRANSLATE(x) ((unsigned)(x) <= 296 ? yytranslate[x] : 84)
186 static const char yytranslate[] = { 0,
187 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
188 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
189 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
190 2, 2, 59, 2, 2, 2, 51, 37, 2, 58,
191 62, 49, 47, 29, 48, 56, 50, 2, 2, 2,
192 2, 2, 2, 2, 2, 2, 2, 65, 2, 40,
193 31, 41, 32, 46, 2, 2, 2, 2, 2, 2,
194 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
195 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
196 57, 2, 61, 36, 2, 2, 2, 2, 2, 2,
197 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
198 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
199 2, 2, 63, 35, 64, 60, 2, 2, 2, 2,
200 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
201 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
202 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
203 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
204 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
205 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
206 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
207 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
208 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
209 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
210 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
211 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
212 2, 2, 2, 2, 2, 1, 2, 3, 4, 5,
213 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
214 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
215 26, 27, 28, 30, 33, 34, 38, 39, 42, 43,
216 44, 45, 52, 53, 54, 55
219 static const short yyrline[] = { 0,
220 218, 222, 223, 228, 231, 234, 238, 242, 246, 250,
221 254, 258, 262, 266, 272, 276, 282, 286, 290, 294,
222 300, 303, 307, 311, 317, 323, 329, 333, 337, 341,
223 345, 349, 353, 357, 361, 365, 369, 373, 377, 381,
224 385, 389, 393, 397, 401, 405, 409, 413, 419, 429,
225 442, 454, 467, 474, 481, 484, 490, 496, 502, 509,
226 516, 523, 540, 550, 562, 575, 621, 695, 696, 731,
227 733, 735, 738, 740, 745, 751, 753, 757, 759, 763,
228 767, 768, 770, 772, 775, 782, 784, 786, 788, 790,
229 792, 794, 796, 798, 801, 804, 807, 809, 811, 813,
230 817, 818, 824, 830, 839, 844, 851, 852, 853, 854,
234 static const char * const yytname[] = { 0,
235 "error","$illegal.","INT","CHAR","UINT","FLOAT","STRING","NAME","BLOCKNAME","TYPENAME",
236 "NAME_OR_INT","NAME_OR_UINT","STRUCT","UNION","ENUM","SIZEOF","UNSIGNED","COLONCOLON","ERROR","SIGNED",
237 "LONG","SHORT","INT_KEYWORD","LAST","REGNAME","VARIABLE","ASSIGN_MODIFY","THIS","','","ABOVE_COMMA",
238 "'='","'?'","OR","AND","'|'","'^'","'&'","EQUAL","NOTEQUAL","'<'",
239 "'>'","LEQ","GEQ","LSH","RSH","'@'","'+'","'-'","'*'","'/'",
240 "'%'","UNARY","INCREMENT","DECREMENT","ARROW","'.'","'['","'('","'!'","'~'",
241 "']'","')'","'{'","'}'","':'","start"
244 static const short yyr1[] = { 0,
245 66, 67, 67, 68, 68, 68, 68, 68, 68, 68,
246 68, 68, 68, 68, 68, 68, 68, 68, 69, 68,
247 70, 70, 70, 68, 68, 68, 68, 68, 68, 68,
248 68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
249 68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
250 68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
251 68, 71, 71, 72, 72, 72, 72, 73, 73, 74,
252 74, 74, 75, 75, 75, 75, 75, 76, 76, 77,
253 78, 78, 78, 78, 78, 79, 79, 79, 79, 79,
254 79, 79, 79, 79, 79, 79, 79, 79, 79, 79,
255 80, 80, 80, 80, 81, 81, 82, 82, 82, 82,
259 static const short yyr2[] = { 0,
260 1, 1, 3, 2, 2, 2, 2, 2, 2, 2,
261 2, 2, 2, 3, 4, 3, 4, 4, 0, 5,
262 0, 1, 3, 4, 4, 3, 3, 3, 3, 3,
263 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
264 3, 3, 3, 3, 3, 5, 3, 3, 1, 1,
265 1, 1, 1, 1, 1, 1, 1, 1, 4, 1,
266 1, 1, 3, 3, 3, 2, 1, 1, 2, 1,
267 2, 1, 3, 2, 1, 2, 1, 2, 3, 2,
268 1, 3, 6, 8, 9, 1, 1, 1, 1, 2,
269 3, 2, 3, 2, 2, 2, 2, 1, 2, 1,
270 1, 1, 1, 1, 1, 3, 1, 1, 1, 1,
274 static const short yydefact[] = { 0,
275 49, 53, 51, 54, 60, 112, 113, 86, 50, 52,
276 0, 0, 0, 0, 98, 0, 100, 88, 89, 87,
277 56, 57, 58, 61, 0, 0, 0, 0, 0, 0,
278 0, 0, 0, 1, 2, 0, 55, 0, 67, 107,
279 108, 109, 110, 111, 94, 95, 96, 0, 13, 101,
280 103, 104, 102, 97, 66, 103, 104, 99, 90, 92,
281 5, 6, 4, 9, 10, 0, 81, 0, 68, 7,
282 8, 0, 68, 0, 0, 0, 0, 0, 0, 0,
283 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
284 0, 0, 0, 0, 0, 0, 11, 12, 0, 0,
285 0, 19, 0, 0, 0, 91, 93, 26, 0, 0,
286 0, 70, 0, 0, 69, 72, 75, 77, 0, 0,
287 3, 48, 47, 0, 45, 44, 43, 42, 41, 35,
288 36, 39, 40, 37, 38, 33, 34, 27, 31, 32,
289 28, 29, 30, 0, 14, 0, 16, 0, 21, 64,
290 65, 59, 0, 25, 82, 71, 0, 78, 80, 0,
291 0, 74, 76, 24, 0, 15, 17, 18, 22, 0,
292 0, 79, 73, 46, 0, 20, 0, 23, 83, 0,
293 84, 105, 0, 0, 85, 106, 0, 0, 0
296 static const short yydefgoto[] = { 187,
297 66, 35, 149, 170, 36, 37, 67, 115, 116, 117,
298 118, 68, 38, 54, 183, 151, 39
301 static const short yypact[] = { 159,
302 -32768,-32768,-32768,-32768,-32768,-32768, -13,-32768,-32768,-32768,
303 21, 21, 21, 220, 121, 21, 124, -15, 3,-32768,
304 -32768,-32768,-32768,-32768, 159, 159, 159, 159, 159, 159,
305 159, 159, 272, 80, 306, 32,-32768, 99,-32768,-32768,
306 -32768,-32768,-32768,-32768,-32768,-32768,-32768, 159, 508,-32768,
307 100, 101,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
308 508, 508, 508, 508, 508, -4,-32768, -52, 79, 508,
309 508, -55, 92, 159, 159, 159, 159, 159, 159, 159,
310 159, 159, 159, 159, 159, 159, 159, 159, 159, 159,
311 159, 159, 159, 159, 159, 159,-32768,-32768, 90, 104,
312 159,-32768, 21, 21, -35,-32768,-32768,-32768, 272, 159,
313 110, 157, 25, 209,-32768, 30,-32768,-32768, 159, 84,
314 306, 306, 306, 271, 358, 382, 405, 427, 448, 467,
315 467, 144, 144, 144, 144, 480, 480, 492, 502, 502,
316 508, 508, 508, 159,-32768, 159,-32768, 66, 159, 111,
317 -32768, 31, 122, 508,-32768,-32768, 94,-32768,-32768, 95,
318 98,-32768,-32768, 508, 159, 508, 508,-32768, 306, 63,
319 107,-32768,-32768, 333, 159,-32768, 116, 306, 128, 239,
320 -32768, 145, 64, 272,-32768, 145, 204, 205,-32768
323 static const short yypgoto[] = {-32768,
324 2, -14,-32768,-32768,-32768,-32768,-32768, -8,-32768, 93,
325 105, -32, -26, 193,-32768, 8,-32768
332 static const short yytable[] = { 49,
333 72, 34, 109, 69, -62, 109, 73, 59, 119, 110,
334 61, 62, 63, 64, 65, 105, 70, 71, 45, 46,
335 47, 69, 109, 55, 74, 60, 152, 157, 40, 41,
336 42, 43, 44, 1, 2, 3, 4, 5, 6, 7,
337 8, 9, 10, 11, 12, 13, 14, 15, 16, 103,
338 17, 18, 19, 20, 21, 22, 23, 108, 24, 121,
339 122, 123, 124, 125, 126, 127, 128, 129, 130, 131,
340 132, 133, 134, 135, 136, 137, 138, 139, 140, 141,
341 142, 143, 153, 28, 29, 158, 113, 161, 30, 31,
342 32, 175, 184, 33, 74, 154, 111, 40, 41, 42,
343 43, 44, 148, 156, 164, 160, 145, 147, 74, 120,
344 150, 40, 41, 42, 43, 44, 104, 40, 41, 42,
345 43, 44, 106, 107, 176, 185, 168, 112, -63, 166,
346 50, 167, 155, 50, 169, 113, 114, 154, 144, 171,
347 112, 51, 52, 53, 56, 57, 53, 182, 113, 114,
348 174, 186, 146, 73, 172, 177, 173, 73, 155, 159,
349 178, 1, 2, 3, 4, 5, 6, 7, 8, 9,
350 10, 11, 12, 13, 14, 15, 16, 179, 17, 18,
351 19, 20, 21, 22, 23, 180, 24, 89, 90, 91,
352 92, 93, 94, 95, 96, 25, 97, 98, 99, 100,
353 101, 102, 109, 188, 189, 112, 26, 27, 162, 58,
354 0, 28, 29, 113, 114, 0, 30, 31, 32, 0,
355 163, 33, 1, 2, 3, 4, 5, 6, 7, 8,
356 9, 10, 11, 12, 13, 14, 15, 16, 0, 17,
357 18, 19, 20, 21, 22, 23, 0, 24, 8, 0,
358 0, 11, 12, 13, 0, 15, 25, 112, 17, 18,
359 19, 20, 0, 0, 0, 113, 114, 26, 27, 0,
360 159, 0, 28, 29, 0, 0, 0, 48, 31, 32,
361 0, 8, 33, 0, 11, 12, 13, 0, 15, 0,
362 0, 17, 18, 19, 20, 0, 0, 75, 0, 0,
363 181, 76, 77, 78, 79, 80, 81, 82, 83, 84,
364 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
365 95, 96, 0, 97, 98, 99, 100, 101, 102, 0,
366 0, 0, 75, 0, 0, 165, 76, 77, 78, 79,
367 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
368 90, 91, 92, 93, 94, 95, 96, 0, 97, 98,
369 99, 100, 101, 102, 77, 78, 79, 80, 81, 82,
370 83, 84, 85, 86, 87, 88, 89, 90, 91, 92,
371 93, 94, 95, 96, 0, 97, 98, 99, 100, 101,
372 102, 79, 80, 81, 82, 83, 84, 85, 86, 87,
373 88, 89, 90, 91, 92, 93, 94, 95, 96, 0,
374 97, 98, 99, 100, 101, 102, 80, 81, 82, 83,
375 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
376 94, 95, 96, 0, 97, 98, 99, 100, 101, 102,
377 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
378 91, 92, 93, 94, 95, 96, 0, 97, 98, 99,
379 100, 101, 102, 82, 83, 84, 85, 86, 87, 88,
380 89, 90, 91, 92, 93, 94, 95, 96, 0, 97,
381 98, 99, 100, 101, 102, 83, 84, 85, 86, 87,
382 88, 89, 90, 91, 92, 93, 94, 95, 96, 0,
383 97, 98, 99, 100, 101, 102, 85, 86, 87, 88,
384 89, 90, 91, 92, 93, 94, 95, 96, 0, 97,
385 98, 99, 100, 101, 102, 91, 92, 93, 94, 95,
386 96, 0, 97, 98, 99, 100, 101, 102, 92, 93,
387 94, 95, 96, 0, 97, 98, 99, 100, 101, 102,
388 94, 95, 96, 0, 97, 98, 99, 100, 101, 102,
389 97, 98, 99, 100, 101, 102
392 static const short yycheck[] = { 14,
393 33, 0, 58, 30, 18, 58, 33, 23, 64, 62,
394 25, 26, 27, 28, 29, 48, 31, 32, 11, 12,
395 13, 48, 58, 16, 29, 23, 62, 3, 8, 9,
396 10, 11, 12, 3, 4, 5, 6, 7, 8, 9,
397 10, 11, 12, 13, 14, 15, 16, 17, 18, 18,
398 20, 21, 22, 23, 24, 25, 26, 62, 28, 74,
399 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
400 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
401 95, 96, 109, 53, 54, 61, 57, 58, 58, 59,
402 60, 29, 29, 63, 29, 110, 18, 8, 9, 10,
403 11, 12, 101, 112, 119, 114, 99, 100, 29, 18,
404 103, 8, 9, 10, 11, 12, 18, 8, 9, 10,
405 11, 12, 23, 23, 62, 62, 61, 49, 18, 144,
406 10, 146, 49, 10, 149, 57, 58, 152, 49, 18,
407 49, 21, 22, 23, 21, 22, 23, 180, 57, 58,
408 165, 184, 49, 180, 61, 49, 62, 184, 49, 62,
409 175, 3, 4, 5, 6, 7, 8, 9, 10, 11,
410 12, 13, 14, 15, 16, 17, 18, 62, 20, 21,
411 22, 23, 24, 25, 26, 58, 28, 44, 45, 46,
412 47, 48, 49, 50, 51, 37, 53, 54, 55, 56,
413 57, 58, 58, 0, 0, 49, 48, 49, 116, 17,
414 -1, 53, 54, 57, 58, -1, 58, 59, 60, -1,
415 116, 63, 3, 4, 5, 6, 7, 8, 9, 10,
416 11, 12, 13, 14, 15, 16, 17, 18, -1, 20,
417 21, 22, 23, 24, 25, 26, -1, 28, 10, -1,
418 -1, 13, 14, 15, -1, 17, 37, 49, 20, 21,
419 22, 23, -1, -1, -1, 57, 58, 48, 49, -1,
420 62, -1, 53, 54, -1, -1, -1, 58, 59, 60,
421 -1, 10, 63, -1, 13, 14, 15, -1, 17, -1,
422 -1, 20, 21, 22, 23, -1, -1, 27, -1, -1,
423 62, 31, 32, 33, 34, 35, 36, 37, 38, 39,
424 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
425 50, 51, -1, 53, 54, 55, 56, 57, 58, -1,
426 -1, -1, 27, -1, -1, 65, 31, 32, 33, 34,
427 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
428 45, 46, 47, 48, 49, 50, 51, -1, 53, 54,
429 55, 56, 57, 58, 32, 33, 34, 35, 36, 37,
430 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
431 48, 49, 50, 51, -1, 53, 54, 55, 56, 57,
432 58, 34, 35, 36, 37, 38, 39, 40, 41, 42,
433 43, 44, 45, 46, 47, 48, 49, 50, 51, -1,
434 53, 54, 55, 56, 57, 58, 35, 36, 37, 38,
435 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
436 49, 50, 51, -1, 53, 54, 55, 56, 57, 58,
437 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
438 46, 47, 48, 49, 50, 51, -1, 53, 54, 55,
439 56, 57, 58, 37, 38, 39, 40, 41, 42, 43,
440 44, 45, 46, 47, 48, 49, 50, 51, -1, 53,
441 54, 55, 56, 57, 58, 38, 39, 40, 41, 42,
442 43, 44, 45, 46, 47, 48, 49, 50, 51, -1,
443 53, 54, 55, 56, 57, 58, 40, 41, 42, 43,
444 44, 45, 46, 47, 48, 49, 50, 51, -1, 53,
445 54, 55, 56, 57, 58, 46, 47, 48, 49, 50,
446 51, -1, 53, 54, 55, 56, 57, 58, 47, 48,
447 49, 50, 51, -1, 53, 54, 55, 56, 57, 58,
448 49, 50, 51, -1, 53, 54, 55, 56, 57, 58,
449 53, 54, 55, 56, 57, 58
453 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
454 #line 3 "bison.simple"
456 /* Skeleton output parser for bison,
457 Copyright (C) 1984 Bob Corbett and Richard Stallman
459 This program is free software; you can redistribute it and/or modify
460 it under the terms of the GNU General Public License as published by
461 the Free Software Foundation; either version 1, or (at your option)
464 This program is distributed in the hope that it will be useful,
465 but WITHOUT ANY WARRANTY; without even the implied warranty of
466 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
467 GNU General Public License for more details.
469 You should have received a copy of the GNU General Public License
470 along with this program; if not, write to the Free Software
471 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
474 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__)
478 /* This is the parser code that is written into each bison parser
479 when the %semantic_parser declaration is not specified in the grammar.
480 It was written by Richard Stallman by simplifying the hairy parser
481 used when %semantic_parser is specified. */
483 /* Note: there must be only one dollar sign in this file.
484 It is replaced by the list of actions, each action
485 as one case of the switch. */
487 #define yyerrok (yyerrstatus = 0)
488 #define yyclearin (yychar = YYEMPTY)
491 #define YYFAIL goto yyerrlab;
492 #define YYACCEPT return(0)
493 #define YYABORT return(1)
494 #define YYERROR goto yyerrlab
497 #define YYERRCODE 256
500 #define YYLEX yylex()
504 #define YYLEX yylex(&yylval, &yylloc)
507 /* If nonreentrant, generate the variables here */
511 int yychar; /* the lookahead symbol */
512 YYSTYPE yylval; /* the semantic value of the */
513 /* lookahead symbol */
515 YYLTYPE yylloc; /* location data for the lookahead */
518 int yynerrs; /* number of parse errors so far */
519 #endif /* YYIMPURE */
522 int yydebug; /* nonzero means print parse trace */
523 /* Since this is uninitialized, it does not stop multiple parsers
527 /* YYMAXDEPTH indicates the initial size of the parser's stacks */
530 #define YYMAXDEPTH 200
533 /* YYMAXLIMIT is the maximum size the stacks can grow to
534 (effective only if the built-in stack extension method is used). */
537 #define YYMAXLIMIT 10000
541 #line 90 "bison.simple"
545 register int yystate;
547 register short *yyssp;
548 register YYSTYPE *yyvsp;
550 int yyerrstatus; /* number of tokens to shift before error messages enabled */
551 int yychar1; /* lookahead token as an internal (translated) token number */
553 short yyssa[YYMAXDEPTH]; /* the state stack */
554 YYSTYPE yyvsa[YYMAXDEPTH]; /* the semantic value stack */
555 YYLTYPE yylsa[YYMAXDEPTH]; /* the location stack */
557 short *yyss = yyssa; /* refer to the stacks thru separate pointers */
558 YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
559 YYLTYPE *yyls = yylsa;
561 int yymaxdepth = YYMAXDEPTH;
570 YYSTYPE yyval; /* the variable used to return */
571 /* semantic values from the action */
578 fprintf(stderr, "Starting parse\n");
584 yychar = YYEMPTY; /* Cause a token to be read. */
586 /* Initialize stack pointers.
587 Waste one element of value and location stack
588 so that they stay on the same level as the state stack. */
594 /* Push a new state, which is found in yystate . */
595 /* In all cases, when you get here, the value and location stacks
596 have just been pushed. so pushing a state here evens the stacks. */
601 if (yyssp >= yyss + yymaxdepth - 1)
603 /* Give user a chance to reallocate the stack */
604 /* Use copies of these so that the &'s don't force the real ones into memory. */
605 YYSTYPE *yyvs1 = yyvs;
606 YYLTYPE *yyls1 = yyls;
609 /* Get the current used size of the three stacks, in elements. */
610 int size = yyssp - yyss + 1;
613 /* Each stack pointer address is followed by the size of
614 the data in use in that stack, in bytes. */
615 yyoverflow("parser stack overflow",
616 &yyss1, size * sizeof (*yyssp),
617 &yyvs1, size * sizeof (*yyvsp),
618 &yyls1, size * sizeof (*yylsp),
621 yyss = yyss1; yyvs = yyvs1; yyls = yyls1;
622 #else /* no yyoverflow */
623 /* Extend the stack our own way. */
624 if (yymaxdepth >= YYMAXLIMIT)
625 yyerror("parser stack overflow");
627 if (yymaxdepth > YYMAXLIMIT)
628 yymaxdepth = YYMAXLIMIT;
629 yyss = (short *) alloca (yymaxdepth * sizeof (*yyssp));
630 bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
631 yyvs = (YYSTYPE *) alloca (yymaxdepth * sizeof (*yyvsp));
632 bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
634 yyls = (YYLTYPE *) alloca (yymaxdepth * sizeof (*yylsp));
635 bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
637 #endif /* no yyoverflow */
639 yyssp = yyss + size - 1;
640 yyvsp = yyvs + size - 1;
642 yylsp = yyls + size - 1;
647 fprintf(stderr, "Stack size increased to %d\n", yymaxdepth);
650 if (yyssp >= yyss + yymaxdepth - 1)
656 fprintf(stderr, "Entering state %d\n", yystate);
659 /* Do appropriate processing given the current state. */
660 /* Read a lookahead token if we need one and don't already have one. */
663 /* First try to decide what to do without reference to lookahead token. */
665 yyn = yypact[yystate];
669 /* Not known => get a lookahead token if don't already have one. */
671 /* yychar is either YYEMPTY or YYEOF
672 or a valid token in external form. */
674 if (yychar == YYEMPTY)
678 fprintf(stderr, "Reading a token: ");
683 /* Convert token to internal form (in yychar1) for indexing tables with */
685 if (yychar <= 0) /* This means end of input. */
688 yychar = YYEOF; /* Don't call YYLEX any more */
692 fprintf(stderr, "Now at end of input.\n");
697 yychar1 = YYTRANSLATE(yychar);
701 fprintf(stderr, "Next token is %d (%s)\n", yychar, yytname[yychar1]);
706 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
711 /* yyn is what to do for this token type in this state.
712 Negative => reduce, -yyn is rule number.
713 Positive => shift, yyn is new state.
714 New state is final state => don't bother to shift,
716 0, or most negative number => error. */
731 /* Shift the lookahead token. */
735 fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
738 /* Discard the token being shifted unless it is eof. */
747 /* count tokens shifted since error; after three, turn off error status. */
748 if (yyerrstatus) yyerrstatus--;
753 /* Do the default action for the current state. */
756 yyn = yydefact[yystate];
760 /* Do a reduction. yyn is the number of a rule to reduce with. */
763 yyval = yyvsp[1-yylen]; /* implement default value of the action */
769 fprintf (stderr, "Reducing 1 value via line %d, ",
772 fprintf (stderr, "Reducing %d values via line %d, ",
773 yylen, yyrline[yyn]);
781 #line 224 "expread.y"
782 { write_exp_elt_opcode (BINOP_COMMA); ;
785 #line 229 "expread.y"
786 { write_exp_elt_opcode (UNOP_IND); ;
789 #line 232 "expread.y"
790 { write_exp_elt_opcode (UNOP_ADDR); ;
793 #line 235 "expread.y"
794 { write_exp_elt_opcode (UNOP_NEG); ;
797 #line 239 "expread.y"
798 { write_exp_elt_opcode (UNOP_ZEROP); ;
801 #line 243 "expread.y"
802 { write_exp_elt_opcode (UNOP_LOGNOT); ;
805 #line 247 "expread.y"
806 { write_exp_elt_opcode (UNOP_PREINCREMENT); ;
809 #line 251 "expread.y"
810 { write_exp_elt_opcode (UNOP_PREDECREMENT); ;
813 #line 255 "expread.y"
814 { write_exp_elt_opcode (UNOP_POSTINCREMENT); ;
817 #line 259 "expread.y"
818 { write_exp_elt_opcode (UNOP_POSTDECREMENT); ;
821 #line 263 "expread.y"
822 { write_exp_elt_opcode (UNOP_SIZEOF); ;
825 #line 267 "expread.y"
826 { write_exp_elt_opcode (STRUCTOP_PTR);
827 write_exp_string (yyvsp[0].sval);
828 write_exp_elt_opcode (STRUCTOP_PTR); ;
831 #line 273 "expread.y"
832 { write_exp_elt_opcode (STRUCTOP_MPTR); ;
835 #line 277 "expread.y"
836 { write_exp_elt_opcode (STRUCTOP_STRUCT);
837 write_exp_string (yyvsp[0].sval);
838 write_exp_elt_opcode (STRUCTOP_STRUCT); ;
841 #line 283 "expread.y"
842 { write_exp_elt_opcode (STRUCTOP_MEMBER); ;
845 #line 287 "expread.y"
846 { write_exp_elt_opcode (BINOP_SUBSCRIPT); ;
849 #line 293 "expread.y"
850 { start_arglist (); ;
853 #line 295 "expread.y"
854 { write_exp_elt_opcode (OP_FUNCALL);
855 write_exp_elt_longcst ((LONGEST) end_arglist ());
856 write_exp_elt_opcode (OP_FUNCALL); ;
859 #line 304 "expread.y"
863 #line 308 "expread.y"
867 #line 312 "expread.y"
868 { write_exp_elt_opcode (UNOP_MEMVAL);
869 write_exp_elt_type (yyvsp[-2].tval);
870 write_exp_elt_opcode (UNOP_MEMVAL); ;
873 #line 318 "expread.y"
874 { write_exp_elt_opcode (UNOP_CAST);
875 write_exp_elt_type (yyvsp[-2].tval);
876 write_exp_elt_opcode (UNOP_CAST); ;
879 #line 324 "expread.y"
883 #line 330 "expread.y"
884 { write_exp_elt_opcode (BINOP_REPEAT); ;
887 #line 334 "expread.y"
888 { write_exp_elt_opcode (BINOP_MUL); ;
891 #line 338 "expread.y"
892 { write_exp_elt_opcode (BINOP_DIV); ;
895 #line 342 "expread.y"
896 { write_exp_elt_opcode (BINOP_REM); ;
899 #line 346 "expread.y"
900 { write_exp_elt_opcode (BINOP_ADD); ;
903 #line 350 "expread.y"
904 { write_exp_elt_opcode (BINOP_SUB); ;
907 #line 354 "expread.y"
908 { write_exp_elt_opcode (BINOP_LSH); ;
911 #line 358 "expread.y"
912 { write_exp_elt_opcode (BINOP_RSH); ;
915 #line 362 "expread.y"
916 { write_exp_elt_opcode (BINOP_EQUAL); ;
919 #line 366 "expread.y"
920 { write_exp_elt_opcode (BINOP_NOTEQUAL); ;
923 #line 370 "expread.y"
924 { write_exp_elt_opcode (BINOP_LEQ); ;
927 #line 374 "expread.y"
928 { write_exp_elt_opcode (BINOP_GEQ); ;
931 #line 378 "expread.y"
932 { write_exp_elt_opcode (BINOP_LESS); ;
935 #line 382 "expread.y"
936 { write_exp_elt_opcode (BINOP_GTR); ;
939 #line 386 "expread.y"
940 { write_exp_elt_opcode (BINOP_LOGAND); ;
943 #line 390 "expread.y"
944 { write_exp_elt_opcode (BINOP_LOGXOR); ;
947 #line 394 "expread.y"
948 { write_exp_elt_opcode (BINOP_LOGIOR); ;
951 #line 398 "expread.y"
952 { write_exp_elt_opcode (BINOP_AND); ;
955 #line 402 "expread.y"
956 { write_exp_elt_opcode (BINOP_OR); ;
959 #line 406 "expread.y"
960 { write_exp_elt_opcode (TERNOP_COND); ;
963 #line 410 "expread.y"
964 { write_exp_elt_opcode (BINOP_ASSIGN); ;
967 #line 414 "expread.y"
968 { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY);
969 write_exp_elt_opcode (yyvsp[-1].opcode);
970 write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); ;
973 #line 420 "expread.y"
974 { write_exp_elt_opcode (OP_LONG);
975 if (yyvsp[0].lval == (int) yyvsp[0].lval || yyvsp[0].lval == (unsigned int) yyvsp[0].lval)
976 write_exp_elt_type (builtin_type_int);
978 write_exp_elt_type (BUILTIN_TYPE_LONGEST);
979 write_exp_elt_longcst ((LONGEST) yyvsp[0].lval);
980 write_exp_elt_opcode (OP_LONG); ;
983 #line 430 "expread.y"
985 parse_number (yyvsp[0].ssym.stoken.ptr, yyvsp[0].ssym.stoken.length, 0, &val);
986 write_exp_elt_opcode (OP_LONG);
987 if (val.lval == (int) val.lval ||
988 val.lval == (unsigned int) val.lval)
989 write_exp_elt_type (builtin_type_int);
991 write_exp_elt_type (BUILTIN_TYPE_LONGEST);
992 write_exp_elt_longcst (val.lval);
993 write_exp_elt_opcode (OP_LONG); ;
996 #line 443 "expread.y"
998 write_exp_elt_opcode (OP_LONG);
999 if (yyvsp[0].ulval == (unsigned int) yyvsp[0].ulval)
1000 write_exp_elt_type (builtin_type_unsigned_int);
1002 write_exp_elt_type (BUILTIN_TYPE_UNSIGNED_LONGEST);
1003 write_exp_elt_longcst ((LONGEST) yyvsp[0].ulval);
1004 write_exp_elt_opcode (OP_LONG);
1008 #line 455 "expread.y"
1010 parse_number (yyvsp[0].ssym.stoken.ptr, yyvsp[0].ssym.stoken.length, 0, &val);
1011 write_exp_elt_opcode (OP_LONG);
1012 if (val.ulval == (unsigned int) val.ulval)
1013 write_exp_elt_type (builtin_type_unsigned_int);
1015 write_exp_elt_type (BUILTIN_TYPE_UNSIGNED_LONGEST);
1016 write_exp_elt_longcst ((LONGEST)val.ulval);
1017 write_exp_elt_opcode (OP_LONG);
1021 #line 468 "expread.y"
1022 { write_exp_elt_opcode (OP_LONG);
1023 write_exp_elt_type (builtin_type_char);
1024 write_exp_elt_longcst ((LONGEST) yyvsp[0].lval);
1025 write_exp_elt_opcode (OP_LONG); ;
1028 #line 475 "expread.y"
1029 { write_exp_elt_opcode (OP_DOUBLE);
1030 write_exp_elt_type (builtin_type_double);
1031 write_exp_elt_dblcst (yyvsp[0].dval);
1032 write_exp_elt_opcode (OP_DOUBLE); ;
1035 #line 485 "expread.y"
1036 { write_exp_elt_opcode (OP_LAST);
1037 write_exp_elt_longcst ((LONGEST) yyvsp[0].lval);
1038 write_exp_elt_opcode (OP_LAST); ;
1041 #line 491 "expread.y"
1042 { write_exp_elt_opcode (OP_REGISTER);
1043 write_exp_elt_longcst ((LONGEST) yyvsp[0].lval);
1044 write_exp_elt_opcode (OP_REGISTER); ;
1047 #line 497 "expread.y"
1048 { write_exp_elt_opcode (OP_INTERNALVAR);
1049 write_exp_elt_intern (yyvsp[0].ivar);
1050 write_exp_elt_opcode (OP_INTERNALVAR); ;
1053 #line 503 "expread.y"
1054 { write_exp_elt_opcode (OP_LONG);
1055 write_exp_elt_type (builtin_type_int);
1056 write_exp_elt_longcst ((LONGEST) TYPE_LENGTH (yyvsp[-1].tval));
1057 write_exp_elt_opcode (OP_LONG); ;
1060 #line 510 "expread.y"
1061 { write_exp_elt_opcode (OP_STRING);
1062 write_exp_string (yyvsp[0].sval);
1063 write_exp_elt_opcode (OP_STRING); ;
1066 #line 517 "expread.y"
1067 { write_exp_elt_opcode (OP_THIS);
1068 write_exp_elt_opcode (OP_THIS); ;
1071 #line 524 "expread.y"
1073 if (yyvsp[0].ssym.sym != 0)
1074 yyval.bval = SYMBOL_BLOCK_VALUE (yyvsp[0].ssym.sym);
1077 struct symtab *tem =
1078 lookup_symtab (copy_name (yyvsp[0].ssym.stoken));
1080 yyval.bval = BLOCKVECTOR_BLOCK (BLOCKVECTOR (tem), 1);
1082 error ("No file or function \"%s\".",
1083 copy_name (yyvsp[0].ssym.stoken));
1088 #line 541 "expread.y"
1089 { struct symbol *tem
1090 = lookup_symbol (copy_name (yyvsp[0].sval), yyvsp[-2].bval,
1091 VAR_NAMESPACE, 0, NULL);
1092 if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
1093 error ("No function \"%s\" in specified context.",
1094 copy_name (yyvsp[0].sval));
1095 yyval.bval = SYMBOL_BLOCK_VALUE (tem); ;
1098 #line 551 "expread.y"
1099 { struct symbol *sym;
1100 sym = lookup_symbol (copy_name (yyvsp[0].sval), yyvsp[-2].bval,
1101 VAR_NAMESPACE, 0, NULL);
1103 error ("No symbol \"%s\" in specified context.",
1104 copy_name (yyvsp[0].sval));
1105 write_exp_elt_opcode (OP_VAR_VALUE);
1106 write_exp_elt_sym (sym);
1107 write_exp_elt_opcode (OP_VAR_VALUE); ;
1110 #line 563 "expread.y"
1112 struct type *type = yyvsp[-2].tval;
1113 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
1114 && TYPE_CODE (type) != TYPE_CODE_UNION)
1115 error ("`%s' is not defined as an aggregate type.",
1118 write_exp_elt_opcode (OP_SCOPE);
1119 write_exp_elt_type (type);
1120 write_exp_string (yyvsp[0].sval);
1121 write_exp_elt_opcode (OP_SCOPE);
1125 #line 576 "expread.y"
1127 char *name = copy_name (yyvsp[0].sval);
1132 lookup_symbol (name, 0, VAR_NAMESPACE, 0, NULL);
1135 write_exp_elt_opcode (OP_VAR_VALUE);
1136 write_exp_elt_sym (sym);
1137 write_exp_elt_opcode (OP_VAR_VALUE);
1140 for (i = 0; i < misc_function_count; i++)
1141 if (!strcmp (misc_function_vector[i].name, name))
1144 if (i < misc_function_count)
1146 enum misc_function_type mft =
1147 misc_function_vector[i].type;
1149 write_exp_elt_opcode (OP_LONG);
1150 write_exp_elt_type (builtin_type_int);
1151 write_exp_elt_longcst ((LONGEST) misc_function_vector[i].address);
1152 write_exp_elt_opcode (OP_LONG);
1153 write_exp_elt_opcode (UNOP_MEMVAL);
1154 if (mft == mf_data || mft == mf_bss)
1155 write_exp_elt_type (builtin_type_int);
1156 else if (mft == mf_text)
1157 write_exp_elt_type (lookup_function_type (builtin_type_int));
1159 write_exp_elt_type (builtin_type_char);
1160 write_exp_elt_opcode (UNOP_MEMVAL);
1163 if (symtab_list == 0
1164 && partial_symtab_list == 0)
1165 error ("No symbol table is loaded. Use the \"file\" command.");
1167 error ("No symbol \"%s\" in current context.", name);
1171 #line 622 "expread.y"
1172 { struct symbol *sym = yyvsp[0].ssym.sym;
1182 if (innermost_block == 0 ||
1183 contained_in (block_found,
1185 innermost_block = block_found;
1187 write_exp_elt_opcode (OP_VAR_VALUE);
1188 write_exp_elt_sym (sym);
1189 write_exp_elt_opcode (OP_VAR_VALUE);
1191 else if (yyvsp[0].ssym.is_a_field_of_this)
1193 /* C++: it hangs off of `this'. Must
1194 not inadvertently convert from a method call
1196 if (innermost_block == 0 ||
1197 contained_in (block_found, innermost_block))
1198 innermost_block = block_found;
1199 write_exp_elt_opcode (OP_THIS);
1200 write_exp_elt_opcode (OP_THIS);
1201 write_exp_elt_opcode (STRUCTOP_PTR);
1202 write_exp_string (yyvsp[0].ssym.stoken);
1203 write_exp_elt_opcode (STRUCTOP_PTR);
1208 register char *arg = copy_name (yyvsp[0].ssym.stoken);
1210 /* FIXME, this search is linear! At least
1211 optimize the strcmp with a 1-char cmp... */
1212 for (i = 0; i < misc_function_count; i++)
1213 if (!strcmp (misc_function_vector[i].name, arg))
1216 if (i < misc_function_count)
1218 enum misc_function_type mft =
1219 misc_function_vector[i].type;
1221 write_exp_elt_opcode (OP_LONG);
1222 write_exp_elt_type (builtin_type_int);
1223 write_exp_elt_longcst ((LONGEST) misc_function_vector[i].address);
1224 write_exp_elt_opcode (OP_LONG);
1225 write_exp_elt_opcode (UNOP_MEMVAL);
1226 if (mft == mf_data || mft == mf_bss)
1227 write_exp_elt_type (builtin_type_int);
1228 else if (mft == mf_text)
1229 write_exp_elt_type (lookup_function_type (builtin_type_int));
1231 write_exp_elt_type (builtin_type_char);
1232 write_exp_elt_opcode (UNOP_MEMVAL);
1234 else if (symtab_list == 0
1235 && partial_symtab_list == 0)
1236 error ("No symbol table is loaded. Use the \"file\" command.");
1238 error ("No symbol \"%s\" in current context.",
1239 copy_name (yyvsp[0].ssym.stoken));
1244 #line 697 "expread.y"
1246 /* This is where the interesting stuff happens. */
1249 struct type *follow_type = yyvsp[-1].tval;
1252 switch (pop_type ())
1258 follow_type = lookup_pointer_type (follow_type);
1261 follow_type = lookup_reference_type (follow_type);
1264 array_size = (int) pop_type ();
1265 if (array_size != -1)
1266 follow_type = create_array_type (follow_type,
1269 follow_type = lookup_pointer_type (follow_type);
1272 follow_type = lookup_function_type (follow_type);
1275 yyval.tval = follow_type;
1279 #line 732 "expread.y"
1280 { push_type (tp_pointer); yyval.voidval = 0; ;
1283 #line 734 "expread.y"
1284 { push_type (tp_pointer); yyval.voidval = yyvsp[0].voidval; ;
1287 #line 739 "expread.y"
1288 { yyval.voidval = yyvsp[-1].voidval; ;
1291 #line 741 "expread.y"
1293 push_type ((enum type_pieces) yyvsp[0].lval);
1294 push_type (tp_array);
1298 #line 746 "expread.y"
1300 push_type ((enum type_pieces) yyvsp[0].lval);
1301 push_type (tp_array);
1306 #line 752 "expread.y"
1307 { push_type (tp_function); ;
1310 #line 754 "expread.y"
1311 { push_type (tp_function); ;
1314 #line 758 "expread.y"
1315 { yyval.lval = -1; ;
1318 #line 760 "expread.y"
1319 { yyval.lval = yyvsp[-1].lval; ;
1322 #line 764 "expread.y"
1323 { yyval.voidval = 0; ;
1326 #line 769 "expread.y"
1327 { yyval.tval = lookup_member_type (builtin_type_int, yyvsp[-2].tval); ;
1330 #line 771 "expread.y"
1331 { yyval.tval = lookup_member_type (yyvsp[-5].tval, yyvsp[-3].tval); ;
1334 #line 773 "expread.y"
1335 { yyval.tval = lookup_member_type
1336 (lookup_function_type (yyvsp[-7].tval), yyvsp[-5].tval); ;
1339 #line 776 "expread.y"
1340 { yyval.tval = lookup_member_type
1341 (lookup_function_type (yyvsp[-8].tval), yyvsp[-6].tval);
1342 free (yyvsp[-1].tvec); ;
1345 #line 783 "expread.y"
1346 { yyval.tval = yyvsp[0].tsym.type; ;
1349 #line 785 "expread.y"
1350 { yyval.tval = builtin_type_int; ;
1353 #line 787 "expread.y"
1354 { yyval.tval = builtin_type_long; ;
1357 #line 789 "expread.y"
1358 { yyval.tval = builtin_type_short; ;
1361 #line 791 "expread.y"
1362 { yyval.tval = builtin_type_long; ;
1365 #line 793 "expread.y"
1366 { yyval.tval = builtin_type_unsigned_long; ;
1369 #line 795 "expread.y"
1370 { yyval.tval = builtin_type_short; ;
1373 #line 797 "expread.y"
1374 { yyval.tval = builtin_type_unsigned_short; ;
1377 #line 799 "expread.y"
1378 { yyval.tval = lookup_struct (copy_name (yyvsp[0].sval),
1379 expression_context_block); ;
1382 #line 802 "expread.y"
1383 { yyval.tval = lookup_union (copy_name (yyvsp[0].sval),
1384 expression_context_block); ;
1387 #line 805 "expread.y"
1388 { yyval.tval = lookup_enum (copy_name (yyvsp[0].sval),
1389 expression_context_block); ;
1392 #line 808 "expread.y"
1393 { yyval.tval = lookup_unsigned_typename (TYPE_NAME(yyvsp[0].tsym.type)); ;
1396 #line 810 "expread.y"
1397 { yyval.tval = builtin_type_unsigned_int; ;
1400 #line 812 "expread.y"
1401 { yyval.tval = yyvsp[0].tsym.type; ;
1404 #line 814 "expread.y"
1405 { yyval.tval = builtin_type_int; ;
1408 #line 819 "expread.y"
1410 yyval.tsym.stoken.ptr = "int";
1411 yyval.tsym.stoken.length = 3;
1412 yyval.tsym.type = builtin_type_int;
1416 #line 825 "expread.y"
1418 yyval.tsym.stoken.ptr = "long";
1419 yyval.tsym.stoken.length = 4;
1420 yyval.tsym.type = builtin_type_long;
1424 #line 831 "expread.y"
1426 yyval.tsym.stoken.ptr = "short";
1427 yyval.tsym.stoken.length = 5;
1428 yyval.tsym.type = builtin_type_short;
1432 #line 840 "expread.y"
1433 { yyval.tvec = (struct type **)xmalloc (sizeof (struct type *) * 2);
1434 yyval.tvec[0] = (struct type *)0;
1435 yyval.tvec[1] = yyvsp[0].tval;
1439 #line 845 "expread.y"
1440 { int len = sizeof (struct type *) * ++(yyvsp[-2].ivec[0]);
1441 yyval.tvec = (struct type **)xrealloc (yyvsp[-2].tvec, len);
1442 yyval.tvec[yyval.ivec[0]] = yyvsp[0].tval;
1446 #line 851 "expread.y"
1447 { yyval.sval = yyvsp[0].ssym.stoken; ;
1450 #line 852 "expread.y"
1451 { yyval.sval = yyvsp[0].ssym.stoken; ;
1454 #line 853 "expread.y"
1455 { yyval.sval = yyvsp[0].tsym.stoken; ;
1458 #line 854 "expread.y"
1459 { yyval.sval = yyvsp[0].ssym.stoken; ;
1462 #line 855 "expread.y"
1463 { yyval.sval = yyvsp[0].ssym.stoken; ;
1466 /* the action file gets copied in in place of this dollarsign */
1467 #line 327 "bison.simple"
1478 short *ssp1 = yyss - 1;
1479 fprintf (stderr, "state stack now");
1480 while (ssp1 != yyssp)
1481 fprintf (stderr, " %d", *++ssp1);
1482 fprintf (stderr, "\n");
1492 yylsp->first_line = yylloc.first_line;
1493 yylsp->first_column = yylloc.first_column;
1494 yylsp->last_line = (yylsp-1)->last_line;
1495 yylsp->last_column = (yylsp-1)->last_column;
1500 yylsp->last_line = (yylsp+yylen-1)->last_line;
1501 yylsp->last_column = (yylsp+yylen-1)->last_column;
1505 /* Now "shift" the result of the reduction.
1506 Determine what state that goes to,
1507 based on the state we popped back to
1508 and the rule number reduced by. */
1512 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
1513 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1514 yystate = yytable[yystate];
1516 yystate = yydefgoto[yyn - YYNTBASE];
1520 yyerrlab: /* here on detecting error */
1523 /* If not already recovering from an error, report this error. */
1526 yyerror("parse error");
1529 if (yyerrstatus == 3)
1531 /* if just tried and failed to reuse lookahead token after an error, discard it. */
1533 /* return failure if at end of input */
1534 if (yychar == YYEOF)
1539 fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
1545 /* Else will try to reuse lookahead token
1546 after shifting the error token. */
1548 yyerrstatus = 3; /* Each real token shifted decrements this */
1552 yyerrdefault: /* current state does not do anything special for the error token. */
1555 /* This is wrong; only states that explicitly want error tokens
1556 should shift them. */
1557 yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
1558 if (yyn) goto yydefault;
1561 yyerrpop: /* pop the current state because it cannot handle the error token */
1563 if (yyssp == yyss) YYABORT;
1573 short *ssp1 = yyss - 1;
1574 fprintf (stderr, "Error: state stack now");
1575 while (ssp1 != yyssp)
1576 fprintf (stderr, " %d", *++ssp1);
1577 fprintf (stderr, "\n");
1583 yyn = yypact[yystate];
1588 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
1607 fprintf(stderr, "Shifting error token, ");
1618 #line 870 "expread.y"
1621 /* Begin counting arguments for a function call,
1622 saving the data about any containing call. */
1627 register struct funcall *new = (struct funcall *) xmalloc (sizeof (struct funcall));
1629 new->next = funcall_chain;
1630 new->arglist_len = arglist_len;
1632 funcall_chain = new;
1635 /* Return the number of arguments in a function call just terminated,
1636 and restore the data for the containing function call. */
1641 register int val = arglist_len;
1642 register struct funcall *call = funcall_chain;
1643 funcall_chain = call->next;
1644 arglist_len = call->arglist_len;
1649 /* Free everything in the funcall chain.
1650 Used when there is an error inside parsing. */
1655 register struct funcall *call, *next;
1657 for (call = funcall_chain; call; call = next)
1664 /* This page contains the functions for adding data to the struct expression
1665 being constructed. */
1667 /* Add one element to the end of the expression. */
1669 /* To avoid a bug in the Sun 4 compiler, we pass things that can fit into
1670 a register through here */
1673 write_exp_elt (expelt)
1674 union exp_element expelt;
1676 if (expout_ptr >= expout_size)
1679 expout = (struct expression *) xrealloc (expout,
1680 sizeof (struct expression)
1681 + expout_size * sizeof (union exp_element));
1683 expout->elts[expout_ptr++] = expelt;
1687 write_exp_elt_opcode (expelt)
1688 enum exp_opcode expelt;
1690 union exp_element tmp;
1692 tmp.opcode = expelt;
1694 write_exp_elt (tmp);
1698 write_exp_elt_sym (expelt)
1699 struct symbol *expelt;
1701 union exp_element tmp;
1703 tmp.symbol = expelt;
1705 write_exp_elt (tmp);
1709 write_exp_elt_longcst (expelt)
1712 union exp_element tmp;
1714 tmp.longconst = expelt;
1716 write_exp_elt (tmp);
1720 write_exp_elt_dblcst (expelt)
1723 union exp_element tmp;
1725 tmp.doubleconst = expelt;
1727 write_exp_elt (tmp);
1731 write_exp_elt_type (expelt)
1732 struct type *expelt;
1734 union exp_element tmp;
1738 write_exp_elt (tmp);
1742 write_exp_elt_intern (expelt)
1743 struct internalvar *expelt;
1745 union exp_element tmp;
1747 tmp.internalvar = expelt;
1749 write_exp_elt (tmp);
1752 /* Add a string constant to the end of the expression.
1753 Follow it by its length in bytes, as a separate exp_element. */
1756 write_exp_string (str)
1759 register int len = str.length;
1761 = (len + sizeof (union exp_element)) / sizeof (union exp_element);
1763 expout_ptr += lenelt;
1765 if (expout_ptr >= expout_size)
1767 expout_size = max (expout_size * 2, expout_ptr + 10);
1768 expout = (struct expression *)
1769 xrealloc (expout, (sizeof (struct expression)
1770 + (expout_size * sizeof (union exp_element))));
1772 bcopy (str.ptr, (char *) &expout->elts[expout_ptr - lenelt], len);
1773 ((char *) &expout->elts[expout_ptr - lenelt])[len] = 0;
1774 write_exp_elt_longcst ((LONGEST) len);
1777 /* During parsing of a C expression, the pointer to the next character
1778 is in this variable. */
1780 static char *lexptr;
1782 /* Tokens that refer to names do so with explicit pointer and length,
1783 so they can share the storage that lexptr is parsing.
1785 When it is necessary to pass a name to a function that expects
1786 a null-terminated string, the substring is copied out
1787 into a block of storage that namecopy points to.
1789 namecopy is allocated once, guaranteed big enough, for each parsing. */
1791 static char *namecopy;
1793 /* Current depth in parentheses within the expression. */
1795 static int paren_depth;
1797 /* Nonzero means stop parsing on first comma (if not within parentheses). */
1799 static int comma_terminates;
1801 /* Take care of parsing a number (anything that starts with a digit).
1802 Set yylval and return the token type; update lexptr.
1803 LEN is the number of characters in it. */
1805 /*** Needs some error checking for the float case ***/
1808 parse_number (p, len, parsed_float, putithere)
1814 register LONGEST n = 0;
1817 register int base = input_radix;
1820 extern double atof ();
1824 /* It's a float since it contains a point or an exponent. */
1825 putithere->dval = atof (p);
1829 /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
1863 if (c >= 'A' && c <= 'Z')
1865 if (c != 'l' && c != 'u')
1867 if (c >= '0' && c <= '9')
1871 if (base > 10 && c >= 'a' && c <= 'f')
1872 n += i = c - 'a' + 10;
1873 else if (len == 0 && c == 'l')
1875 else if (len == 0 && c == 'u')
1878 return ERROR; /* Char not a digit */
1881 return ERROR; /* Invalid digit in this base */
1886 putithere->ulval = n;
1891 putithere->lval = n;
1900 enum exp_opcode opcode;
1903 static struct token tokentab3[] =
1905 {">>=", ASSIGN_MODIFY, BINOP_RSH},
1906 {"<<=", ASSIGN_MODIFY, BINOP_LSH}
1909 static struct token tokentab2[] =
1911 {"+=", ASSIGN_MODIFY, BINOP_ADD},
1912 {"-=", ASSIGN_MODIFY, BINOP_SUB},
1913 {"*=", ASSIGN_MODIFY, BINOP_MUL},
1914 {"/=", ASSIGN_MODIFY, BINOP_DIV},
1915 {"%=", ASSIGN_MODIFY, BINOP_REM},
1916 {"|=", ASSIGN_MODIFY, BINOP_LOGIOR},
1917 {"&=", ASSIGN_MODIFY, BINOP_LOGAND},
1918 {"^=", ASSIGN_MODIFY, BINOP_LOGXOR},
1919 {"++", INCREMENT, BINOP_END},
1920 {"--", DECREMENT, BINOP_END},
1921 {"->", ARROW, BINOP_END},
1922 {"&&", AND, BINOP_END},
1923 {"||", OR, BINOP_END},
1924 {"::", COLONCOLON, BINOP_END},
1925 {"<<", LSH, BINOP_END},
1926 {">>", RSH, BINOP_END},
1927 {"==", EQUAL, BINOP_END},
1928 {"!=", NOTEQUAL, BINOP_END},
1929 {"<=", LEQ, BINOP_END},
1930 {">=", GEQ, BINOP_END}
1933 /* assign machine-independent names to certain registers
1934 * (unless overridden by the REGISTER_NAMES table)
1941 { "pc", PC_REGNUM },
1944 { "fp", FP_REGNUM },
1947 { "sp", SP_REGNUM },
1950 { "ps", PS_REGNUM },
1954 #define NUM_STD_REGS (sizeof std_regs / sizeof std_regs[0])
1956 /* Read one token, getting characters through lexptr. */
1962 register int namelen;
1963 register unsigned i;
1964 register char *tokstart;
1969 /* See if it is a special token of length 3. */
1970 for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++)
1971 if (!strncmp (tokstart, tokentab3[i].operator, 3))
1974 yylval.opcode = tokentab3[i].opcode;
1975 return tokentab3[i].token;
1978 /* See if it is a special token of length 2. */
1979 for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++)
1980 if (!strncmp (tokstart, tokentab2[i].operator, 2))
1983 yylval.opcode = tokentab2[i].opcode;
1984 return tokentab2[i].token;
1987 switch (c = *tokstart)
2002 c = parse_escape (&lexptr);
2006 error ("Invalid character constant.");
2015 if (paren_depth == 0)
2022 if (comma_terminates && paren_depth == 0)
2028 /* Might be a floating point number. */
2029 if (lexptr[1] < '0' || lexptr[1] > '9')
2030 goto symbol; /* Nope, must be a symbol. */
2031 /* FALL THRU into number case. */
2044 /* It's a number. */
2045 int got_dot = 0, got_e = 0, toktype;
2046 register char *p = tokstart;
2047 int hex = input_radix > 10;
2049 if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
2054 else if (c == '0' && (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))
2062 if (!hex && !got_e && (*p == 'e' || *p == 'E'))
2063 got_dot = got_e = 1;
2064 else if (!hex && !got_dot && *p == '.')
2066 else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
2067 && (*p == '-' || *p == '+'))
2068 /* This is the sign of the exponent, not the end of the
2071 /* We will take any letters or digits. parse_number will
2072 complain if past the radix, or if L or U are not final. */
2073 else if ((*p < '0' || *p > '9')
2074 && ((*p < 'a' || *p > 'z')
2075 && (*p < 'A' || *p > 'Z')))
2078 toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval);
2079 if (toktype == ERROR)
2081 char *err_copy = (char *) alloca (p - tokstart + 1);
2083 bcopy (tokstart, err_copy, p - tokstart);
2084 err_copy[p - tokstart] = 0;
2085 error ("Invalid number \"%s\".", err_copy);
2116 for (namelen = 1; (c = tokstart[namelen]) != '"'; namelen++)
2119 c = tokstart[++namelen];
2120 if (c >= '0' && c <= '9')
2122 c = tokstart[++namelen];
2123 if (c >= '0' && c <= '9')
2124 c = tokstart[++namelen];
2127 yylval.sval.ptr = tokstart + 1;
2128 yylval.sval.length = namelen - 1;
2129 lexptr += namelen + 1;
2133 if (!(c == '_' || c == '$'
2134 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
2135 /* We must have come across a bad character (e.g. ';'). */
2136 error ("Invalid character '%c' in expression.", c);
2138 /* It's a name. See how long it is. */
2140 for (c = tokstart[namelen];
2141 (c == '_' || c == '$' || (c >= '0' && c <= '9')
2142 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
2143 c = tokstart[++namelen])
2146 /* The token "if" terminates the expression and is NOT
2147 removed from the input stream. */
2148 if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
2155 /* Handle the tokens $digits; also $ (short for $0) and $$ (short for $$1)
2156 and $$digits (equivalent to $<-digits> if you could type that).
2157 Make token type LAST, and put the number (the digits) in yylval. */
2159 if (*tokstart == '$')
2161 register int negate = 0;
2163 /* Double dollar means negate the number and add -1 as well.
2164 Thus $$ alone means -1. */
2165 if (namelen >= 2 && tokstart[1] == '$')
2172 /* Just dollars (one or two) */
2173 yylval.lval = - negate;
2176 /* Is the rest of the token digits? */
2177 for (; c < namelen; c++)
2178 if (!(tokstart[c] >= '0' && tokstart[c] <= '9'))
2182 yylval.lval = atoi (tokstart + 1 + negate);
2184 yylval.lval = - yylval.lval;
2189 /* Handle tokens that refer to machine registers:
2190 $ followed by a register name. */
2192 if (*tokstart == '$') {
2193 for (c = 0; c < NUM_REGS; c++)
2194 if (namelen - 1 == strlen (reg_names[c])
2195 && !strncmp (tokstart + 1, reg_names[c], namelen - 1))
2200 for (c = 0; c < NUM_STD_REGS; c++)
2201 if (namelen - 1 == strlen (std_regs[c].name)
2202 && !strncmp (tokstart + 1, std_regs[c].name, namelen - 1))
2204 yylval.lval = std_regs[c].regnum;
2208 /* Catch specific keywords. Should be done with a data structure. */
2212 if (!strncmp (tokstart, "unsigned", 8))
2216 if (!strncmp (tokstart, "struct", 6))
2218 if (!strncmp (tokstart, "signed", 6))
2220 if (!strncmp (tokstart, "sizeof", 6))
2224 if (!strncmp (tokstart, "union", 5))
2226 if (!strncmp (tokstart, "short", 5))
2230 if (!strncmp (tokstart, "enum", 4))
2232 if (!strncmp (tokstart, "long", 4))
2234 if (!strncmp (tokstart, "this", 4))
2236 static const char this_name[] =
2237 { CPLUS_MARKER, 't', 'h', 'i', 's', '\0' };
2239 if (lookup_symbol (this_name, expression_context_block,
2240 VAR_NAMESPACE, 0, NULL))
2245 if (!strncmp (tokstart, "int", 3))
2252 yylval.sval.ptr = tokstart;
2253 yylval.sval.length = namelen;
2255 /* Any other names starting in $ are debugger internal variables. */
2257 if (*tokstart == '$')
2259 yylval.ivar = lookup_internalvar (copy_name (yylval.sval) + 1);
2263 /* Use token-type BLOCKNAME for symbols that happen to be defined as
2264 functions or symtabs. If this is not so, then ...
2265 Use token-type TYPENAME for symbols that happen to be defined
2266 currently as names of types; NAME for other symbols.
2267 The caller is not constrained to care about the distinction. */
2269 char *tmp = copy_name (yylval.sval);
2271 int is_a_field_of_this = 0;
2274 sym = lookup_symbol (tmp, expression_context_block,
2275 VAR_NAMESPACE, &is_a_field_of_this, NULL);
2276 if ((sym && SYMBOL_CLASS (sym) == LOC_BLOCK) ||
2277 lookup_partial_symtab (tmp))
2279 yylval.ssym.sym = sym;
2280 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
2283 if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
2285 yylval.tsym.type = SYMBOL_TYPE (sym);
2288 if ((yylval.tsym.type = lookup_primitive_typename (tmp)) != 0)
2291 /* Input names that aren't symbols but ARE valid hex numbers,
2292 when the input radix permits them, can be names or numbers
2293 depending on the parse. Note we support radixes > 16 here. */
2295 ((tokstart[0] >= 'a' && tokstart[0] < 'a' + input_radix - 10) ||
2296 (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10)))
2298 YYSTYPE newlval; /* Its value is ignored. */
2299 hextype = parse_number (tokstart, namelen, 0, &newlval);
2302 yylval.ssym.sym = sym;
2303 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
2306 if (hextype == UINT)
2308 yylval.ssym.sym = sym;
2309 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
2310 return NAME_OR_UINT;
2314 /* Any other kind of symbol */
2315 yylval.ssym.sym = sym;
2316 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
2325 error ("Invalid syntax in expression.");
2328 /* Return a null-terminated temporary copy of the name
2329 of a string token. */
2333 struct stoken token;
2335 bcopy (token.ptr, namecopy, token.length);
2336 namecopy[token.length] = 0;
2340 /* Reverse an expression from suffix form (in which it is constructed)
2341 to prefix form (in which we can conveniently print or execute it). */
2343 static void prefixify_subexp ();
2346 prefixify_expression (expr)
2347 register struct expression *expr;
2349 register int len = sizeof (struct expression) +
2350 expr->nelts * sizeof (union exp_element);
2351 register struct expression *temp;
2352 register int inpos = expr->nelts, outpos = 0;
2354 temp = (struct expression *) alloca (len);
2356 /* Copy the original expression into temp. */
2357 bcopy (expr, temp, len);
2359 prefixify_subexp (temp, expr, inpos, outpos);
2362 /* Return the number of exp_elements in the subexpression of EXPR
2363 whose last exp_element is at index ENDPOS - 1 in EXPR. */
2366 length_of_subexp (expr, endpos)
2367 register struct expression *expr;
2368 register int endpos;
2370 register int oplen = 1;
2371 register int args = 0;
2375 error ("?error in length_of_subexp");
2377 i = (int) expr->elts[endpos - 1].opcode;
2383 oplen = 4 + ((expr->elts[endpos - 2].longconst
2384 + sizeof (union exp_element))
2385 / sizeof (union exp_element));
2396 case OP_INTERNALVAR:
2402 args = 1 + expr->elts[endpos - 2].longconst;
2411 case STRUCTOP_STRUCT:
2415 oplen = 3 + ((expr->elts[endpos - 2].longconst
2416 + sizeof (union exp_element))
2417 / sizeof (union exp_element));
2424 case BINOP_ASSIGN_MODIFY:
2435 args = 1 + (i < (int) BINOP_END);
2440 oplen += length_of_subexp (expr, endpos - oplen);
2447 /* Copy the subexpression ending just before index INEND in INEXPR
2448 into OUTEXPR, starting at index OUTBEG.
2449 In the process, convert it from suffix to prefix form. */
2452 prefixify_subexp (inexpr, outexpr, inend, outbeg)
2453 register struct expression *inexpr;
2454 struct expression *outexpr;
2458 register int oplen = 1;
2459 register int args = 0;
2462 enum exp_opcode opcode;
2464 /* Compute how long the last operation is (in OPLEN),
2465 and also how many preceding subexpressions serve as
2466 arguments for it (in ARGS). */
2468 opcode = inexpr->elts[inend - 1].opcode;
2473 oplen = 4 + ((inexpr->elts[inend - 2].longconst
2474 + sizeof (union exp_element))
2475 / sizeof (union exp_element));
2486 case OP_INTERNALVAR:
2492 args = 1 + inexpr->elts[inend - 2].longconst;
2501 case STRUCTOP_STRUCT:
2505 oplen = 3 + ((inexpr->elts[inend - 2].longconst
2506 + sizeof (union exp_element))
2507 / sizeof (union exp_element));
2515 case BINOP_ASSIGN_MODIFY:
2526 args = 1 + ((int) opcode < (int) BINOP_END);
2529 /* Copy the final operator itself, from the end of the input
2530 to the beginning of the output. */
2532 bcopy (&inexpr->elts[inend], &outexpr->elts[outbeg],
2533 oplen * sizeof (union exp_element));
2536 /* Find the lengths of the arg subexpressions. */
2537 arglens = (int *) alloca (args * sizeof (int));
2538 for (i = args - 1; i >= 0; i--)
2540 oplen = length_of_subexp (inexpr, inend);
2545 /* Now copy each subexpression, preserving the order of
2546 the subexpressions, but prefixifying each one.
2547 In this loop, inend starts at the beginning of
2548 the expression this level is working on
2549 and marches forward over the arguments.
2550 outbeg does similarly in the output. */
2551 for (i = 0; i < args; i++)
2555 prefixify_subexp (inexpr, outexpr, inend, outbeg);
2560 /* This page contains the two entry points to this file. */
2562 /* Read a C expression from the string *STRINGPTR points to,
2563 parse it, and return a pointer to a struct expression that we malloc.
2564 Use block BLOCK as the lexical context for variable names;
2565 if BLOCK is zero, use the block of the selected stack frame.
2566 Meanwhile, advance *STRINGPTR to point after the expression,
2567 at the first nonwhite character that is not part of the expression
2568 (possibly a null character).
2570 If COMMA is nonzero, stop if a comma is reached. */
2573 parse_c_1 (stringptr, block, comma)
2575 struct block *block;
2578 struct cleanup *old_chain;
2580 lexptr = *stringptr;
2583 type_stack_depth = 0;
2585 comma_terminates = comma;
2587 if (lexptr == 0 || *lexptr == 0)
2588 error_no_arg ("expression to compute");
2590 old_chain = make_cleanup (free_funcalls, 0);
2593 expression_context_block = block ? block : get_selected_block ();
2595 namecopy = (char *) alloca (strlen (lexptr) + 1);
2598 expout = (struct expression *)
2599 xmalloc (sizeof (struct expression)
2600 + expout_size * sizeof (union exp_element));
2601 make_cleanup (free_current_contents, &expout);
2604 discard_cleanups (old_chain);
2605 expout->nelts = expout_ptr;
2606 expout = (struct expression *)
2608 sizeof (struct expression)
2609 + expout_ptr * sizeof (union exp_element));
2610 prefixify_expression (expout);
2611 *stringptr = lexptr;
2615 /* Parse STRING as an expression, and complain if this fails
2616 to use up all of the contents of STRING. */
2619 parse_c_expression (string)
2622 register struct expression *exp;
2623 exp = parse_c_1 (&string, 0, 0);
2625 error ("Junk after end of expression.");
2631 enum type_pieces tp;
2633 if (type_stack_depth == type_stack_size)
2635 type_stack_size *= 2;
2636 type_stack = (enum type_pieces *)
2637 xrealloc (type_stack, type_stack_size * sizeof (enum type_pieces));
2639 type_stack[type_stack_depth++] = tp;
2642 static enum type_pieces
2645 if (type_stack_depth)
2646 return type_stack[--type_stack_depth];
2651 _initialize_expread ()
2653 type_stack_size = 80;
2654 type_stack_depth = 0;
2655 type_stack = (enum type_pieces *)
2656 xmalloc (type_stack_size * sizeof (enum type_pieces));