2 /* A Bison parser, made from expread.y */
15 #define COLONCOLON 269
19 #define ASSIGN_MODIFY 273
21 #define ABOVE_COMMA 275
41 #include "expression.h"
45 static struct expression
*expout
;
46 static int expout_size
;
47 static int expout_ptr
;
51 static void write_exp_elt ();
52 static void write_exp_string ();
53 static void start_arglist ();
54 static int end_arglist ();
55 static void free_funcalls ();
56 static char *copy_name ();
58 /* If this is nonzero, this block is used as the lexical context
61 static struct block
*expression_context_block
;
63 /* Number of arguments seen so far in innermost function call. */
64 static int arglist_len
;
66 /* Data structure for saving values of arglist_len
67 for function calls whose arguments contain other function calls. */
75 struct funcall
*funcall_chain
;
77 /* This kind of datum is used to represent the name
96 enum exp_opcode opcode
;
97 struct internalvar
*ivar
;
116 #define YYLTYPE yyltype
119 #define YYACCEPT return(0)
120 #define YYABORT return(1)
121 #define YYERROR return(1)
131 #define YYFLAG -32768
134 #define YYTRANSLATE(x) ((unsigned)(x) <= 287 ? yytranslate[x] : 68)
136 static const char yytranslate
[] = { 0,
137 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
138 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
139 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
140 2, 2, 48, 2, 2, 2, 40, 27, 2, 51,
141 52, 38, 36, 20, 37, 46, 39, 2, 2, 2,
142 2, 2, 2, 2, 2, 2, 2, 56, 2, 30,
143 22, 31, 55, 41, 2, 2, 2, 2, 2, 2,
144 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
145 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
146 47, 2, 50, 26, 2, 2, 2, 2, 2, 2,
147 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
148 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
149 2, 2, 53, 25, 54, 49, 2, 2, 2, 2,
150 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
151 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
152 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
153 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
154 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
155 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
156 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
157 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
158 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
159 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
160 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
161 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
162 2, 2, 2, 2, 2, 1, 2, 3, 4, 5,
163 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
164 16, 17, 18, 19, 21, 23, 24, 28, 29, 32,
165 33, 34, 35, 42, 43, 44, 45
168 static const short yyrline
[] = { 0,
169 152, 156, 157, 162, 165, 168, 172, 176, 180, 184,
170 188, 192, 196, 200, 206, 210, 216, 220, 224, 228,
171 234, 237, 241, 245, 251, 257, 263, 267, 271, 275,
172 279, 283, 287, 291, 295, 299, 303, 307, 311, 315,
173 319, 323, 327, 331, 335, 339, 343, 347, 353, 360,
174 367, 374, 377, 383, 389, 395, 402, 409, 416, 437,
175 448, 461, 474, 510, 575, 576, 578, 580, 582, 584,
176 586, 592, 595, 598, 601, 604, 609, 614, 621, 622
179 static const char * const yytname
[] = { 0,
180 "error","$illegal.","INT","CHAR","FLOAT","NAME","TYPENAME","STRING","STRUCT","UNION",
181 "ENUM","SIZEOF","UNSIGNED","COLONCOLON","LAST","REGNAME","VARIABLE","ASSIGN_MODIFY","THIS","','",
182 "ABOVE_COMMA","'='","OR","AND","'|'","'^'","'&'","EQUAL","NOTEQUAL","'<'",
183 "'>'","LEQ","GEQ","LSH","RSH","'+'","'-'","'*'","'/'","'%'",
184 "'@'","UNARY","INCREMENT","DECREMENT","ARROW","'.'","'['","'!'","'~'","']'",
185 "'('","')'","'{'","'}'","'?'","':'","start"
188 static const short yyr1
[] = { 0,
189 57, 58, 58, 59, 59, 59, 59, 59, 59, 59,
190 59, 59, 59, 59, 59, 59, 59, 59, 60, 59,
191 61, 61, 61, 59, 59, 59, 59, 59, 59, 59,
192 59, 59, 59, 59, 59, 59, 59, 59, 59, 59,
193 59, 59, 59, 59, 59, 59, 59, 59, 59, 59,
194 59, 59, 59, 59, 59, 59, 59, 59, 62, 62,
195 63, 63, 63, 63, 64, 64, 64, 64, 64, 64,
196 64, 65, 65, 65, 65, 65, 66, 66, 67, 67
199 static const short yyr2
[] = { 0,
200 1, 1, 3, 2, 2, 2, 2, 2, 2, 2,
201 2, 2, 2, 3, 4, 3, 4, 4, 0, 5,
202 0, 1, 3, 4, 4, 3, 3, 3, 3, 3,
203 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
204 3, 3, 3, 3, 3, 5, 3, 3, 1, 1,
205 1, 1, 1, 1, 1, 4, 1, 1, 1, 3,
206 3, 3, 2, 1, 1, 2, 2, 3, 6, 8,
207 9, 1, 2, 2, 2, 2, 1, 3, 1, 1
210 static const short yydefact
[] = { 0,
211 49, 50, 51, 64, 72, 57, 0, 0, 0, 0,
212 0, 0, 53, 54, 55, 58, 0, 0, 0, 0,
213 0, 0, 0, 0, 0, 1, 2, 0, 52, 0,
214 59, 79, 80, 73, 74, 75, 0, 13, 76, 63,
215 5, 6, 4, 9, 10, 7, 8, 0, 0, 65,
216 72, 0, 65, 0, 0, 0, 0, 0, 0, 0,
217 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
218 0, 0, 0, 0, 0, 11, 12, 0, 0, 0,
219 19, 0, 0, 0, 0, 26, 67, 66, 0, 0,
220 0, 0, 0, 3, 48, 47, 45, 44, 43, 42,
221 41, 35, 36, 39, 40, 37, 38, 33, 34, 31,
222 32, 28, 29, 30, 27, 0, 14, 0, 16, 0,
223 21, 0, 61, 62, 56, 0, 25, 68, 24, 15,
224 17, 18, 22, 0, 0, 0, 0, 20, 46, 0,
225 23, 69, 0, 70, 77, 0, 0, 71, 78, 0,
229 static const short yydefgoto
[] = { 150,
230 48, 27, 121, 134, 28, 29, 49, 30, 146, 31
233 static const short yypact
[] = { 125,
234 -32768,-32768,-32768, 1,-32768,-32768, 24, 24, 24, 176,
235 24, 24,-32768,-32768,-32768,-32768, 125, 125, 125, 125,
236 125, 125, 125, 125, 515, 0, 243, 14,-32768, 18,
237 -32768,-32768,-32768,-32768,-32768,-32768, 125, 472,-32768,-32768,
238 472, 472, 472, 472, 472, 472, 472, 21, 52, 19,
239 -32768, 58, 20, 125, 125, 125, 125, 125, 125, 125,
240 125, 125, 125, 125, 125, 125, 125, 125, 125, 125,
241 125, 125, 125, 125, 125,-32768,-32768, -1, 29, 125,
242 -32768, 125, 24, 24, 119,-32768,-32768,-32768, 515, 125,
243 32, 125, -14, 243, 243, 243, 275, 306, 336, 365,
244 393, 419, 419, 441, 441, 441, 441, 161, 161, 459,
245 459, 104, 104, 104, 472, 125,-32768, 125,-32768, 49,
246 125, 208, 26,-32768, 125, 57, 472,-32768, 472, 104,
247 104,-32768, 243, 22, 125, 38, 125,-32768, 243, 25,
248 243, 27, 16,-32768, 54, 23, 515,-32768, 54, 84,
252 static const short yypgoto
[] = {-32768,
253 3, -10,-32768,-32768,-32768,-32768, -21, -23,-32768, 10
260 static const short yytable
[] = { 38,
261 50, 53, 26, 52, 32, 33, 41, 42, 43, 44,
262 45, 46, 47, 50, -79, 85, 34, 35, 36, 54,
263 39, 40, 51, 128, 7, 8, 9, 83, 11, 32,
264 33, 84, 91, 93, 32, 33, 116, 32, 33, -60,
265 54, 137, 147, 94, 95, 96, 97, 98, 99, 100,
266 101, 102, 103, 104, 105, 106, 107, 108, 109, 110,
267 111, 112, 113, 114, 115, 126, 118, 144, 54, 128,
268 136, 122, 86, 138, 148, 140, 142, 143, 87, 127,
269 87, 129, 120, 151, 87, 152, 0, 117, 119, 88,
270 0, 88, 123, 124, 0, 88, 0, 0, 132, 0,
271 124, 0, 89, 90, 89, 130, 0, 131, 89, 0,
272 133, 92, 0, 0, 127, 0, 0, 0, 0, 53,
273 0, 145, 0, 53, 139, 149, 141, 1, 2, 3,
274 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
275 14, 15, 0, 16, 75, 87, 76, 77, 78, 79,
276 80, 17, 0, 0, 81, 0, 88, 0, 82, 0,
277 0, 18, 19, 0, 0, 0, 0, 20, 21, 89,
278 125, 0, 22, 23, 0, 24, 0, 25, 1, 2,
279 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
280 13, 14, 15, 0, 16, 0, 70, 71, 72, 73,
281 74, 75, 17, 76, 77, 78, 79, 80, 0, 0,
282 0, 81, 18, 19, 0, 82, 0, 0, 20, 21,
283 0, 0, 0, 22, 23, 55, 37, 0, 25, 56,
284 57, 58, 59, 60, 61, 62, 63, 64, 65, 66,
285 67, 68, 69, 70, 71, 72, 73, 74, 75, 0,
286 76, 77, 78, 79, 80, 0, 0, 0, 81, 0,
287 55, 0, 82, 135, 56, 57, 58, 59, 60, 61,
288 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
289 72, 73, 74, 75, 0, 76, 77, 78, 79, 80,
290 0, 0, 0, 81, 0, 0, 0, 82, 58, 59,
291 60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
292 70, 71, 72, 73, 74, 75, 0, 76, 77, 78,
293 79, 80, 0, 0, 0, 81, 0, 0, 0, 82,
294 59, 60, 61, 62, 63, 64, 65, 66, 67, 68,
295 69, 70, 71, 72, 73, 74, 75, 0, 76, 77,
296 78, 79, 80, 0, 0, 0, 81, 0, 0, 0,
297 82, 60, 61, 62, 63, 64, 65, 66, 67, 68,
298 69, 70, 71, 72, 73, 74, 75, 0, 76, 77,
299 78, 79, 80, 0, 0, 0, 81, 0, 0, 0,
300 82, 61, 62, 63, 64, 65, 66, 67, 68, 69,
301 70, 71, 72, 73, 74, 75, 0, 76, 77, 78,
302 79, 80, 0, 0, 0, 81, 0, 0, 0, 82,
303 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
304 72, 73, 74, 75, 0, 76, 77, 78, 79, 80,
305 0, 0, 0, 81, 0, 0, 0, 82, 64, 65,
306 66, 67, 68, 69, 70, 71, 72, 73, 74, 75,
307 0, 76, 77, 78, 79, 80, 0, 0, 0, 81,
308 0, 0, 0, 82, 68, 69, 70, 71, 72, 73,
309 74, 75, 0, 76, 77, 78, 79, 80, 0, 0,
310 0, 81, 0, 0, 0, 82, 72, 73, 74, 75,
311 0, 76, 77, 78, 79, 80, 0, 0, 0, 81,
312 0, 0, 0, 82, 76, 77, 78, 79, 80, 0,
313 0, 51, 81, 7, 8, 9, 82, 11
316 static const short yycheck
[] = { 10,
317 24, 25, 0, 25, 6, 7, 17, 18, 19, 20,
318 21, 22, 23, 37, 14, 37, 7, 8, 9, 20,
319 11, 12, 7, 38, 9, 10, 11, 14, 13, 6,
320 7, 14, 14, 14, 6, 7, 38, 6, 7, 14,
321 20, 20, 20, 54, 55, 56, 57, 58, 59, 60,
322 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
323 71, 72, 73, 74, 75, 89, 38, 52, 20, 38,
324 14, 82, 52, 52, 52, 38, 52, 51, 27, 90,
325 27, 92, 80, 0, 27, 0, -1, 78, 79, 38,
326 -1, 38, 83, 84, -1, 38, -1, -1, 50, -1,
327 91, -1, 51, 52, 51, 116, -1, 118, 51, -1,
328 121, 54, -1, -1, 125, -1, -1, -1, -1, 143,
329 -1, 143, -1, 147, 135, 147, 137, 3, 4, 5,
330 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
331 16, 17, -1, 19, 41, 27, 43, 44, 45, 46,
332 47, 27, -1, -1, 51, -1, 38, -1, 55, -1,
333 -1, 37, 38, -1, -1, -1, -1, 43, 44, 51,
334 52, -1, 48, 49, -1, 51, -1, 53, 3, 4,
335 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
336 15, 16, 17, -1, 19, -1, 36, 37, 38, 39,
337 40, 41, 27, 43, 44, 45, 46, 47, -1, -1,
338 -1, 51, 37, 38, -1, 55, -1, -1, 43, 44,
339 -1, -1, -1, 48, 49, 18, 51, -1, 53, 22,
340 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
341 33, 34, 35, 36, 37, 38, 39, 40, 41, -1,
342 43, 44, 45, 46, 47, -1, -1, -1, 51, -1,
343 18, -1, 55, 56, 22, 23, 24, 25, 26, 27,
344 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
345 38, 39, 40, 41, -1, 43, 44, 45, 46, 47,
346 -1, -1, -1, 51, -1, -1, -1, 55, 24, 25,
347 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
348 36, 37, 38, 39, 40, 41, -1, 43, 44, 45,
349 46, 47, -1, -1, -1, 51, -1, -1, -1, 55,
350 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
351 35, 36, 37, 38, 39, 40, 41, -1, 43, 44,
352 45, 46, 47, -1, -1, -1, 51, -1, -1, -1,
353 55, 26, 27, 28, 29, 30, 31, 32, 33, 34,
354 35, 36, 37, 38, 39, 40, 41, -1, 43, 44,
355 45, 46, 47, -1, -1, -1, 51, -1, -1, -1,
356 55, 27, 28, 29, 30, 31, 32, 33, 34, 35,
357 36, 37, 38, 39, 40, 41, -1, 43, 44, 45,
358 46, 47, -1, -1, -1, 51, -1, -1, -1, 55,
359 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
360 38, 39, 40, 41, -1, 43, 44, 45, 46, 47,
361 -1, -1, -1, 51, -1, -1, -1, 55, 30, 31,
362 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
363 -1, 43, 44, 45, 46, 47, -1, -1, -1, 51,
364 -1, -1, -1, 55, 34, 35, 36, 37, 38, 39,
365 40, 41, -1, 43, 44, 45, 46, 47, -1, -1,
366 -1, 51, -1, -1, -1, 55, 38, 39, 40, 41,
367 -1, 43, 44, 45, 46, 47, -1, -1, -1, 51,
368 -1, -1, -1, 55, 43, 44, 45, 46, 47, -1,
369 -1, 7, 51, 9, 10, 11, 55, 13
373 #line 2 "bison.simple"
375 /* Skeleton output parser for bison,
376 copyright (C) 1984 Bob Corbett and Richard Stallman
380 BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
381 NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW. EXCEPT
382 WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
383 RICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
384 WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
385 BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
386 FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY
387 AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
388 DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
391 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
392 STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
393 WHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
394 LIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
395 OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
396 USE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
397 DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
398 A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
399 PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
400 DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
402 GENERAL PUBLIC LICENSE TO COPY
404 1. You may copy and distribute verbatim copies of this source file
405 as you receive it, in any medium, provided that you conspicuously and
406 appropriately publish on each copy a valid copyright notice "Copyright
407 (C) 1985 Free Software Foundation, Inc."; and include following the
408 copyright notice a verbatim copy of the above disclaimer of warranty
409 and of this License. You may charge a distribution fee for the
410 physical act of transferring a copy.
412 2. You may modify your copy or copies of this source file or
413 any portion of it, and copy and distribute such modifications under
414 the terms of Paragraph 1 above, provided that you also do the following:
416 a) cause the modified files to carry prominent notices stating
417 that you changed the files and the date of any change; and
419 b) cause the whole of any work that you distribute or publish,
420 that in whole or in part contains or is a derivative of this
421 program or any part thereof, to be licensed at no charge to all
422 third parties on terms identical to those contained in this
423 License Agreement (except that you may choose to grant more
424 extensive warranty protection to third parties, at your option).
426 c) You may charge a distribution fee for the physical act of
427 transferring a copy, and you may at your option offer warranty
428 protection in exchange for a fee.
430 3. You may copy and distribute this program or any portion of it in
431 compiled, executable or object code form under the terms of Paragraphs
432 1 and 2 above provided that you do the following:
434 a) cause each such copy to be accompanied by the
435 corresponding machine-readable source code, which must
436 be distributed under the terms of Paragraphs 1 and 2 above; or,
438 b) cause each such copy to be accompanied by a
439 written offer, with no time limit, to give any third party
440 free (except for a nominal shipping charge) a machine readable
441 copy of the corresponding source code, to be distributed
442 under the terms of Paragraphs 1 and 2 above; or,
444 c) in the case of a recipient of this program in compiled, executable
445 or object code form (without the corresponding source code) you
446 shall cause copies you distribute to be accompanied by a copy
447 of the written offer of source code which you received along
448 with the copy you received.
450 4. You may not copy, sublicense, distribute or transfer this program
451 except as expressly provided under this License Agreement. Any attempt
452 otherwise to copy, sublicense, distribute or transfer this program is void and
453 your rights to use the program under this License agreement shall be
454 automatically terminated. However, parties who have received computer
455 software programs from you with this License Agreement will not have
456 their licenses terminated so long as such parties remain in full compliance.
458 5. If you wish to incorporate parts of this program into other free
459 programs whose distribution conditions are different, write to the Free
460 Software Foundation at 675 Mass Ave, Cambridge, MA 02139. We have not yet
461 worked out a simple rule that can be stated here, but we will often permit
462 this. We will be guided by the two goals of preserving the free status of
463 all derivatives of our free software and of promoting the sharing and reuse of
467 In other words, you are welcome to use, share and improve this program.
468 You are forbidden to forbid anyone else to use, share and improve
469 what you give them. Help stamp out software-hoarding! */
471 /* This is the parser code that is written into each bison parser
472 when the %semantic_parser declaration is not specified in the grammar.
473 It was written by Richard Stallman by simplifying the hairy parser
474 used when %semantic_parser is specified. */
476 /* Note: there must be only one dollar sign in this file.
477 It is replaced by the list of actions, each action
478 as one case of the switch. */
480 #define yyerrok (yyerrstatus = 0)
481 #define yyclearin (yychar = YYEMPTY)
484 #define YYFAIL goto yyerrlab;
489 #define YYLEX yylex()
493 #define YYLEX yylex(&yylval, &yylloc)
496 /* If nonreentrant, generate the variables here */
500 int yychar
; /* the lookahead symbol */
501 YYSTYPE yylval
; /* the semantic value of the */
502 /* lookahead symbol */
504 YYLTYPE yylloc
; /* location data for the lookahead */
507 int yydebug
= 0; /* nonzero means print parse trace */
509 #endif /* YYIMPURE */
512 /* YYMAXDEPTH indicates the initial size of the parser's stacks */
515 #define YYMAXDEPTH 200
518 /* YYMAXLIMIT is the maximum size the stacks can grow to
519 (effective only if the built-in stack extension method is used). */
522 #define YYMAXLIMIT 10000
526 #line 87 "bison.simple"
530 register int yystate
;
532 register short *yyssp
;
533 register YYSTYPE
*yyvsp
;
535 int yyerrstatus
; /* number of tokens to shift before error messages enabled */
536 int yychar1
; /* lookahead token as an internal (translated) token number */
538 short yyssa
[YYMAXDEPTH
]; /* the state stack */
539 YYSTYPE yyvsa
[YYMAXDEPTH
]; /* the semantic value stack */
540 YYLTYPE yylsa
[YYMAXDEPTH
]; /* the location stack */
542 short *yyss
= yyssa
; /* refer to the stacks thru separate pointers */
543 YYSTYPE
*yyvs
= yyvsa
; /* to allow yyoverflow to reallocate them elsewhere */
544 YYLTYPE
*yyls
= yylsa
;
546 int yymaxdepth
= YYMAXDEPTH
;
559 YYSTYPE yyval
; /* the variable used to return */
560 /* semantic values from the action */
566 fprintf(stderr
, "Starting parse\n");
570 yychar
= YYEMPTY
; /* Cause a token to be read. */
572 /* Initialize stack pointers.
573 Waste one element of value and location stack
574 so that they stay on the same level as the state stack. */
580 /* Push a new state, which is found in yystate . */
581 /* In all cases, when you get here, the value and location stacks
582 have just been pushed. so pushing a state here evens the stacks. */
587 if (yyssp
>= yyss
+ yymaxdepth
- 1)
589 /* Give user a chance to reallocate the stack */
590 /* Use copies of these so that the &'s don't force the real ones into memory. */
591 YYSTYPE
*yyvs1
= yyvs
;
592 YYLTYPE
*yyls1
= yyls
;
595 /* Get the current used size of the three stacks, in elements. */
596 int size
= yyssp
- yyss
+ 1;
599 /* Each stack pointer address is followed by the size of
600 the data in use in that stack, in bytes. */
601 yyoverflow("parser stack overflow",
602 &yyss1
, size
* sizeof (*yyssp
),
603 &yyvs1
, size
* sizeof (*yyvsp
),
604 &yyls1
, size
* sizeof (*yylsp
),
607 yyss
= yyss1
; yyvs
= yyvs1
; yyls
= yyls1
;
608 #else /* no yyoverflow */
609 /* Extend the stack our own way. */
610 if (yymaxdepth
>= YYMAXLIMIT
)
611 yyerror("parser stack overflow");
613 if (yymaxdepth
> YYMAXLIMIT
)
614 yymaxdepth
= YYMAXLIMIT
;
615 yyss
= (short *) alloca (yymaxdepth
* sizeof (*yyssp
));
616 bcopy ((char *)yyss1
, (char *)yyss
, size
* sizeof (*yyssp
));
617 yyls
= (YYLTYPE
*) alloca (yymaxdepth
* sizeof (*yylsp
));
618 bcopy ((char *)yyls1
, (char *)yyls
, size
* sizeof (*yylsp
));
619 yyvs
= (YYSTYPE
*) alloca (yymaxdepth
* sizeof (*yyvsp
));
620 bcopy ((char *)yyvs1
, (char *)yyvs
, size
* sizeof (*yyvsp
));
621 #endif /* no yyoverflow */
623 yyssp
= yyss
+ size
- 1;
624 yylsp
= yyls
+ size
- 1;
625 yyvsp
= yyvs
+ size
- 1;
628 fprintf(stderr
, "Stack size increased to %d\n", yymaxdepth
);
630 if (yyssp
>= yyss
+ yymaxdepth
- 1)
635 fprintf(stderr
, "Entering state %d\n", yystate
);
637 /* Do appropriate processing given the current state. */
638 /* Read a lookahead token if we need one and don't already have one. */
641 /* First try to decide what to do without reference to lookahead token. */
643 yyn
= yypact
[yystate
];
647 /* Not known => get a lookahead token if don't already have one. */
649 /* yychar is either YYEMPTY or YYEOF
650 or a valid token in external form. */
652 if (yychar
== YYEMPTY
)
657 /* Convert token to internal form (in yychar1) for indexing tables with */
659 if (yychar
<= 0) /* This means end of input. */
662 yychar
= YYEOF
; /* Don't call YYLEX any more */
665 fprintf(stderr
, "Now at end of input.\n");
669 yychar1
= YYTRANSLATE(yychar
);
672 fprintf(stderr
, "Parsing next token; it is %d (%s)\n", yychar
, yytname
[yychar1
]);
676 if (yyn
< 0 || yyn
> YYLAST
|| yycheck
[yyn
] != yychar1
)
681 /* yyn is what to do for this token type in this state.
682 Negative => reduce, -yyn is rule number.
683 Positive => shift, yyn is new state.
684 New state is final state => don't bother to shift,
686 0, or most negative number => error. */
701 /* Shift the lookahead token. */
704 fprintf(stderr
, "Shifting token %d (%s), ", yychar
, yytname
[yychar1
]);
706 /* Discard the token being shifted unless it is eof. */
713 /* count tokens shifted since error; after three, turn off error status. */
714 if (yyerrstatus
) yyerrstatus
--;
719 /* Do the default action for the current state. */
722 yyn
= yydefact
[yystate
];
726 /* Do a reduction. yyn is the number of a rule to reduce with. */
729 yyval
= yyvsp
[1-yylen
]; /* implement default value of the action */
734 fprintf (stderr
, "Reducing 1 value via line %d, ",
737 fprintf (stderr
, "Reducing %d values via line %d, ",
738 yylen
, yyrline
[yyn
]);
745 #line 158 "expread.y"
746 { write_exp_elt (BINOP_COMMA
); ;
749 #line 163 "expread.y"
750 { write_exp_elt (UNOP_IND
); ;
753 #line 166 "expread.y"
754 { write_exp_elt (UNOP_ADDR
); ;
757 #line 169 "expread.y"
758 { write_exp_elt (UNOP_NEG
); ;
761 #line 173 "expread.y"
762 { write_exp_elt (UNOP_ZEROP
); ;
765 #line 177 "expread.y"
766 { write_exp_elt (UNOP_LOGNOT
); ;
769 #line 181 "expread.y"
770 { write_exp_elt (UNOP_PREINCREMENT
); ;
773 #line 185 "expread.y"
774 { write_exp_elt (UNOP_PREDECREMENT
); ;
777 #line 189 "expread.y"
778 { write_exp_elt (UNOP_POSTINCREMENT
); ;
781 #line 193 "expread.y"
782 { write_exp_elt (UNOP_POSTDECREMENT
); ;
785 #line 197 "expread.y"
786 { write_exp_elt (UNOP_SIZEOF
); ;
789 #line 201 "expread.y"
790 { write_exp_elt (STRUCTOP_PTR
);
791 write_exp_string (yyvsp
[0].sval
);
792 write_exp_elt (STRUCTOP_PTR
); ;
795 #line 207 "expread.y"
796 { write_exp_elt (STRUCTOP_MPTR
); ;
799 #line 211 "expread.y"
800 { write_exp_elt (STRUCTOP_STRUCT
);
801 write_exp_string (yyvsp
[0].sval
);
802 write_exp_elt (STRUCTOP_STRUCT
); ;
805 #line 217 "expread.y"
806 { write_exp_elt (STRUCTOP_MEMBER
); ;
809 #line 221 "expread.y"
810 { write_exp_elt (BINOP_SUBSCRIPT
); ;
813 #line 227 "expread.y"
814 { start_arglist (); ;
817 #line 229 "expread.y"
818 { write_exp_elt (OP_FUNCALL
);
819 write_exp_elt (end_arglist ());
820 write_exp_elt (OP_FUNCALL
); ;
823 #line 238 "expread.y"
827 #line 242 "expread.y"
831 #line 246 "expread.y"
832 { write_exp_elt (UNOP_MEMVAL
);
833 write_exp_elt (yyvsp
[-2].tval
);
834 write_exp_elt (UNOP_MEMVAL
); ;
837 #line 252 "expread.y"
838 { write_exp_elt (UNOP_CAST
);
839 write_exp_elt (yyvsp
[-2].tval
);
840 write_exp_elt (UNOP_CAST
); ;
843 #line 258 "expread.y"
847 #line 264 "expread.y"
848 { write_exp_elt (BINOP_REPEAT
); ;
851 #line 268 "expread.y"
852 { write_exp_elt (BINOP_MUL
); ;
855 #line 272 "expread.y"
856 { write_exp_elt (BINOP_DIV
); ;
859 #line 276 "expread.y"
860 { write_exp_elt (BINOP_REM
); ;
863 #line 280 "expread.y"
864 { write_exp_elt (BINOP_ADD
); ;
867 #line 284 "expread.y"
868 { write_exp_elt (BINOP_SUB
); ;
871 #line 288 "expread.y"
872 { write_exp_elt (BINOP_LSH
); ;
875 #line 292 "expread.y"
876 { write_exp_elt (BINOP_RSH
); ;
879 #line 296 "expread.y"
880 { write_exp_elt (BINOP_EQUAL
); ;
883 #line 300 "expread.y"
884 { write_exp_elt (BINOP_NOTEQUAL
); ;
887 #line 304 "expread.y"
888 { write_exp_elt (BINOP_LEQ
); ;
891 #line 308 "expread.y"
892 { write_exp_elt (BINOP_GEQ
); ;
895 #line 312 "expread.y"
896 { write_exp_elt (BINOP_LESS
); ;
899 #line 316 "expread.y"
900 { write_exp_elt (BINOP_GTR
); ;
903 #line 320 "expread.y"
904 { write_exp_elt (BINOP_LOGAND
); ;
907 #line 324 "expread.y"
908 { write_exp_elt (BINOP_LOGXOR
); ;
911 #line 328 "expread.y"
912 { write_exp_elt (BINOP_LOGIOR
); ;
915 #line 332 "expread.y"
916 { write_exp_elt (BINOP_AND
); ;
919 #line 336 "expread.y"
920 { write_exp_elt (BINOP_OR
); ;
923 #line 340 "expread.y"
924 { write_exp_elt (TERNOP_COND
); ;
927 #line 344 "expread.y"
928 { write_exp_elt (BINOP_ASSIGN
); ;
931 #line 348 "expread.y"
932 { write_exp_elt (BINOP_ASSIGN_MODIFY
);
933 write_exp_elt (yyvsp
[-1].opcode
);
934 write_exp_elt (BINOP_ASSIGN_MODIFY
); ;
937 #line 354 "expread.y"
938 { write_exp_elt (OP_LONG
);
939 write_exp_elt (builtin_type_long
);
940 write_exp_elt (yyvsp
[0].lval
);
941 write_exp_elt (OP_LONG
); ;
944 #line 361 "expread.y"
945 { write_exp_elt (OP_LONG
);
946 write_exp_elt (builtin_type_char
);
947 write_exp_elt (yyvsp
[0].lval
);
948 write_exp_elt (OP_LONG
); ;
951 #line 368 "expread.y"
952 { write_exp_elt (OP_DOUBLE
);
953 write_exp_elt (builtin_type_double
);
954 write_exp_elt (yyvsp
[0].dval
);
955 write_exp_elt (OP_DOUBLE
); ;
958 #line 378 "expread.y"
959 { write_exp_elt (OP_LAST
);
960 write_exp_elt (yyvsp
[0].lval
);
961 write_exp_elt (OP_LAST
); ;
964 #line 384 "expread.y"
965 { write_exp_elt (OP_REGISTER
);
966 write_exp_elt (yyvsp
[0].lval
);
967 write_exp_elt (OP_REGISTER
); ;
970 #line 390 "expread.y"
971 { write_exp_elt (OP_INTERNALVAR
);
972 write_exp_elt (yyvsp
[0].ivar
);
973 write_exp_elt (OP_INTERNALVAR
); ;
976 #line 396 "expread.y"
977 { write_exp_elt (OP_LONG
);
978 write_exp_elt (builtin_type_int
);
979 write_exp_elt ((long) TYPE_LENGTH (yyvsp
[-1].tval
));
980 write_exp_elt (OP_LONG
); ;
983 #line 403 "expread.y"
984 { write_exp_elt (OP_STRING
);
985 write_exp_string (yyvsp
[0].sval
);
986 write_exp_elt (OP_STRING
); ;
989 #line 410 "expread.y"
990 { write_exp_elt (OP_THIS
);
991 write_exp_elt (OP_THIS
); ;
994 #line 417 "expread.y"
996 struct symtab
*tem
= lookup_symtab (copy_name (yyvsp
[0].sval
));
1000 yyval
.bval
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (tem
), 1);
1003 sym
= lookup_symbol (copy_name (yyvsp
[0].sval
),
1004 expression_context_block
,
1006 if (sym
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1007 yyval
.bval
= SYMBOL_BLOCK_VALUE (sym
);
1009 error ("No file or function \"%s\".",
1010 copy_name (yyvsp
[0].sval
));
1015 #line 438 "expread.y"
1018 = lookup_symbol (copy_name (yyvsp
[0].sval
), yyvsp
[-2].bval
, VAR_NAMESPACE
);
1019 if (!tem
|| SYMBOL_CLASS (tem
) != LOC_BLOCK
)
1020 error ("No function \"%s\" in specified context.",
1021 copy_name (yyvsp
[-2].bval
));
1022 yyval
.bval
= SYMBOL_BLOCK_VALUE (tem
);
1026 #line 449 "expread.y"
1029 sym
= lookup_symbol (copy_name (yyvsp
[0].sval
), yyvsp
[-2].bval
, VAR_NAMESPACE
);
1031 error ("No symbol \"%s\" in specified context.",
1032 copy_name (yyvsp
[0].sval
));
1033 write_exp_elt (OP_VAR_VALUE
);
1034 write_exp_elt (sym
);
1035 write_exp_elt (OP_VAR_VALUE
);
1039 #line 462 "expread.y"
1041 struct type
*type
= yyvsp
[-2].tval
;
1042 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
1043 && TYPE_CODE (type
) != TYPE_CODE_UNION
)
1044 error ("`%s' is not defined as an aggregate type.",
1047 write_exp_elt (OP_SCOPE
);
1048 write_exp_elt (type
);
1049 write_exp_string (yyvsp
[0].sval
);
1050 write_exp_elt (OP_SCOPE
);
1054 #line 475 "expread.y"
1056 char *name
= copy_name (yyvsp
[0].sval
);
1060 sym
= lookup_symbol_2 (name
, 0, VAR_NAMESPACE
);
1063 write_exp_elt (OP_VAR_VALUE
);
1064 write_exp_elt (sym
);
1065 write_exp_elt (OP_VAR_VALUE
);
1068 for (i
= 0; i
< misc_function_count
; i
++)
1069 if (!strcmp (misc_function_vector
[i
].name
, name
))
1072 if (i
< misc_function_count
)
1074 write_exp_elt (OP_LONG
);
1075 write_exp_elt (builtin_type_int
);
1076 write_exp_elt (misc_function_vector
[i
].address
);
1077 write_exp_elt (OP_LONG
);
1078 write_exp_elt (UNOP_MEMVAL
);
1079 write_exp_elt (builtin_type_char
);
1080 write_exp_elt (UNOP_MEMVAL
);
1083 if (symtab_list
== 0)
1084 error ("No symbol table is loaded. Use the \"symbol-file\" command.");
1086 error ("No symbol \"%s\" in current context.", name
);
1090 #line 511 "expread.y"
1091 { struct symbol
*sym
;
1092 sym
= lookup_symbol_1 (copy_name (yyvsp
[0].sval
),
1093 expression_context_block
,
1097 write_exp_elt (OP_VAR_VALUE
);
1098 write_exp_elt (sym
);
1099 write_exp_elt (OP_VAR_VALUE
);
1103 register char *arg
= copy_name (yyvsp
[0].sval
);
1106 /* C++: see if it hangs off of `this'. Must
1107 not inadvertently convert from a method call
1109 v
= (int)value_of_this (0);
1112 val
= check_field (v
, arg
);
1115 write_exp_elt (OP_THIS
);
1116 write_exp_elt (OP_THIS
);
1117 write_exp_elt (STRUCTOP_PTR
);
1118 write_exp_string (yyvsp
[0].sval
);
1119 write_exp_elt (STRUCTOP_PTR
);
1123 sym
= lookup_symbol_2 (arg
, 0, VAR_NAMESPACE
);
1126 write_exp_elt (OP_VAR_VALUE
);
1127 write_exp_elt (sym
);
1128 write_exp_elt (OP_VAR_VALUE
);
1129 break; /* YACC-dependent */
1131 for (i
= 0; i
< misc_function_count
; i
++)
1132 if (!strcmp (misc_function_vector
[i
].name
, arg
))
1135 if (i
< misc_function_count
)
1137 write_exp_elt (OP_LONG
);
1138 write_exp_elt (builtin_type_int
);
1139 write_exp_elt (misc_function_vector
[i
].address
);
1140 write_exp_elt (OP_LONG
);
1141 write_exp_elt (UNOP_MEMVAL
);
1142 write_exp_elt (builtin_type_char
);
1143 write_exp_elt (UNOP_MEMVAL
);
1146 if (symtab_list
== 0)
1147 error ("No symbol table is loaded. Use the \"symbol-file\" command.");
1149 error ("No symbol \"%s\" in current context.",
1150 copy_name (yyvsp
[0].sval
));
1155 #line 577 "expread.y"
1156 { yyval
.tval
= lookup_pointer_type (yyvsp
[-1].tval
); ;
1159 #line 579 "expread.y"
1160 { yyval
.tval
= lookup_reference_type (yyvsp
[-1].tval
); ;
1163 #line 581 "expread.y"
1164 { yyval
.tval
= lookup_member_pointer_type (builtin_type_int
, yyvsp
[-2].tval
); ;
1167 #line 583 "expread.y"
1168 { yyval
.tval
= lookup_member_pointer_type (yyvsp
[-5].tval
, yyvsp
[-3].tval
); ;
1171 #line 585 "expread.y"
1172 { yyval
.tval
= lookup_member_pointer_type (lookup_function_type (yyvsp
[-7].tval
, 0), yyvsp
[-5].tval
); ;
1175 #line 587 "expread.y"
1176 { yyval
.tval
= lookup_member_pointer_type (lookup_function_type (yyvsp
[-8].tval
, yyvsp
[-1].tvec
), yyvsp
[-6].tval
);
1177 free (yyvsp
[-1].tvec
); ;
1180 #line 593 "expread.y"
1181 { yyval
.tval
= lookup_typename (copy_name (yyvsp
[0].sval
),
1182 expression_context_block
, 0); ;
1185 #line 596 "expread.y"
1186 { yyval
.tval
= lookup_struct (copy_name (yyvsp
[0].sval
),
1187 expression_context_block
); ;
1190 #line 599 "expread.y"
1191 { yyval
.tval
= lookup_union (copy_name (yyvsp
[0].sval
),
1192 expression_context_block
); ;
1195 #line 602 "expread.y"
1196 { yyval
.tval
= lookup_enum (copy_name (yyvsp
[0].sval
),
1197 expression_context_block
); ;
1200 #line 605 "expread.y"
1201 { yyval
.tval
= lookup_unsigned_typename (copy_name (yyvsp
[0].sval
)); ;
1204 #line 610 "expread.y"
1205 { yyval
.tvec
= (struct type
**)xmalloc (sizeof (struct type
*) * 2);
1206 yyval
.tvec
[0] = (struct type
*)0;
1207 yyval
.tvec
[1] = yyvsp
[0].tval
;
1211 #line 615 "expread.y"
1212 { int len
= sizeof (struct type
*) * ++(yyvsp
[-2].ivec
[0]);
1213 yyval
.tvec
= (struct type
**)xrealloc (yyvsp
[-2].tvec
, len
);
1214 yyval
.tvec
[yyval
.ivec
[0]] = yyvsp
[0].tval
;
1218 /* the action file gets copied in in place of this dollarsign */
1219 #line 303 "bison.simple"
1227 short *ssp1
= yyss
- 1;
1228 fprintf (stderr
, "state stack now", yyssp
-yyss
);
1229 while (ssp1
!= yyssp
)
1230 fprintf (stderr
, " %d", *++ssp1
);
1231 fprintf (stderr
, "\n");
1239 yylsp
->first_line
= yylloc
.first_line
;
1240 yylsp
->first_column
= yylloc
.first_column
;
1241 yylsp
->last_line
= (yylsp
-1)->last_line
;
1242 yylsp
->last_column
= (yylsp
-1)->last_column
;
1247 yylsp
->last_line
= (yylsp
+yylen
-1)->last_line
;
1248 yylsp
->last_column
= (yylsp
+yylen
-1)->last_column
;
1251 /* Now "shift" the result of the reduction.
1252 Determine what state that goes to,
1253 based on the state we popped back to
1254 and the rule number reduced by. */
1258 yystate
= yypgoto
[yyn
- YYNTBASE
] + *yyssp
;
1259 if (yystate
>= 0 && yystate
<= YYLAST
&& yycheck
[yystate
] == *yyssp
)
1260 yystate
= yytable
[yystate
];
1262 yystate
= yydefgoto
[yyn
- YYNTBASE
];
1266 yyerrlab
: /* here on detecting error */
1269 /* If not already recovering from an error, report this error. */
1272 db_yyerror("parse error", yyssp
, yychar
);
1274 yyerror("parse error");
1278 if (yyerrstatus
== 3)
1280 /* if just tried and failed to reuse lookahead token after an error, discard it. */
1282 /* return failure if at end of input */
1283 if (yychar
== YYEOF
)
1287 fprintf(stderr
, "Discarding token %d (%s).\n", yychar
, yytname
[yychar1
]);
1292 /* Else will try to reuse lookahead token
1293 after shifting the error token. */
1295 yyerrstatus
= 3; /* Each real token shifted decrements this */
1299 yyerrdefault
: /* current state does not do anything special for the error token. */
1302 /* This is wrong; only states that explicitly want error tokens
1303 should shift them. */
1304 yyn
= yydefact
[yystate
]; /* If its default is to accept any token, ok. Otherwise pop it.*/
1305 if (yyn
) goto yydefault
;
1308 yyerrpop
: /* pop the current state because it cannot handle the error token */
1310 if (yyssp
== yyss
) YYERROR
;
1317 short *ssp1
= yyss
- 1;
1318 fprintf (stderr
, "Error: state stack now", yyssp
-yyss
);
1319 while (ssp1
!= yyssp
)
1320 fprintf (stderr
, " %d", *++ssp1
);
1321 fprintf (stderr
, "\n");
1326 yyn
= yypact
[yystate
];
1331 if (yyn
< 0 || yyn
> YYLAST
|| yycheck
[yyn
] != YYTERROR
)
1349 fprintf(stderr
, "Shifting error token, ");
1357 #line 624 "expread.y"
1360 /* Begin counting arguments for a function call,
1361 saving the data about any containing call. */
1366 register struct funcall
*new = (struct funcall
*) xmalloc (sizeof (struct funcall
));
1368 new->next
= funcall_chain
;
1369 new->arglist_len
= arglist_len
;
1371 funcall_chain
= new;
1374 /* Return the number of arguments in a function call just terminated,
1375 and restore the data for the containing function call. */
1380 register int val
= arglist_len
;
1381 register struct funcall
*call
= funcall_chain
;
1382 funcall_chain
= call
->next
;
1383 arglist_len
= call
->arglist_len
;
1388 /* Free everything in the funcall chain.
1389 Used when there is an error inside parsing. */
1394 register struct funcall
*call
, *next
;
1396 for (call
= funcall_chain
; call
; call
= next
)
1403 /* This page contains the functions for adding data to the struct expression
1404 being constructed. */
1406 /* Add one element to the end of the expression. */
1409 write_exp_elt (expelt
)
1410 union exp_element expelt
;
1412 if (expout_ptr
>= expout_size
)
1415 expout
= (struct expression
*) xrealloc (expout
,
1416 sizeof (struct expression
)
1417 + expout_size
* sizeof (union exp_element
));
1419 expout
->elts
[expout_ptr
++] = expelt
;
1422 /* Add a string constant to the end of the expression.
1423 Follow it by its length in bytes, as a separate exp_element. */
1426 write_exp_string (str
)
1429 register int len
= str
.length
;
1431 = (len
+ sizeof (union exp_element
)) / sizeof (union exp_element
);
1433 expout_ptr
+= lenelt
;
1435 if (expout_ptr
>= expout_size
)
1437 expout_size
= max (expout_size
* 2, expout_ptr
+ 10);
1438 expout
= (struct expression
*) xrealloc (expout
,
1439 sizeof (struct expression
)
1440 + expout_size
* sizeof (union exp_element
));
1442 bcopy (str
.ptr
, (char *) &expout
->elts
[expout_ptr
- lenelt
], len
);
1443 ((char *) &expout
->elts
[expout_ptr
- lenelt
])[len
] = 0;
1444 write_exp_elt (len
);
1447 /* During parsing of a C expression, the pointer to the next character
1448 is in this variable. */
1450 static char *lexptr
;
1452 /* Tokens that refer to names do so with explicit pointer and length,
1453 so they can share the storage that lexptr is parsing.
1455 When it is necessary to pass a name to a function that expects
1456 a null-terminated string, the substring is copied out
1457 into a block of storage that namecopy points to.
1459 namecopy is allocated once, guaranteed big enough, for each parsing. */
1461 static char *namecopy
;
1463 /* Current depth in parentheses within the expression. */
1465 static int paren_depth
;
1467 /* Nonzero means stop parsing on first comma (if not within parentheses). */
1469 static int comma_terminates
;
1471 /* Take care of parsing a number (anything that starts with a digit).
1472 Set yylval and return the token type; update lexptr.
1473 LEN is the number of characters in it. */
1475 /*** Needs some error checking for the float case ***/
1481 register char *p
= lexptr
;
1482 register long n
= 0;
1484 register int base
= 10;
1485 register int len
= olen
;
1488 extern double atof ();
1490 for (c
= 0; c
< len
; c
++)
1493 /* It's a float since it contains a point. */
1494 yylval
.dval
= atof (p
);
1499 if (len
>= 3 && (!strncmp (p
, "0x", 2) || !strncmp (p
, "0X", 2)))
1512 if (c
>= '0' && c
<= '9')
1516 if (c
>= 'A' && c
<= 'Z') c
+= 'a' - 'A';
1517 if (base
== 16 && c
>= 'a' && c
<= 'f')
1519 else if (len
== 0 && c
== 'l')
1523 err_copy
= (char *) alloca (olen
+ 1);
1524 bcopy (lexptr
, err_copy
, olen
);
1526 error ("Invalid number \"%s\".", err_copy
);
1540 enum exp_opcode opcode
;
1543 static struct token tokentab3
[] =
1545 {">>=", ASSIGN_MODIFY
, BINOP_RSH
},
1546 {"<<=", ASSIGN_MODIFY
, BINOP_LSH
}
1549 static struct token tokentab2
[] =
1551 {"+=", ASSIGN_MODIFY
, BINOP_ADD
},
1552 {"-=", ASSIGN_MODIFY
, BINOP_SUB
},
1553 {"*=", ASSIGN_MODIFY
, BINOP_MUL
},
1554 {"/=", ASSIGN_MODIFY
, BINOP_DIV
},
1555 {"%=", ASSIGN_MODIFY
, BINOP_REM
},
1556 {"|=", ASSIGN_MODIFY
, BINOP_LOGIOR
},
1557 {"&=", ASSIGN_MODIFY
, BINOP_LOGAND
},
1558 {"^=", ASSIGN_MODIFY
, BINOP_LOGXOR
},
1559 {"++", INCREMENT
, BINOP_END
},
1560 {"--", DECREMENT
, BINOP_END
},
1561 {"->", ARROW
, BINOP_END
},
1562 {"&&", AND
, BINOP_END
},
1563 {"||", OR
, BINOP_END
},
1564 {"::", COLONCOLON
, BINOP_END
},
1565 {"<<", LSH
, BINOP_END
},
1566 {">>", RSH
, BINOP_END
},
1567 {"==", EQUAL
, BINOP_END
},
1568 {"!=", NOTEQUAL
, BINOP_END
},
1569 {"<=", LEQ
, BINOP_END
},
1570 {">=", GEQ
, BINOP_END
}
1573 /* Read one token, getting characters through lexptr. */
1579 register int namelen
;
1581 register char *tokstart
;
1586 /* See if it is a special token of length 3. */
1587 for (i
= 0; i
< sizeof tokentab3
/ sizeof tokentab3
[0]; i
++)
1588 if (!strncmp (tokstart
, tokentab3
[i
].operator, 3))
1591 yylval
.opcode
= tokentab3
[i
].opcode
;
1592 return tokentab3
[i
].token
;
1595 /* See if it is a special token of length 2. */
1596 for (i
= 0; i
< sizeof tokentab2
/ sizeof tokentab2
[0]; i
++)
1597 if (!strncmp (tokstart
, tokentab2
[i
].operator, 2))
1600 yylval
.opcode
= tokentab2
[i
].opcode
;
1601 return tokentab2
[i
].token
;
1604 switch (c
= *tokstart
)
1619 c
= parse_escape (&lexptr
);
1623 error ("Invalid character constant.");
1632 if (paren_depth
== 0)
1639 if (comma_terminates
&& paren_depth
== 0)
1669 for (namelen
= 1; (c
= tokstart
[namelen
]) != '"'; namelen
++)
1672 c
= tokstart
[++namelen
];
1673 if (c
>= '0' && c
<= '9')
1675 c
= tokstart
[++namelen
];
1676 if (c
>= '0' && c
<= '9')
1677 c
= tokstart
[++namelen
];
1680 yylval
.sval
.ptr
= tokstart
+ 1;
1681 yylval
.sval
.length
= namelen
- 1;
1682 lexptr
+= namelen
+ 1;
1685 if (c
>= '0' && c
<= '9')
1689 c
= tokstart
[namelen
],
1690 (c
== '_' || c
== '$' || c
== '.' || (c
>= '0' && c
<= '9')
1691 || (c
>= 'a' && c
<= 'z') || (c
>= 'A' && c
<= 'Z'));
1694 return parse_number (namelen
);
1697 if (!(c
== '_' || c
== '$'
1698 || (c
>= 'a' && c
<= 'z') || (c
>= 'A' && c
<= 'Z')))
1699 error ("Invalid token in expression.");
1701 /* It is a name. See how long it is. */
1704 c
= tokstart
[namelen
],
1705 (c
== '_' || c
== '$' || (c
>= '0' && c
<= '9')
1706 || (c
>= 'a' && c
<= 'z') || (c
>= 'A' && c
<= 'Z'));
1710 /* The token "if" terminates the expression and is NOT
1711 removed from the input stream. */
1712 if (namelen
== 2 && tokstart
[0] == 'i' && tokstart
[1] == 'f')
1719 /* Handle the tokens $digits; also $ (short for $0) and $$ (short for $$1)
1720 and $$digits (equivalent to $<-digits> if you could type that).
1721 Make token type LAST, and put the number (the digits) in yylval. */
1723 if (*tokstart
== '$')
1725 register int negate
= 0;
1727 /* Double dollar means negate the number and add -1 as well.
1728 Thus $$ alone means -1. */
1729 if (namelen
>= 2 && tokstart
[1] == '$')
1736 /* Just dollars (one or two) */
1737 yylval
.lval
= - negate
;
1740 /* Is the rest of the token digits? */
1741 for (; c
< namelen
; c
++)
1742 if (!(tokstart
[c
] >= '0' && tokstart
[c
] <= '9'))
1746 yylval
.lval
= atoi (tokstart
+ 1 + negate
);
1748 yylval
.lval
= - yylval
.lval
;
1753 /* Handle tokens that refer to machine registers:
1754 $ followed by a register name. */
1756 if (*tokstart
== '$')
1757 for (c
= 0; c
< NUM_REGS
; c
++)
1758 if (namelen
- 1 == strlen (reg_names
[c
])
1759 && !strncmp (tokstart
+ 1, reg_names
[c
], namelen
- 1))
1765 if (namelen
== 6 && !strncmp (tokstart
, "struct", 6))
1771 if (!strncmp (tokstart
, "union", 5))
1778 if (!strncmp (tokstart
, "enum", 4))
1782 if (!strncmp (tokstart
, "this", 4))
1787 if (namelen
== 6 && !strncmp (tokstart
, "sizeof", 6))
1791 if (namelen
== 8 && !strncmp (tokstart
, "unsigned", 6))
1795 yylval
.sval
.ptr
= tokstart
;
1796 yylval
.sval
.length
= namelen
;
1798 /* Any other names starting in $ are debugger internal variables. */
1800 if (*tokstart
== '$')
1802 yylval
.ivar
= (struct internalvar
*) lookup_internalvar (copy_name (yylval
.sval
) + 1);
1806 /* Use token-type TYPENAME for symbols that happen to be defined
1807 currently as names of types; NAME for other symbols.
1808 The caller is not constrained to care about the distinction. */
1809 if (lookup_typename (copy_name (yylval
.sval
), expression_context_block
, 1))
1817 error ("Invalid syntax in expression.");
1820 /* Return a null-terminated temporary copy of the name
1821 of a string token. */
1825 struct stoken token
;
1827 bcopy (token
.ptr
, namecopy
, token
.length
);
1828 namecopy
[token
.length
] = 0;
1832 /* Reverse an expression from suffix form (in which it is constructed)
1833 to prefix form (in which we can conveniently print or execute it). */
1835 static void prefixify_subexp ();
1838 prefixify_expression (expr
)
1839 register struct expression
*expr
;
1841 register int len
= sizeof (struct expression
) +
1842 expr
->nelts
* sizeof (union exp_element
);
1843 register struct expression
*temp
;
1844 register int inpos
= expr
->nelts
, outpos
= 0;
1846 temp
= (struct expression
*) alloca (len
);
1848 /* Copy the original expression into temp. */
1849 bcopy (expr
, temp
, len
);
1851 prefixify_subexp (temp
, expr
, inpos
, outpos
);
1854 /* Return the number of exp_elements in the subexpression of EXPR
1855 whose last exp_element is at index ENDPOS - 1 in EXPR. */
1858 length_of_subexp (expr
, endpos
)
1859 register struct expression
*expr
;
1860 register int endpos
;
1862 register int oplen
= 1;
1863 register int args
= 0;
1867 error ("?error in length_of_subexp");
1869 i
= (int) expr
->elts
[endpos
- 1].opcode
;
1875 oplen
= 4 + ((expr
->elts
[endpos
- 2].longconst
1876 + sizeof (union exp_element
))
1877 / sizeof (union exp_element
));
1888 case OP_INTERNALVAR
:
1894 args
= 1 + expr
->elts
[endpos
- 2].longconst
;
1903 case STRUCTOP_STRUCT
:
1907 oplen
= 3 + ((expr
->elts
[endpos
- 2].longconst
1908 + sizeof (union exp_element
))
1909 / sizeof (union exp_element
));
1916 case BINOP_ASSIGN_MODIFY
:
1927 args
= 1 + (i
< (int) BINOP_END
);
1932 oplen
+= length_of_subexp (expr
, endpos
- oplen
);
1939 /* Copy the subexpression ending just before index INEND in INEXPR
1940 into OUTEXPR, starting at index OUTBEG.
1941 In the process, convert it from suffix to prefix form. */
1944 prefixify_subexp (inexpr
, outexpr
, inend
, outbeg
)
1945 register struct expression
*inexpr
;
1946 struct expression
*outexpr
;
1950 register int oplen
= 1;
1951 register int args
= 0;
1954 enum exp_opcode opcode
;
1956 /* Compute how long the last operation is (in OPLEN),
1957 and also how many preceding subexpressions serve as
1958 arguments for it (in ARGS). */
1960 opcode
= inexpr
->elts
[inend
- 1].opcode
;
1965 oplen
= 4 + ((inexpr
->elts
[inend
- 2].longconst
1966 + sizeof (union exp_element
))
1967 / sizeof (union exp_element
));
1978 case OP_INTERNALVAR
:
1984 args
= 1 + inexpr
->elts
[inend
- 2].longconst
;
1993 case STRUCTOP_STRUCT
:
1997 oplen
= 3 + ((inexpr
->elts
[inend
- 2].longconst
1998 + sizeof (union exp_element
))
1999 / sizeof (union exp_element
));
2007 case BINOP_ASSIGN_MODIFY
:
2018 args
= 1 + ((int) opcode
< (int) BINOP_END
);
2021 /* Copy the final operator itself, from the end of the input
2022 to the beginning of the output. */
2024 bcopy (&inexpr
->elts
[inend
], &outexpr
->elts
[outbeg
],
2025 oplen
* sizeof (union exp_element
));
2028 /* Find the lengths of the arg subexpressions. */
2029 arglens
= (int *) alloca (args
* sizeof (int));
2030 for (i
= args
- 1; i
>= 0; i
--)
2032 oplen
= length_of_subexp (inexpr
, inend
);
2037 /* Now copy each subexpression, preserving the order of
2038 the subexpressions, but prefixifying each one.
2039 In this loop, inend starts at the beginning of
2040 the expression this level is working on
2041 and marches forward over the arguments.
2042 outbeg does similarly in the output. */
2043 for (i
= 0; i
< args
; i
++)
2047 prefixify_subexp (inexpr
, outexpr
, inend
, outbeg
);
2052 /* This page contains the two entry points to this file. */
2054 /* Read a C expression from the string *STRINGPTR points to,
2055 parse it, and return a pointer to a struct expression that we malloc.
2056 Use block BLOCK as the lexical context for variable names;
2057 if BLOCK is zero, use the block of the selected stack frame.
2058 Meanwhile, advance *STRINGPTR to point after the expression,
2059 at the first nonwhite character that is not part of the expression
2060 (possibly a null character).
2062 If COMMA is nonzero, stop if a comma is reached. */
2065 parse_c_1 (stringptr
, block
, comma
)
2067 struct block
*block
;
2069 struct cleanup
*old_chain
;
2071 lexptr
= *stringptr
;
2073 comma_terminates
= comma
;
2075 if (lexptr
== 0 || *lexptr
== 0)
2076 error_no_arg ("expression to compute");
2078 old_chain
= make_cleanup (free_funcalls
, 0);
2081 expression_context_block
= block
? block
: get_selected_block ();
2083 namecopy
= (char *) alloca (strlen (lexptr
) + 1);
2086 expout
= (struct expression
*) xmalloc (sizeof (struct expression
)
2087 + expout_size
* sizeof (union exp_element
));
2088 make_cleanup (free_current_contents
, &expout
);
2091 discard_cleanups (old_chain
);
2092 expout
->nelts
= expout_ptr
;
2093 expout
= (struct expression
*)
2095 sizeof (struct expression
)
2096 + expout_ptr
* sizeof (union exp_element
));
2097 prefixify_expression (expout
);
2098 *stringptr
= lexptr
;
2102 /* Parse STRING as an expression, and complain if this fails
2103 to use up all of the contents of STRING. */
2106 parse_c_expression (string
)
2109 register struct expression
*exp
;
2110 exp
= parse_c_1 (&string
, 0, 0);
2112 error ("Junk after end of expression.");
This page took 0.09851 seconds and 5 git commands to generate.