2 /* A Bison parser, made from expread.y */
17 #define COLONCOLON 271
21 #define INT_KEYWORD 275
25 #define ASSIGN_MODIFY 279
27 #define ABOVE_COMMA 281
47 #include "expression.h"
52 static struct expression
*expout
;
53 static int expout_size
;
54 static int expout_ptr
;
57 static void yyerror ();
58 static void write_exp_elt ();
59 static void write_exp_elt_opcode ();
60 static void write_exp_elt_sym ();
61 static void write_exp_elt_longcst ();
62 static void write_exp_elt_dblcst ();
63 static void write_exp_elt_type ();
64 static void write_exp_elt_intern ();
65 static void write_exp_string ();
66 static void start_arglist ();
67 static int end_arglist ();
68 static void free_funcalls ();
69 static char *copy_name ();
71 /* If this is nonzero, this block is used as the lexical context
74 static struct block
*expression_context_block
;
76 /* The innermost context required by the stack and register variables
77 we've encountered so far. */
78 struct block
*innermost_block
;
80 /* The block in which the most recently discovered symbol was found. */
81 struct block
*block_found
;
83 /* Number of arguments seen so far in innermost function call. */
84 static int arglist_len
;
86 /* Data structure for saving values of arglist_len
87 for function calls whose arguments contain other function calls. */
95 struct funcall
*funcall_chain
;
97 /* This kind of datum is used to represent the name
106 /* For parsing of complicated types.
107 An array should be preceded in the list by the size of the array. */
109 {tp_end
= -1, tp_pointer
, tp_reference
, tp_array
, tp_function
};
110 static enum type_pieces
*type_stack
;
111 static int type_stack_depth
, type_stack_size
;
113 static void push_type ();
114 static enum type_pieces
pop_type ();
116 /* Allow debugging of parsing. */
119 #line 111 "expread.y"
123 unsigned LONGEST ulval
;
130 enum exp_opcode opcode
;
131 struct internalvar
*ivar
;
150 #define YYLTYPE yyltype
162 #define YYFLAG -32768
165 #define YYTRANSLATE(x) ((unsigned)(x) <= 293 ? yytranslate[x] : 81)
167 static const char yytranslate
[] = { 0,
168 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
169 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
170 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
171 2, 2, 56, 2, 2, 2, 48, 34, 2, 55,
172 59, 46, 44, 26, 45, 53, 47, 2, 2, 2,
173 2, 2, 2, 2, 2, 2, 2, 62, 2, 37,
174 28, 38, 29, 43, 2, 2, 2, 2, 2, 2,
175 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
176 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
177 54, 2, 58, 33, 2, 2, 2, 2, 2, 2,
178 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
179 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
180 2, 2, 60, 32, 61, 57, 2, 2, 2, 2,
181 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
182 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
183 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
184 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
185 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
186 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
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, 2, 2, 2, 2, 2, 2, 2, 2,
191 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
192 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
193 2, 2, 2, 2, 2, 1, 2, 3, 4, 5,
194 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
195 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
196 27, 30, 31, 35, 36, 39, 40, 41, 42, 49,
200 static const short yyrline
[] = { 0,
201 190, 194, 195, 200, 203, 206, 210, 214, 218, 222,
202 226, 230, 234, 238, 244, 248, 254, 258, 262, 266,
203 272, 275, 279, 283, 289, 295, 301, 305, 309, 313,
204 317, 321, 325, 329, 333, 337, 341, 345, 349, 353,
205 357, 361, 365, 369, 373, 377, 381, 385, 391, 401,
206 413, 420, 427, 430, 436, 442, 448, 455, 462, 469,
207 490, 499, 510, 523, 569, 646, 647, 682, 684, 686,
208 689, 691, 696, 702, 704, 708, 710, 714, 718, 719,
209 721, 723, 726, 733, 736, 738, 740, 742, 744, 746,
210 748, 750, 753, 756, 759, 761, 763, 766, 770, 771,
211 776, 781, 789, 794, 801, 802, 803, 806, 807
214 static const char * const yytname
[] = { 0,
215 "error","$illegal.","INT","CHAR","UINT","FLOAT","NAME","TYPENAME","BLOCKNAME","STRING",
216 "STRUCT","UNION","ENUM","SIZEOF","UNSIGNED","COLONCOLON","SIGNED","LONG","SHORT","INT_KEYWORD",
217 "LAST","REGNAME","VARIABLE","ASSIGN_MODIFY","THIS","','","ABOVE_COMMA","'='","'?'","OR",
218 "AND","'|'","'^'","'&'","EQUAL","NOTEQUAL","'<'","'>'","LEQ","GEQ",
219 "LSH","RSH","'@'","'+'","'-'","'*'","'/'","'%'","UNARY","INCREMENT",
220 "DECREMENT","ARROW","'.'","'['","'('","'!'","'~'","']'","')'","'{'",
224 static const short yyr1
[] = { 0,
225 63, 64, 64, 65, 65, 65, 65, 65, 65, 65,
226 65, 65, 65, 65, 65, 65, 65, 65, 66, 65,
227 67, 67, 67, 65, 65, 65, 65, 65, 65, 65,
228 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
229 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
230 65, 65, 65, 65, 65, 65, 65, 65, 65, 68,
231 68, 69, 69, 69, 69, 70, 70, 71, 71, 71,
232 72, 72, 72, 72, 72, 73, 73, 74, 75, 75,
233 75, 75, 75, 76, 76, 76, 76, 76, 76, 76,
234 76, 76, 76, 76, 76, 76, 76, 76, 77, 77,
235 77, 77, 78, 78, 79, 79, 79, 80, 80
238 static const short yyr2
[] = { 0,
239 1, 1, 3, 2, 2, 2, 2, 2, 2, 2,
240 2, 2, 2, 3, 4, 3, 4, 4, 0, 5,
241 0, 1, 3, 4, 4, 3, 3, 3, 3, 3,
242 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
243 3, 3, 3, 3, 3, 5, 3, 3, 1, 1,
244 1, 1, 1, 1, 1, 1, 4, 1, 1, 1,
245 3, 3, 3, 2, 1, 1, 2, 1, 2, 1,
246 3, 2, 1, 2, 1, 2, 3, 2, 1, 3,
247 6, 8, 9, 1, 1, 1, 1, 2, 3, 2,
248 3, 2, 2, 2, 2, 1, 2, 1, 1, 1,
249 1, 1, 1, 3, 1, 1, 1, 1, 1
252 static const short yydefact
[] = { 0,
253 49, 51, 50, 52, 108, 84, 109, 58, 0, 0,
254 0, 0, 96, 0, 98, 86, 87, 85, 54, 55,
255 56, 59, 0, 0, 0, 0, 0, 0, 0, 0,
256 0, 1, 2, 0, 53, 0, 65, 105, 107, 106,
257 92, 93, 94, 0, 13, 99, 101, 102, 100, 95,
258 64, 101, 102, 97, 88, 90, 5, 6, 4, 9,
259 10, 0, 79, 0, 66, 7, 8, 0, 66, 0,
260 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
261 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
262 0, 0, 11, 12, 0, 0, 0, 19, 0, 0,
263 0, 89, 91, 26, 0, 0, 0, 68, 0, 0,
264 67, 70, 73, 75, 0, 0, 3, 48, 47, 0,
265 45, 44, 43, 42, 41, 35, 36, 39, 40, 37,
266 38, 33, 34, 27, 31, 32, 28, 29, 30, 0,
267 14, 0, 16, 0, 21, 62, 63, 57, 0, 25,
268 80, 69, 0, 76, 78, 0, 0, 72, 74, 24,
269 0, 15, 17, 18, 22, 0, 0, 77, 71, 46,
270 0, 20, 0, 23, 81, 0, 82, 103, 0, 0,
274 static const short yydefgoto
[] = { 183,
275 62, 33, 145, 166, 34, 35, 63, 111, 112, 113,
276 114, 64, 36, 50, 179, 147, 37
279 static const short yypact
[] = { 157,
280 -32768,-32768,-32768,-32768,-32768,-32768, -13,-32768, 105, 105,
281 105, 215, 82, 105, 178, -10, -4,-32768,-32768,-32768,
282 -32768,-32768, 157, 157, 157, 157, 157, 157, 157, 157,
283 239, 6, 284, 75,-32768, 79,-32768,-32768,-32768,-32768,
284 -32768,-32768,-32768, 157, 501,-32768, 66, 84,-32768,-32768,
285 -32768,-32768,-32768,-32768,-32768,-32768, 501, 501, 501, 501,
286 501, 67,-32768, -50, 69, 501, 501, -53, 138, 157,
287 157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
288 157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
289 157, 157,-32768,-32768, 111, 197, 157,-32768, 105, 105,
290 -28,-32768,-32768,-32768, 239, 157, 202, -21, 26, 51,
291 -32768, 62,-32768,-32768, 157, 63, 284, 284, 284, 249,
292 336, 360, 383, 405, 426, 445, 445, 460, 460, 460,
293 460, 473, 473, 485, 495, 495, 501, 501, 501, 157,
294 -32768, 157,-32768, -2, 157, 106,-32768, 32, 109, 501,
295 -32768,-32768, 77,-32768,-32768, 68, 72,-32768,-32768, 501,
296 157, 501, 501,-32768, 284, 70, 94,-32768,-32768, 311,
297 157,-32768, 83, 284, 92, 126,-32768, 93, 73, 239,
298 -32768, 93, 121, 150,-32768
301 static const short yypgoto
[] = {-32768,
302 1, -12,-32768,-32768,-32768,-32768,-32768, -80,-32768, 41,
303 46, -25, -24, 166,-32768, 12,-32768
310 static const short yytable
[] = { 45,
311 32, 105, -60, 65, 105, 68, 69, 115, 106, 55,
312 57, 58, 59, 60, 61, 56, 66, 67, 101, 65,
313 41, 42, 43, 70, 108, 51, 105, 152, 153, 156,
314 148, 70, 109, 110, 1, 2, 3, 4, 5, 6,
315 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
316 17, 18, 19, 20, 21, 164, 22, 117, 118, 119,
317 120, 121, 122, 123, 124, 125, 126, 127, 128, 129,
318 130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
319 149, 26, 27, 154, 107, 102, 28, 29, 30, 46,
320 99, 31, 70, 150, 100, 171, 108, 144, 180, 47,
321 48, 49, 160, 103, 109, 110, 141, 143, 151, 155,
322 146, 38, 39, 40, 108, 109, 157, 38, 39, 40,
323 184, -61, 109, 110, 167, 104, 169, 162, 172, 163,
324 155, 181, 165, 6, 168, 150, 9, 10, 11, 173,
325 13, 175, 15, 16, 17, 18, 176, 105, 170, 185,
326 178, 69, 158, 116, 182, 69, 140, 159, 174, 1,
327 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
328 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
329 54, 22, 0, 108, 177, 46, 0, 0, 0, 0,
330 23, 109, 110, 0, 0, 52, 53, 49, 0, 0,
331 0, 24, 25, 38, 39, 40, 26, 27, 38, 39,
332 40, 28, 29, 30, 0, 0, 31, 1, 2, 3,
333 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
334 14, 15, 16, 17, 18, 19, 20, 21, 0, 22,
335 0, 0, 142, 0, 0, 0, 6, 151, 23, 9,
336 10, 11, 0, 13, 0, 15, 16, 17, 18, 24,
337 25, 0, 0, 0, 26, 27, 0, 0, 0, 44,
338 29, 30, 71, 0, 31, 0, 72, 73, 74, 75,
339 76, 77, 78, 79, 80, 81, 82, 83, 84, 85,
340 86, 87, 88, 89, 90, 91, 92, 0, 93, 94,
341 95, 96, 97, 98, 0, 0, 0, 71, 0, 0,
342 161, 72, 73, 74, 75, 76, 77, 78, 79, 80,
343 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
344 91, 92, 0, 93, 94, 95, 96, 97, 98, 73,
345 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
346 84, 85, 86, 87, 88, 89, 90, 91, 92, 0,
347 93, 94, 95, 96, 97, 98, 75, 76, 77, 78,
348 79, 80, 81, 82, 83, 84, 85, 86, 87, 88,
349 89, 90, 91, 92, 0, 93, 94, 95, 96, 97,
350 98, 76, 77, 78, 79, 80, 81, 82, 83, 84,
351 85, 86, 87, 88, 89, 90, 91, 92, 0, 93,
352 94, 95, 96, 97, 98, 77, 78, 79, 80, 81,
353 82, 83, 84, 85, 86, 87, 88, 89, 90, 91,
354 92, 0, 93, 94, 95, 96, 97, 98, 78, 79,
355 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
356 90, 91, 92, 0, 93, 94, 95, 96, 97, 98,
357 79, 80, 81, 82, 83, 84, 85, 86, 87, 88,
358 89, 90, 91, 92, 0, 93, 94, 95, 96, 97,
359 98, 81, 82, 83, 84, 85, 86, 87, 88, 89,
360 90, 91, 92, 0, 93, 94, 95, 96, 97, 98,
361 85, 86, 87, 88, 89, 90, 91, 92, 0, 93,
362 94, 95, 96, 97, 98, 87, 88, 89, 90, 91,
363 92, 0, 93, 94, 95, 96, 97, 98, 88, 89,
364 90, 91, 92, 0, 93, 94, 95, 96, 97, 98,
365 90, 91, 92, 0, 93, 94, 95, 96, 97, 98,
366 93, 94, 95, 96, 97, 98
369 static const short yycheck
[] = { 12,
370 0, 55, 16, 28, 55, 31, 31, 61, 59, 20,
371 23, 24, 25, 26, 27, 20, 29, 30, 44, 44,
372 9, 10, 11, 26, 46, 14, 55, 108, 3, 110,
373 59, 26, 54, 55, 3, 4, 5, 6, 7, 8,
374 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
375 19, 20, 21, 22, 23, 58, 25, 70, 71, 72,
376 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
377 83, 84, 85, 86, 87, 88, 89, 90, 91, 92,
378 105, 50, 51, 58, 16, 20, 55, 56, 57, 8,
379 16, 60, 26, 106, 16, 26, 46, 97, 26, 18,
380 19, 20, 115, 20, 54, 55, 95, 96, 46, 59,
381 99, 7, 8, 9, 46, 54, 55, 7, 8, 9,
382 0, 16, 54, 55, 16, 59, 59, 140, 59, 142,
383 59, 59, 145, 8, 58, 148, 11, 12, 13, 46,
384 15, 59, 17, 18, 19, 20, 55, 55, 161, 0,
385 176, 176, 112, 16, 180, 180, 46, 112, 171, 3,
386 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
387 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
388 15, 25, -1, 46, 59, 8, -1, -1, -1, -1,
389 34, 54, 55, -1, -1, 18, 19, 20, -1, -1,
390 -1, 45, 46, 7, 8, 9, 50, 51, 7, 8,
391 9, 55, 56, 57, -1, -1, 60, 3, 4, 5,
392 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
393 16, 17, 18, 19, 20, 21, 22, 23, -1, 25,
394 -1, -1, 46, -1, -1, -1, 8, 46, 34, 11,
395 12, 13, -1, 15, -1, 17, 18, 19, 20, 45,
396 46, -1, -1, -1, 50, 51, -1, -1, -1, 55,
397 56, 57, 24, -1, 60, -1, 28, 29, 30, 31,
398 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
399 42, 43, 44, 45, 46, 47, 48, -1, 50, 51,
400 52, 53, 54, 55, -1, -1, -1, 24, -1, -1,
401 62, 28, 29, 30, 31, 32, 33, 34, 35, 36,
402 37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
403 47, 48, -1, 50, 51, 52, 53, 54, 55, 29,
404 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
405 40, 41, 42, 43, 44, 45, 46, 47, 48, -1,
406 50, 51, 52, 53, 54, 55, 31, 32, 33, 34,
407 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
408 45, 46, 47, 48, -1, 50, 51, 52, 53, 54,
409 55, 32, 33, 34, 35, 36, 37, 38, 39, 40,
410 41, 42, 43, 44, 45, 46, 47, 48, -1, 50,
411 51, 52, 53, 54, 55, 33, 34, 35, 36, 37,
412 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
413 48, -1, 50, 51, 52, 53, 54, 55, 34, 35,
414 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
415 46, 47, 48, -1, 50, 51, 52, 53, 54, 55,
416 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
417 45, 46, 47, 48, -1, 50, 51, 52, 53, 54,
418 55, 37, 38, 39, 40, 41, 42, 43, 44, 45,
419 46, 47, 48, -1, 50, 51, 52, 53, 54, 55,
420 41, 42, 43, 44, 45, 46, 47, 48, -1, 50,
421 51, 52, 53, 54, 55, 43, 44, 45, 46, 47,
422 48, -1, 50, 51, 52, 53, 54, 55, 44, 45,
423 46, 47, 48, -1, 50, 51, 52, 53, 54, 55,
424 46, 47, 48, -1, 50, 51, 52, 53, 54, 55,
425 50, 51, 52, 53, 54, 55
429 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
430 #line 3 "bison.simple"
432 /* Skeleton output parser for bison,
433 Copyright (C) 1984 Bob Corbett and Richard Stallman
435 This program is free software; you can redistribute it and/or modify
436 it under the terms of the GNU General Public License as published by
437 the Free Software Foundation; either version 1, or (at your option)
440 This program is distributed in the hope that it will be useful,
441 but WITHOUT ANY WARRANTY; without even the implied warranty of
442 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
443 GNU General Public License for more details.
445 You should have received a copy of the GNU General Public License
446 along with this program; if not, write to the Free Software
447 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
450 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__)
454 /* This is the parser code that is written into each bison parser
455 when the %semantic_parser declaration is not specified in the grammar.
456 It was written by Richard Stallman by simplifying the hairy parser
457 used when %semantic_parser is specified. */
459 /* Note: there must be only one dollar sign in this file.
460 It is replaced by the list of actions, each action
461 as one case of the switch. */
463 #define yyerrok (yyerrstatus = 0)
464 #define yyclearin (yychar = YYEMPTY)
467 #define YYFAIL goto yyerrlab;
468 #define YYACCEPT return(0)
469 #define YYABORT return(1)
470 #define YYERROR goto yyerrlab
473 #define YYERRCODE 256
476 #define YYLEX yylex()
480 #define YYLEX yylex(&yylval, &yylloc)
483 /* If nonreentrant, generate the variables here */
487 int yychar
; /* the lookahead symbol */
488 YYSTYPE yylval
; /* the semantic value of the */
489 /* lookahead symbol */
491 YYLTYPE yylloc
; /* location data for the lookahead */
494 int yynerrs
; /* number of parse errors so far */
495 #endif /* YYIMPURE */
498 int yydebug
; /* nonzero means print parse trace */
499 /* Since this is uninitialized, it does not stop multiple parsers
503 /* YYMAXDEPTH indicates the initial size of the parser's stacks */
506 #define YYMAXDEPTH 200
509 /* YYMAXLIMIT is the maximum size the stacks can grow to
510 (effective only if the built-in stack extension method is used). */
513 #define YYMAXLIMIT 10000
517 #line 90 "bison.simple"
521 register int yystate
;
523 register short *yyssp
;
524 register YYSTYPE
*yyvsp
;
526 int yyerrstatus
; /* number of tokens to shift before error messages enabled */
527 int yychar1
; /* lookahead token as an internal (translated) token number */
529 short yyssa
[YYMAXDEPTH
]; /* the state stack */
530 YYSTYPE yyvsa
[YYMAXDEPTH
]; /* the semantic value stack */
531 YYLTYPE yylsa
[YYMAXDEPTH
]; /* the location stack */
533 short *yyss
= yyssa
; /* refer to the stacks thru separate pointers */
534 YYSTYPE
*yyvs
= yyvsa
; /* to allow yyoverflow to reallocate them elsewhere */
535 YYLTYPE
*yyls
= yylsa
;
537 int yymaxdepth
= YYMAXDEPTH
;
546 YYSTYPE yyval
; /* the variable used to return */
547 /* semantic values from the action */
557 fprintf(stderr
, "Starting parse\n");
563 yychar
= YYEMPTY
; /* Cause a token to be read. */
565 /* Initialize stack pointers.
566 Waste one element of value and location stack
567 so that they stay on the same level as the state stack. */
573 /* Push a new state, which is found in yystate . */
574 /* In all cases, when you get here, the value and location stacks
575 have just been pushed. so pushing a state here evens the stacks. */
580 if (yyssp
>= yyss
+ yymaxdepth
- 1)
582 /* Give user a chance to reallocate the stack */
583 /* Use copies of these so that the &'s don't force the real ones into memory. */
584 YYSTYPE
*yyvs1
= yyvs
;
585 #if defined(yyoverflow) || defined(YYLSP_NEEDED)
586 YYLTYPE
*yyls1
= yyls
;
590 /* Get the current used size of the three stacks, in elements. */
591 int size
= yyssp
- yyss
+ 1;
594 /* Each stack pointer address is followed by the size of
595 the data in use in that stack, in bytes. */
596 yyoverflow("parser stack overflow",
597 &yyss1
, size
* sizeof (*yyssp
),
598 &yyvs1
, size
* sizeof (*yyvsp
),
599 &yyls1
, size
* sizeof (*yylsp
),
602 yyss
= yyss1
; yyvs
= yyvs1
; yyls
= yyls1
;
603 #else /* no yyoverflow */
604 /* Extend the stack our own way. */
605 if (yymaxdepth
>= YYMAXLIMIT
)
606 yyerror("parser stack overflow");
608 if (yymaxdepth
> YYMAXLIMIT
)
609 yymaxdepth
= YYMAXLIMIT
;
610 yyss
= (short *) alloca (yymaxdepth
* sizeof (*yyssp
));
611 bcopy ((char *)yyss1
, (char *)yyss
, size
* sizeof (*yyssp
));
612 yyvs
= (YYSTYPE
*) alloca (yymaxdepth
* sizeof (*yyvsp
));
613 bcopy ((char *)yyvs1
, (char *)yyvs
, size
* sizeof (*yyvsp
));
615 yyls
= (YYLTYPE
*) alloca (yymaxdepth
* sizeof (*yylsp
));
616 bcopy ((char *)yyls1
, (char *)yyls
, size
* sizeof (*yylsp
));
618 #endif /* no yyoverflow */
620 yyssp
= yyss
+ size
- 1;
621 yyvsp
= yyvs
+ size
- 1;
623 yylsp
= yyls
+ size
- 1;
628 fprintf(stderr
, "Stack size increased to %d\n", yymaxdepth
);
631 if (yyssp
>= yyss
+ yymaxdepth
- 1)
637 fprintf(stderr
, "Entering state %d\n", yystate
);
640 /* Do appropriate processing given the current state. */
641 /* Read a lookahead token if we need one and don't already have one. */
643 /* First try to decide what to do without reference to lookahead token. */
645 yyn
= yypact
[yystate
];
649 /* Not known => get a lookahead token if don't already have one. */
651 /* yychar is either YYEMPTY or YYEOF
652 or a valid token in external form. */
654 if (yychar
== YYEMPTY
)
658 fprintf(stderr
, "Reading a token: ");
663 /* Convert token to internal form (in yychar1) for indexing tables with */
665 if (yychar
<= 0) /* This means end of input. */
668 yychar
= YYEOF
; /* Don't call YYLEX any more */
672 fprintf(stderr
, "Now at end of input.\n");
677 yychar1
= YYTRANSLATE(yychar
);
681 fprintf(stderr
, "Next token is %d (%s)\n", yychar
, yytname
[yychar1
]);
686 if (yyn
< 0 || yyn
> YYLAST
|| yycheck
[yyn
] != yychar1
)
691 /* yyn is what to do for this token type in this state.
692 Negative => reduce, -yyn is rule number.
693 Positive => shift, yyn is new state.
694 New state is final state => don't bother to shift,
696 0, or most negative number => error. */
711 /* Shift the lookahead token. */
715 fprintf(stderr
, "Shifting token %d (%s), ", yychar
, yytname
[yychar1
]);
718 /* Discard the token being shifted unless it is eof. */
727 /* count tokens shifted since error; after three, turn off error status. */
728 if (yyerrstatus
) yyerrstatus
--;
733 /* Do the default action for the current state. */
736 yyn
= yydefact
[yystate
];
740 /* Do a reduction. yyn is the number of a rule to reduce with. */
743 yyval
= yyvsp
[1-yylen
]; /* implement default value of the action */
749 fprintf (stderr
, "Reducing 1 value via line %d, ",
752 fprintf (stderr
, "Reducing %d values via line %d, ",
753 yylen
, yyrline
[yyn
]);
761 #line 196 "expread.y"
762 { write_exp_elt_opcode (BINOP_COMMA
); ;
765 #line 201 "expread.y"
766 { write_exp_elt_opcode (UNOP_IND
); ;
769 #line 204 "expread.y"
770 { write_exp_elt_opcode (UNOP_ADDR
); ;
773 #line 207 "expread.y"
774 { write_exp_elt_opcode (UNOP_NEG
); ;
777 #line 211 "expread.y"
778 { write_exp_elt_opcode (UNOP_ZEROP
); ;
781 #line 215 "expread.y"
782 { write_exp_elt_opcode (UNOP_LOGNOT
); ;
785 #line 219 "expread.y"
786 { write_exp_elt_opcode (UNOP_PREINCREMENT
); ;
789 #line 223 "expread.y"
790 { write_exp_elt_opcode (UNOP_PREDECREMENT
); ;
793 #line 227 "expread.y"
794 { write_exp_elt_opcode (UNOP_POSTINCREMENT
); ;
797 #line 231 "expread.y"
798 { write_exp_elt_opcode (UNOP_POSTDECREMENT
); ;
801 #line 235 "expread.y"
802 { write_exp_elt_opcode (UNOP_SIZEOF
); ;
805 #line 239 "expread.y"
806 { write_exp_elt_opcode (STRUCTOP_PTR
);
807 write_exp_string (yyvsp
[0].sval
);
808 write_exp_elt_opcode (STRUCTOP_PTR
); ;
811 #line 245 "expread.y"
812 { write_exp_elt_opcode (STRUCTOP_MPTR
); ;
815 #line 249 "expread.y"
816 { write_exp_elt_opcode (STRUCTOP_STRUCT
);
817 write_exp_string (yyvsp
[0].sval
);
818 write_exp_elt_opcode (STRUCTOP_STRUCT
); ;
821 #line 255 "expread.y"
822 { write_exp_elt_opcode (STRUCTOP_MEMBER
); ;
825 #line 259 "expread.y"
826 { write_exp_elt_opcode (BINOP_SUBSCRIPT
); ;
829 #line 265 "expread.y"
830 { start_arglist (); ;
833 #line 267 "expread.y"
834 { write_exp_elt_opcode (OP_FUNCALL
);
835 write_exp_elt_longcst ((LONGEST
) end_arglist ());
836 write_exp_elt_opcode (OP_FUNCALL
); ;
839 #line 276 "expread.y"
843 #line 280 "expread.y"
847 #line 284 "expread.y"
848 { write_exp_elt_opcode (UNOP_MEMVAL
);
849 write_exp_elt_type (yyvsp
[-2].tval
);
850 write_exp_elt_opcode (UNOP_MEMVAL
); ;
853 #line 290 "expread.y"
854 { write_exp_elt_opcode (UNOP_CAST
);
855 write_exp_elt_type (yyvsp
[-2].tval
);
856 write_exp_elt_opcode (UNOP_CAST
); ;
859 #line 296 "expread.y"
863 #line 302 "expread.y"
864 { write_exp_elt_opcode (BINOP_REPEAT
); ;
867 #line 306 "expread.y"
868 { write_exp_elt_opcode (BINOP_MUL
); ;
871 #line 310 "expread.y"
872 { write_exp_elt_opcode (BINOP_DIV
); ;
875 #line 314 "expread.y"
876 { write_exp_elt_opcode (BINOP_REM
); ;
879 #line 318 "expread.y"
880 { write_exp_elt_opcode (BINOP_ADD
); ;
883 #line 322 "expread.y"
884 { write_exp_elt_opcode (BINOP_SUB
); ;
887 #line 326 "expread.y"
888 { write_exp_elt_opcode (BINOP_LSH
); ;
891 #line 330 "expread.y"
892 { write_exp_elt_opcode (BINOP_RSH
); ;
895 #line 334 "expread.y"
896 { write_exp_elt_opcode (BINOP_EQUAL
); ;
899 #line 338 "expread.y"
900 { write_exp_elt_opcode (BINOP_NOTEQUAL
); ;
903 #line 342 "expread.y"
904 { write_exp_elt_opcode (BINOP_LEQ
); ;
907 #line 346 "expread.y"
908 { write_exp_elt_opcode (BINOP_GEQ
); ;
911 #line 350 "expread.y"
912 { write_exp_elt_opcode (BINOP_LESS
); ;
915 #line 354 "expread.y"
916 { write_exp_elt_opcode (BINOP_GTR
); ;
919 #line 358 "expread.y"
920 { write_exp_elt_opcode (BINOP_LOGAND
); ;
923 #line 362 "expread.y"
924 { write_exp_elt_opcode (BINOP_LOGXOR
); ;
927 #line 366 "expread.y"
928 { write_exp_elt_opcode (BINOP_LOGIOR
); ;
931 #line 370 "expread.y"
932 { write_exp_elt_opcode (BINOP_AND
); ;
935 #line 374 "expread.y"
936 { write_exp_elt_opcode (BINOP_OR
); ;
939 #line 378 "expread.y"
940 { write_exp_elt_opcode (TERNOP_COND
); ;
943 #line 382 "expread.y"
944 { write_exp_elt_opcode (BINOP_ASSIGN
); ;
947 #line 386 "expread.y"
948 { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY
);
949 write_exp_elt_opcode (yyvsp
[-1].opcode
);
950 write_exp_elt_opcode (BINOP_ASSIGN_MODIFY
); ;
953 #line 392 "expread.y"
954 { write_exp_elt_opcode (OP_LONG
);
955 if (yyvsp
[0].lval
== (int) yyvsp
[0].lval
|| yyvsp
[0].lval
== (unsigned int) yyvsp
[0].lval
)
956 write_exp_elt_type (builtin_type_int
);
958 write_exp_elt_type (BUILTIN_TYPE_LONGEST
);
959 write_exp_elt_longcst ((LONGEST
) yyvsp
[0].lval
);
960 write_exp_elt_opcode (OP_LONG
); ;
963 #line 402 "expread.y"
965 write_exp_elt_opcode (OP_LONG
);
966 if (yyvsp
[0].ulval
== (unsigned int) yyvsp
[0].ulval
)
967 write_exp_elt_type (builtin_type_unsigned_int
);
969 write_exp_elt_type (BUILTIN_TYPE_UNSIGNED_LONGEST
);
970 write_exp_elt_longcst ((LONGEST
) yyvsp
[0].ulval
);
971 write_exp_elt_opcode (OP_LONG
);
975 #line 414 "expread.y"
976 { write_exp_elt_opcode (OP_LONG
);
977 write_exp_elt_type (builtin_type_char
);
978 write_exp_elt_longcst ((LONGEST
) yyvsp
[0].lval
);
979 write_exp_elt_opcode (OP_LONG
); ;
982 #line 421 "expread.y"
983 { write_exp_elt_opcode (OP_DOUBLE
);
984 write_exp_elt_type (builtin_type_double
);
985 write_exp_elt_dblcst (yyvsp
[0].dval
);
986 write_exp_elt_opcode (OP_DOUBLE
); ;
989 #line 431 "expread.y"
990 { write_exp_elt_opcode (OP_LAST
);
991 write_exp_elt_longcst ((LONGEST
) yyvsp
[0].lval
);
992 write_exp_elt_opcode (OP_LAST
); ;
995 #line 437 "expread.y"
996 { write_exp_elt_opcode (OP_REGISTER
);
997 write_exp_elt_longcst ((LONGEST
) yyvsp
[0].lval
);
998 write_exp_elt_opcode (OP_REGISTER
); ;
1001 #line 443 "expread.y"
1002 { write_exp_elt_opcode (OP_INTERNALVAR
);
1003 write_exp_elt_intern (yyvsp
[0].ivar
);
1004 write_exp_elt_opcode (OP_INTERNALVAR
); ;
1007 #line 449 "expread.y"
1008 { write_exp_elt_opcode (OP_LONG
);
1009 write_exp_elt_type (builtin_type_int
);
1010 write_exp_elt_longcst ((LONGEST
) TYPE_LENGTH (yyvsp
[-1].tval
));
1011 write_exp_elt_opcode (OP_LONG
); ;
1014 #line 456 "expread.y"
1015 { write_exp_elt_opcode (OP_STRING
);
1016 write_exp_string (yyvsp
[0].sval
);
1017 write_exp_elt_opcode (OP_STRING
); ;
1020 #line 463 "expread.y"
1021 { write_exp_elt_opcode (OP_THIS
);
1022 write_exp_elt_opcode (OP_THIS
); ;
1025 #line 470 "expread.y"
1027 struct symtab
*tem
= lookup_symtab (copy_name (yyvsp
[0].sval
));
1031 yyval
.bval
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (tem
), 1);
1034 sym
= lookup_symbol (copy_name (yyvsp
[0].sval
),
1035 expression_context_block
,
1037 if (sym
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1038 yyval
.bval
= SYMBOL_BLOCK_VALUE (sym
);
1040 error ("No file or function \"%s\".",
1041 copy_name (yyvsp
[0].sval
));
1046 #line 491 "expread.y"
1047 { struct symbol
*tem
1048 = lookup_symbol (copy_name (yyvsp
[0].sval
), yyvsp
[-2].bval
, VAR_NAMESPACE
, 0);
1049 if (!tem
|| SYMBOL_CLASS (tem
) != LOC_BLOCK
)
1050 error ("No function \"%s\" in specified context.",
1051 copy_name (yyvsp
[0].sval
));
1052 yyval
.bval
= SYMBOL_BLOCK_VALUE (tem
); ;
1055 #line 500 "expread.y"
1056 { struct symbol
*sym
;
1057 sym
= lookup_symbol (copy_name (yyvsp
[0].sval
), yyvsp
[-2].bval
, VAR_NAMESPACE
, 0);
1059 error ("No symbol \"%s\" in specified context.",
1060 copy_name (yyvsp
[0].sval
));
1061 write_exp_elt_opcode (OP_VAR_VALUE
);
1062 write_exp_elt_sym (sym
);
1063 write_exp_elt_opcode (OP_VAR_VALUE
); ;
1066 #line 511 "expread.y"
1068 struct type
*type
= yyvsp
[-2].tval
;
1069 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
1070 && TYPE_CODE (type
) != TYPE_CODE_UNION
)
1071 error ("`%s' is not defined as an aggregate type.",
1074 write_exp_elt_opcode (OP_SCOPE
);
1075 write_exp_elt_type (type
);
1076 write_exp_string (yyvsp
[0].sval
);
1077 write_exp_elt_opcode (OP_SCOPE
);
1081 #line 524 "expread.y"
1083 char *name
= copy_name (yyvsp
[0].sval
);
1087 sym
= lookup_symbol (name
, 0, VAR_NAMESPACE
, 0);
1090 write_exp_elt_opcode (OP_VAR_VALUE
);
1091 write_exp_elt_sym (sym
);
1092 write_exp_elt_opcode (OP_VAR_VALUE
);
1095 for (i
= 0; i
< misc_function_count
; i
++)
1096 if (!strcmp (misc_function_vector
[i
].name
, name
))
1099 if (i
< misc_function_count
)
1101 enum misc_function_type mft
=
1102 (enum misc_function_type
)
1103 misc_function_vector
[i
].type
;
1105 write_exp_elt_opcode (OP_LONG
);
1106 write_exp_elt_type (builtin_type_int
);
1107 write_exp_elt_longcst ((LONGEST
) misc_function_vector
[i
].address
);
1108 write_exp_elt_opcode (OP_LONG
);
1109 write_exp_elt_opcode (UNOP_MEMVAL
);
1110 if (mft
== mf_data
|| mft
== mf_bss
)
1111 write_exp_elt_type (builtin_type_int
);
1112 else if (mft
== mf_text
)
1113 write_exp_elt_type (lookup_function_type (builtin_type_int
));
1115 write_exp_elt_type (builtin_type_char
);
1116 write_exp_elt_opcode (UNOP_MEMVAL
);
1119 if (symtab_list
== 0
1120 && partial_symtab_list
== 0)
1121 error ("No symbol table is loaded. Use the \"symbol-file\" command.");
1123 error ("No symbol \"%s\" in current context.", name
);
1127 #line 570 "expread.y"
1128 { struct symbol
*sym
;
1129 int is_a_field_of_this
;
1131 sym
= lookup_symbol (copy_name (yyvsp
[0].sval
),
1132 expression_context_block
,
1134 &is_a_field_of_this
);
1142 if (innermost_block
== 0 ||
1143 contained_in (block_found
,
1145 innermost_block
= block_found
;
1147 write_exp_elt_opcode (OP_VAR_VALUE
);
1148 write_exp_elt_sym (sym
);
1149 write_exp_elt_opcode (OP_VAR_VALUE
);
1151 else if (is_a_field_of_this
)
1153 /* C++: it hangs off of `this'. Must
1154 not inadvertently convert from a method call
1156 if (innermost_block
== 0 ||
1157 contained_in (block_found
, innermost_block
))
1158 innermost_block
= block_found
;
1159 write_exp_elt_opcode (OP_THIS
);
1160 write_exp_elt_opcode (OP_THIS
);
1161 write_exp_elt_opcode (STRUCTOP_PTR
);
1162 write_exp_string (yyvsp
[0].sval
);
1163 write_exp_elt_opcode (STRUCTOP_PTR
);
1168 register char *arg
= copy_name (yyvsp
[0].sval
);
1170 for (i
= 0; i
< misc_function_count
; i
++)
1171 if (!strcmp (misc_function_vector
[i
].name
, arg
))
1174 if (i
< misc_function_count
)
1176 enum misc_function_type mft
=
1177 (enum misc_function_type
)
1178 misc_function_vector
[i
].type
;
1180 write_exp_elt_opcode (OP_LONG
);
1181 write_exp_elt_type (builtin_type_int
);
1182 write_exp_elt_longcst ((LONGEST
) misc_function_vector
[i
].address
);
1183 write_exp_elt_opcode (OP_LONG
);
1184 write_exp_elt_opcode (UNOP_MEMVAL
);
1185 if (mft
== mf_data
|| mft
== mf_bss
)
1186 write_exp_elt_type (builtin_type_int
);
1187 else if (mft
== mf_text
)
1188 write_exp_elt_type (lookup_function_type (builtin_type_int
));
1190 write_exp_elt_type (builtin_type_char
);
1191 write_exp_elt_opcode (UNOP_MEMVAL
);
1193 else if (symtab_list
== 0
1194 && partial_symtab_list
== 0)
1195 error ("No symbol table is loaded. Use the \"symbol-file\" command.");
1197 error ("No symbol \"%s\" in current context.",
1198 copy_name (yyvsp
[0].sval
));
1203 #line 648 "expread.y"
1205 /* This is where the interesting stuff happens. */
1208 struct type
*follow_type
= yyvsp
[-1].tval
;
1211 switch (pop_type ())
1217 follow_type
= lookup_pointer_type (follow_type
);
1220 follow_type
= lookup_reference_type (follow_type
);
1223 array_size
= (int) pop_type ();
1224 if (array_size
!= -1)
1225 follow_type
= create_array_type (follow_type
,
1228 follow_type
= lookup_pointer_type (follow_type
);
1231 follow_type
= lookup_function_type (follow_type
);
1234 yyval
.tval
= follow_type
;
1238 #line 683 "expread.y"
1239 { push_type (tp_pointer
); yyval
.voidval
= 0; ;
1242 #line 685 "expread.y"
1243 { push_type (tp_pointer
); yyval
.voidval
= yyvsp
[0].voidval
; ;
1246 #line 690 "expread.y"
1247 { yyval
.voidval
= yyvsp
[-1].voidval
; ;
1250 #line 692 "expread.y"
1252 push_type ((enum type_pieces
) yyvsp
[0].lval
);
1253 push_type (tp_array
);
1257 #line 697 "expread.y"
1259 push_type ((enum type_pieces
) yyvsp
[0].lval
);
1260 push_type (tp_array
);
1265 #line 703 "expread.y"
1266 { push_type (tp_function
); ;
1269 #line 705 "expread.y"
1270 { push_type (tp_function
); ;
1273 #line 709 "expread.y"
1274 { yyval
.lval
= -1; ;
1277 #line 711 "expread.y"
1278 { yyval
.lval
= yyvsp
[-1].lval
; ;
1281 #line 715 "expread.y"
1282 { yyval
.voidval
= 0; ;
1285 #line 720 "expread.y"
1286 { yyval
.tval
= lookup_member_type (builtin_type_int
, yyvsp
[-2].tval
); ;
1289 #line 722 "expread.y"
1290 { yyval
.tval
= lookup_member_type (yyvsp
[-5].tval
, yyvsp
[-3].tval
); ;
1293 #line 724 "expread.y"
1294 { yyval
.tval
= lookup_member_type
1295 (lookup_function_type (yyvsp
[-7].tval
), yyvsp
[-5].tval
); ;
1298 #line 727 "expread.y"
1299 { yyval
.tval
= lookup_member_type
1300 (lookup_function_type (yyvsp
[-8].tval
), yyvsp
[-6].tval
);
1301 free (yyvsp
[-1].tvec
); ;
1304 #line 734 "expread.y"
1305 { yyval
.tval
= lookup_typename (copy_name (yyvsp
[0].sval
),
1306 expression_context_block
, 0); ;
1309 #line 737 "expread.y"
1310 { yyval
.tval
= builtin_type_int
; ;
1313 #line 739 "expread.y"
1314 { yyval
.tval
= builtin_type_long
; ;
1317 #line 741 "expread.y"
1318 { yyval
.tval
= builtin_type_short
; ;
1321 #line 743 "expread.y"
1322 { yyval
.tval
= builtin_type_long
; ;
1325 #line 745 "expread.y"
1326 { yyval
.tval
= builtin_type_unsigned_long
; ;
1329 #line 747 "expread.y"
1330 { yyval
.tval
= builtin_type_short
; ;
1333 #line 749 "expread.y"
1334 { yyval
.tval
= builtin_type_unsigned_short
; ;
1337 #line 751 "expread.y"
1338 { yyval
.tval
= lookup_struct (copy_name (yyvsp
[0].sval
),
1339 expression_context_block
); ;
1342 #line 754 "expread.y"
1343 { yyval
.tval
= lookup_union (copy_name (yyvsp
[0].sval
),
1344 expression_context_block
); ;
1347 #line 757 "expread.y"
1348 { yyval
.tval
= lookup_enum (copy_name (yyvsp
[0].sval
),
1349 expression_context_block
); ;
1352 #line 760 "expread.y"
1353 { yyval
.tval
= lookup_unsigned_typename (copy_name (yyvsp
[0].sval
)); ;
1356 #line 762 "expread.y"
1357 { yyval
.tval
= builtin_type_unsigned_int
; ;
1360 #line 764 "expread.y"
1361 { yyval
.tval
= lookup_typename (copy_name (yyvsp
[0].sval
),
1362 expression_context_block
, 0); ;
1365 #line 767 "expread.y"
1366 { yyval
.tval
= builtin_type_int
; ;
1369 #line 772 "expread.y"
1371 yyval
.sval
.ptr
= "int";
1372 yyval
.sval
.length
= 3;
1376 #line 777 "expread.y"
1378 yyval
.sval
.ptr
= "long";
1379 yyval
.sval
.length
= 4;
1383 #line 782 "expread.y"
1385 yyval
.sval
.ptr
= "short";
1386 yyval
.sval
.length
= 5;
1390 #line 790 "expread.y"
1391 { yyval
.tvec
= (struct type
**)xmalloc (sizeof (struct type
*) * 2);
1392 yyval
.tvec
[0] = (struct type
*)0;
1393 yyval
.tvec
[1] = yyvsp
[0].tval
;
1397 #line 795 "expread.y"
1398 { int len
= sizeof (struct type
*) * ++(yyvsp
[-2].ivec
[0]);
1399 yyval
.tvec
= (struct type
**)xrealloc (yyvsp
[-2].tvec
, len
);
1400 yyval
.tvec
[yyval
.ivec
[0]] = yyvsp
[0].tval
;
1404 /* the action file gets copied in in place of this dollarsign */
1405 #line 331 "bison.simple"
1416 short *ssp1
= yyss
- 1;
1417 fprintf (stderr
, "state stack now");
1418 while (ssp1
!= yyssp
)
1419 fprintf (stderr
, " %d", *++ssp1
);
1420 fprintf (stderr
, "\n");
1430 yylsp
->first_line
= yylloc
.first_line
;
1431 yylsp
->first_column
= yylloc
.first_column
;
1432 yylsp
->last_line
= (yylsp
-1)->last_line
;
1433 yylsp
->last_column
= (yylsp
-1)->last_column
;
1438 yylsp
->last_line
= (yylsp
+yylen
-1)->last_line
;
1439 yylsp
->last_column
= (yylsp
+yylen
-1)->last_column
;
1443 /* Now "shift" the result of the reduction.
1444 Determine what state that goes to,
1445 based on the state we popped back to
1446 and the rule number reduced by. */
1450 yystate
= yypgoto
[yyn
- YYNTBASE
] + *yyssp
;
1451 if (yystate
>= 0 && yystate
<= YYLAST
&& yycheck
[yystate
] == *yyssp
)
1452 yystate
= yytable
[yystate
];
1454 yystate
= yydefgoto
[yyn
- YYNTBASE
];
1458 yyerrlab
: /* here on detecting error */
1461 /* If not already recovering from an error, report this error. */
1464 yyerror("parse error");
1467 if (yyerrstatus
== 3)
1469 /* if just tried and failed to reuse lookahead token after an error, discard it. */
1471 /* return failure if at end of input */
1472 if (yychar
== YYEOF
)
1477 fprintf(stderr
, "Discarding token %d (%s).\n", yychar
, yytname
[yychar1
]);
1483 /* Else will try to reuse lookahead token
1484 after shifting the error token. */
1486 yyerrstatus
= 3; /* Each real token shifted decrements this */
1490 yyerrdefault
: /* current state does not do anything special for the error token. */
1493 /* This is wrong; only states that explicitly want error tokens
1494 should shift them. */
1495 yyn
= yydefact
[yystate
]; /* If its default is to accept any token, ok. Otherwise pop it.*/
1496 if (yyn
) goto yydefault
;
1499 yyerrpop
: /* pop the current state because it cannot handle the error token */
1501 if (yyssp
== yyss
) YYABORT
;
1511 short *ssp1
= yyss
- 1;
1512 fprintf (stderr
, "Error: state stack now");
1513 while (ssp1
!= yyssp
)
1514 fprintf (stderr
, " %d", *++ssp1
);
1515 fprintf (stderr
, "\n");
1521 yyn
= yypact
[yystate
];
1526 if (yyn
< 0 || yyn
> YYLAST
|| yycheck
[yyn
] != YYTERROR
)
1545 fprintf(stderr
, "Shifting error token, ");
1556 #line 810 "expread.y"
1559 /* Begin counting arguments for a function call,
1560 saving the data about any containing call. */
1565 register struct funcall
*new = (struct funcall
*) xmalloc (sizeof (struct funcall
));
1567 new->next
= funcall_chain
;
1568 new->arglist_len
= arglist_len
;
1570 funcall_chain
= new;
1573 /* Return the number of arguments in a function call just terminated,
1574 and restore the data for the containing function call. */
1579 register int val
= arglist_len
;
1580 register struct funcall
*call
= funcall_chain
;
1581 funcall_chain
= call
->next
;
1582 arglist_len
= call
->arglist_len
;
1587 /* Free everything in the funcall chain.
1588 Used when there is an error inside parsing. */
1593 register struct funcall
*call
, *next
;
1595 for (call
= funcall_chain
; call
; call
= next
)
1602 /* This page contains the functions for adding data to the struct expression
1603 being constructed. */
1605 /* Add one element to the end of the expression. */
1607 /* To avoid a bug in the Sun 4 compiler, we pass things that can fit into
1608 a register through here */
1611 write_exp_elt (expelt
)
1612 union exp_element expelt
;
1614 if (expout_ptr
>= expout_size
)
1617 expout
= (struct expression
*) xrealloc (expout
,
1618 sizeof (struct expression
)
1619 + expout_size
* sizeof (union exp_element
));
1621 expout
->elts
[expout_ptr
++] = expelt
;
1625 write_exp_elt_opcode (expelt
)
1626 enum exp_opcode expelt
;
1628 union exp_element tmp
;
1630 tmp
.opcode
= expelt
;
1632 write_exp_elt (tmp
);
1636 write_exp_elt_sym (expelt
)
1637 struct symbol
*expelt
;
1639 union exp_element tmp
;
1641 tmp
.symbol
= expelt
;
1643 write_exp_elt (tmp
);
1647 write_exp_elt_longcst (expelt
)
1650 union exp_element tmp
;
1652 tmp
.longconst
= expelt
;
1654 write_exp_elt (tmp
);
1658 write_exp_elt_dblcst (expelt
)
1661 union exp_element tmp
;
1663 tmp
.doubleconst
= expelt
;
1665 write_exp_elt (tmp
);
1669 write_exp_elt_type (expelt
)
1670 struct type
*expelt
;
1672 union exp_element tmp
;
1676 write_exp_elt (tmp
);
1680 write_exp_elt_intern (expelt
)
1681 struct internalvar
*expelt
;
1683 union exp_element tmp
;
1685 tmp
.internalvar
= expelt
;
1687 write_exp_elt (tmp
);
1690 /* Add a string constant to the end of the expression.
1691 Follow it by its length in bytes, as a separate exp_element. */
1694 write_exp_string (str
)
1697 register int len
= str
.length
;
1699 = (len
+ sizeof (union exp_element
)) / sizeof (union exp_element
);
1701 expout_ptr
+= lenelt
;
1703 if (expout_ptr
>= expout_size
)
1705 expout_size
= max (expout_size
* 2, expout_ptr
+ 10);
1706 expout
= (struct expression
*)
1707 xrealloc (expout
, (sizeof (struct expression
)
1708 + (expout_size
* sizeof (union exp_element
))));
1710 bcopy (str
.ptr
, (char *) &expout
->elts
[expout_ptr
- lenelt
], len
);
1711 ((char *) &expout
->elts
[expout_ptr
- lenelt
])[len
] = 0;
1712 write_exp_elt_longcst ((LONGEST
) len
);
1715 /* During parsing of a C expression, the pointer to the next character
1716 is in this variable. */
1718 static char *lexptr
;
1720 /* Tokens that refer to names do so with explicit pointer and length,
1721 so they can share the storage that lexptr is parsing.
1723 When it is necessary to pass a name to a function that expects
1724 a null-terminated string, the substring is copied out
1725 into a block of storage that namecopy points to.
1727 namecopy is allocated once, guaranteed big enough, for each parsing. */
1729 static char *namecopy
;
1731 /* Current depth in parentheses within the expression. */
1733 static int paren_depth
;
1735 /* Nonzero means stop parsing on first comma (if not within parentheses). */
1737 static int comma_terminates
;
1739 /* Take care of parsing a number (anything that starts with a digit).
1740 Set yylval and return the token type; update lexptr.
1741 LEN is the number of characters in it. */
1743 /*** Needs some error checking for the float case ***/
1749 register char *p
= lexptr
;
1750 register LONGEST n
= 0;
1752 register int base
= 10;
1753 register int len
= olen
;
1757 extern double atof ();
1759 for (c
= 0; c
< len
; c
++)
1762 /* It's a float since it contains a point. */
1763 yylval
.dval
= atof (p
);
1768 if (len
>= 3 && (!strncmp (p
, "0x", 2) || !strncmp (p
, "0X", 2)))
1780 if (c
>= 'A' && c
<= 'Z') c
+= 'a' - 'A';
1781 if (c
!= 'l' && c
!= 'u')
1783 if (c
>= '0' && c
<= '9')
1787 if (base
== 16 && c
>= 'a' && c
<= 'f')
1789 else if (len
== 0 && c
== 'l')
1791 else if (len
== 0 && c
== 'u')
1793 else if (base
== 10 && len
!= 0 && (c
== 'e' || c
== 'E'))
1795 /* Scientific notation, where we are unlucky enough not
1796 to have a '.' in the string. */
1797 yylval
.dval
= atof (lexptr
);
1803 err_copy
= (char *) alloca (olen
+ 1);
1804 bcopy (lexptr
, err_copy
, olen
);
1806 error ("Invalid number \"%s\".", err_copy
);
1828 enum exp_opcode opcode
;
1831 static struct token tokentab3
[] =
1833 {">>=", ASSIGN_MODIFY
, BINOP_RSH
},
1834 {"<<=", ASSIGN_MODIFY
, BINOP_LSH
}
1837 static struct token tokentab2
[] =
1839 {"+=", ASSIGN_MODIFY
, BINOP_ADD
},
1840 {"-=", ASSIGN_MODIFY
, BINOP_SUB
},
1841 {"*=", ASSIGN_MODIFY
, BINOP_MUL
},
1842 {"/=", ASSIGN_MODIFY
, BINOP_DIV
},
1843 {"%=", ASSIGN_MODIFY
, BINOP_REM
},
1844 {"|=", ASSIGN_MODIFY
, BINOP_LOGIOR
},
1845 {"&=", ASSIGN_MODIFY
, BINOP_LOGAND
},
1846 {"^=", ASSIGN_MODIFY
, BINOP_LOGXOR
},
1847 {"++", INCREMENT
, BINOP_END
},
1848 {"--", DECREMENT
, BINOP_END
},
1849 {"->", ARROW
, BINOP_END
},
1850 {"&&", AND
, BINOP_END
},
1851 {"||", OR
, BINOP_END
},
1852 {"::", COLONCOLON
, BINOP_END
},
1853 {"<<", LSH
, BINOP_END
},
1854 {">>", RSH
, BINOP_END
},
1855 {"==", EQUAL
, BINOP_END
},
1856 {"!=", NOTEQUAL
, BINOP_END
},
1857 {"<=", LEQ
, BINOP_END
},
1858 {">=", GEQ
, BINOP_END
}
1861 /* assign machine-independent names to certain registers
1862 * (unless overridden by the REGISTER_NAMES table)
1869 { "pc", PC_REGNUM
},
1872 { "fp", FP_REGNUM
},
1875 { "sp", SP_REGNUM
},
1878 { "ps", PS_REGNUM
},
1882 #define NUM_STD_REGS (sizeof std_regs / sizeof std_regs[0])
1884 /* Read one token, getting characters through lexptr. */
1890 register int namelen
;
1892 register char *tokstart
;
1897 /* See if it is a special token of length 3. */
1898 for (i
= 0; i
< sizeof tokentab3
/ sizeof tokentab3
[0]; i
++)
1899 if (!strncmp (tokstart
, tokentab3
[i
].operator, 3))
1902 yylval
.opcode
= tokentab3
[i
].opcode
;
1903 return tokentab3
[i
].token
;
1906 /* See if it is a special token of length 2. */
1907 for (i
= 0; i
< sizeof tokentab2
/ sizeof tokentab2
[0]; i
++)
1908 if (!strncmp (tokstart
, tokentab2
[i
].operator, 2))
1911 yylval
.opcode
= tokentab2
[i
].opcode
;
1912 return tokentab2
[i
].token
;
1915 switch (c
= *tokstart
)
1930 c
= parse_escape (&lexptr
);
1934 error ("Invalid character constant.");
1943 if (paren_depth
== 0)
1950 if (comma_terminates
&& paren_depth
== 0)
1956 /* Might be a floating point number. */
1957 if (lexptr
[1] >= '0' && lexptr
[1] <= '9')
1958 break; /* Falls into number code. */
1984 for (namelen
= 1; (c
= tokstart
[namelen
]) != '"'; namelen
++)
1987 c
= tokstart
[++namelen
];
1988 if (c
>= '0' && c
<= '9')
1990 c
= tokstart
[++namelen
];
1991 if (c
>= '0' && c
<= '9')
1992 c
= tokstart
[++namelen
];
1995 yylval
.sval
.ptr
= tokstart
+ 1;
1996 yylval
.sval
.length
= namelen
- 1;
1997 lexptr
+= namelen
+ 1;
2001 /* Is it a number? */
2002 /* Note: We have already dealt with the case of the token '.'.
2003 See case '.' above. */
2004 if ((c
>= '0' && c
<= '9') || c
== '.')
2006 /* It's a number. */
2007 int got_dot
= 0, got_e
= 0;
2008 register char *p
= tokstart
;
2009 int hex
= c
== '0' && (p
[1] == 'x' || p
[1] == 'X');
2014 if (!hex
&& !got_e
&& (*p
== 'e' || *p
== 'E'))
2015 got_dot
= got_e
= 1;
2016 else if (!hex
&& !got_dot
&& *p
== '.')
2018 else if (got_e
&& (p
[-1] == 'e' || p
[-1] == 'E')
2019 && (*p
== '-' || *p
== '+'))
2020 /* This is the sign of the exponent, not the end of the
2023 else if (*p
< '0' || *p
> '9'
2024 && (!hex
|| ((*p
< 'a' || *p
> 'f')
2025 && (*p
< 'A' || *p
> 'F'))))
2028 return parse_number (p
- tokstart
);
2031 if (!(c
== '_' || c
== '$'
2032 || (c
>= 'a' && c
<= 'z') || (c
>= 'A' && c
<= 'Z')))
2033 error ("Invalid token in expression.");
2035 /* It's a name. See how long it is. */
2037 for (c
= tokstart
[namelen
];
2038 (c
== '_' || c
== '$' || (c
>= '0' && c
<= '9')
2039 || (c
>= 'a' && c
<= 'z') || (c
>= 'A' && c
<= 'Z'));
2040 c
= tokstart
[++namelen
])
2043 /* The token "if" terminates the expression and is NOT
2044 removed from the input stream. */
2045 if (namelen
== 2 && tokstart
[0] == 'i' && tokstart
[1] == 'f')
2052 /* Handle the tokens $digits; also $ (short for $0) and $$ (short for $$1)
2053 and $$digits (equivalent to $<-digits> if you could type that).
2054 Make token type LAST, and put the number (the digits) in yylval. */
2056 if (*tokstart
== '$')
2058 register int negate
= 0;
2060 /* Double dollar means negate the number and add -1 as well.
2061 Thus $$ alone means -1. */
2062 if (namelen
>= 2 && tokstart
[1] == '$')
2069 /* Just dollars (one or two) */
2070 yylval
.lval
= - negate
;
2073 /* Is the rest of the token digits? */
2074 for (; c
< namelen
; c
++)
2075 if (!(tokstart
[c
] >= '0' && tokstart
[c
] <= '9'))
2079 yylval
.lval
= atoi (tokstart
+ 1 + negate
);
2081 yylval
.lval
= - yylval
.lval
;
2086 /* Handle tokens that refer to machine registers:
2087 $ followed by a register name. */
2089 if (*tokstart
== '$') {
2090 for (c
= 0; c
< NUM_REGS
; c
++)
2091 if (namelen
- 1 == strlen (reg_names
[c
])
2092 && !strncmp (tokstart
+ 1, reg_names
[c
], namelen
- 1))
2097 for (c
= 0; c
< NUM_STD_REGS
; c
++)
2098 if (namelen
- 1 == strlen (std_regs
[c
].name
)
2099 && !strncmp (tokstart
+ 1, std_regs
[c
].name
, namelen
- 1))
2101 yylval
.lval
= std_regs
[c
].regnum
;
2105 /* Catch specific keywords. Should be done with a data structure. */
2109 if (!strncmp (tokstart
, "unsigned", 8))
2113 if (!strncmp (tokstart
, "struct", 6))
2115 if (!strncmp (tokstart
, "signed", 6))
2117 if (!strncmp (tokstart
, "sizeof", 6))
2121 if (!strncmp (tokstart
, "union", 5))
2123 if (!strncmp (tokstart
, "short", 5))
2127 if (!strncmp (tokstart
, "enum", 4))
2129 if (!strncmp (tokstart
, "long", 4))
2131 if (!strncmp (tokstart
, "this", 4)
2132 && lookup_symbol ("$this", expression_context_block
,
2137 if (!strncmp (tokstart
, "int", 3))
2144 yylval
.sval
.ptr
= tokstart
;
2145 yylval
.sval
.length
= namelen
;
2147 /* Any other names starting in $ are debugger internal variables. */
2149 if (*tokstart
== '$')
2151 yylval
.ivar
= (struct internalvar
*) lookup_internalvar (copy_name (yylval
.sval
) + 1);
2155 /* Use token-type BLOCKNAME for symbols that happen to be defined as
2156 functions or symtabs. If this is not so, then ...
2157 Use token-type TYPENAME for symbols that happen to be defined
2158 currently as names of types; NAME for other symbols.
2159 The caller is not constrained to care about the distinction. */
2161 char *tmp
= copy_name (yylval
.sval
);
2164 if (lookup_partial_symtab (tmp
))
2166 sym
= lookup_symbol (tmp
, expression_context_block
,
2168 if (sym
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
2170 if (lookup_typename (copy_name (yylval
.sval
), expression_context_block
, 1))
2179 error ("Invalid syntax in expression.");
2182 /* Return a null-terminated temporary copy of the name
2183 of a string token. */
2187 struct stoken token
;
2189 bcopy (token
.ptr
, namecopy
, token
.length
);
2190 namecopy
[token
.length
] = 0;
2194 /* Reverse an expression from suffix form (in which it is constructed)
2195 to prefix form (in which we can conveniently print or execute it). */
2197 static void prefixify_subexp ();
2200 prefixify_expression (expr
)
2201 register struct expression
*expr
;
2203 register int len
= sizeof (struct expression
) +
2204 expr
->nelts
* sizeof (union exp_element
);
2205 register struct expression
*temp
;
2206 register int inpos
= expr
->nelts
, outpos
= 0;
2208 temp
= (struct expression
*) alloca (len
);
2210 /* Copy the original expression into temp. */
2211 bcopy (expr
, temp
, len
);
2213 prefixify_subexp (temp
, expr
, inpos
, outpos
);
2216 /* Return the number of exp_elements in the subexpression of EXPR
2217 whose last exp_element is at index ENDPOS - 1 in EXPR. */
2220 length_of_subexp (expr
, endpos
)
2221 register struct expression
*expr
;
2222 register int endpos
;
2224 register int oplen
= 1;
2225 register int args
= 0;
2229 error ("?error in length_of_subexp");
2231 i
= (int) expr
->elts
[endpos
- 1].opcode
;
2237 oplen
= 4 + ((expr
->elts
[endpos
- 2].longconst
2238 + sizeof (union exp_element
))
2239 / sizeof (union exp_element
));
2250 case OP_INTERNALVAR
:
2256 args
= 1 + expr
->elts
[endpos
- 2].longconst
;
2265 case STRUCTOP_STRUCT
:
2269 oplen
= 3 + ((expr
->elts
[endpos
- 2].longconst
2270 + sizeof (union exp_element
))
2271 / sizeof (union exp_element
));
2278 case BINOP_ASSIGN_MODIFY
:
2289 args
= 1 + (i
< (int) BINOP_END
);
2294 oplen
+= length_of_subexp (expr
, endpos
- oplen
);
2301 /* Copy the subexpression ending just before index INEND in INEXPR
2302 into OUTEXPR, starting at index OUTBEG.
2303 In the process, convert it from suffix to prefix form. */
2306 prefixify_subexp (inexpr
, outexpr
, inend
, outbeg
)
2307 register struct expression
*inexpr
;
2308 struct expression
*outexpr
;
2312 register int oplen
= 1;
2313 register int args
= 0;
2316 enum exp_opcode opcode
;
2318 /* Compute how long the last operation is (in OPLEN),
2319 and also how many preceding subexpressions serve as
2320 arguments for it (in ARGS). */
2322 opcode
= inexpr
->elts
[inend
- 1].opcode
;
2327 oplen
= 4 + ((inexpr
->elts
[inend
- 2].longconst
2328 + sizeof (union exp_element
))
2329 / sizeof (union exp_element
));
2340 case OP_INTERNALVAR
:
2346 args
= 1 + inexpr
->elts
[inend
- 2].longconst
;
2355 case STRUCTOP_STRUCT
:
2359 oplen
= 3 + ((inexpr
->elts
[inend
- 2].longconst
2360 + sizeof (union exp_element
))
2361 / sizeof (union exp_element
));
2369 case BINOP_ASSIGN_MODIFY
:
2380 args
= 1 + ((int) opcode
< (int) BINOP_END
);
2383 /* Copy the final operator itself, from the end of the input
2384 to the beginning of the output. */
2386 bcopy (&inexpr
->elts
[inend
], &outexpr
->elts
[outbeg
],
2387 oplen
* sizeof (union exp_element
));
2390 /* Find the lengths of the arg subexpressions. */
2391 arglens
= (int *) alloca (args
* sizeof (int));
2392 for (i
= args
- 1; i
>= 0; i
--)
2394 oplen
= length_of_subexp (inexpr
, inend
);
2399 /* Now copy each subexpression, preserving the order of
2400 the subexpressions, but prefixifying each one.
2401 In this loop, inend starts at the beginning of
2402 the expression this level is working on
2403 and marches forward over the arguments.
2404 outbeg does similarly in the output. */
2405 for (i
= 0; i
< args
; i
++)
2409 prefixify_subexp (inexpr
, outexpr
, inend
, outbeg
);
2414 /* This page contains the two entry points to this file. */
2416 /* Read a C expression from the string *STRINGPTR points to,
2417 parse it, and return a pointer to a struct expression that we malloc.
2418 Use block BLOCK as the lexical context for variable names;
2419 if BLOCK is zero, use the block of the selected stack frame.
2420 Meanwhile, advance *STRINGPTR to point after the expression,
2421 at the first nonwhite character that is not part of the expression
2422 (possibly a null character).
2424 If COMMA is nonzero, stop if a comma is reached. */
2427 parse_c_1 (stringptr
, block
, comma
)
2429 struct block
*block
;
2431 struct cleanup
*old_chain
;
2433 lexptr
= *stringptr
;
2436 type_stack_depth
= 0;
2438 comma_terminates
= comma
;
2440 if (lexptr
== 0 || *lexptr
== 0)
2441 error_no_arg ("expression to compute");
2443 old_chain
= make_cleanup (free_funcalls
, 0);
2446 expression_context_block
= block
? block
: get_selected_block ();
2448 namecopy
= (char *) alloca (strlen (lexptr
) + 1);
2451 expout
= (struct expression
*)
2452 xmalloc (sizeof (struct expression
)
2453 + expout_size
* sizeof (union exp_element
));
2454 make_cleanup (free_current_contents
, &expout
);
2457 discard_cleanups (old_chain
);
2458 expout
->nelts
= expout_ptr
;
2459 expout
= (struct expression
*)
2461 sizeof (struct expression
)
2462 + expout_ptr
* sizeof (union exp_element
));
2463 prefixify_expression (expout
);
2464 *stringptr
= lexptr
;
2468 /* Parse STRING as an expression, and complain if this fails
2469 to use up all of the contents of STRING. */
2472 parse_c_expression (string
)
2475 register struct expression
*exp
;
2476 exp
= parse_c_1 (&string
, 0, 0);
2478 error ("Junk after end of expression.");
2484 enum type_pieces tp
;
2486 if (type_stack_depth
== type_stack_size
)
2488 type_stack_size
*= 2;
2489 type_stack
= (enum type_pieces
*)
2490 xrealloc (type_stack
, type_stack_size
* sizeof (enum type_pieces
));
2492 type_stack
[type_stack_depth
++] = tp
;
2495 static enum type_pieces
2498 if (type_stack_depth
)
2499 return type_stack
[--type_stack_depth
];
2504 _initialize_expread ()
2506 type_stack_size
= 80;
2507 type_stack_depth
= 0;
2508 type_stack
= (enum type_pieces
*)
2509 xmalloc (type_stack_size
* sizeof (enum type_pieces
));