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 extensive
424 warranty protection to some or all 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 Mere aggregation of another unrelated program with this program (or its
431 derivative) on a volume of a storage or distribution medium does not bring
432 the other program under the scope of these terms.
434 3. You may copy and distribute this program (or a portion or derivative
435 of it, under Paragraph 2) in object code or executable form under the terms
436 of Paragraphs 1 and 2 above provided that you also do one of the following:
438 a) accompany it with the complete corresponding machine-readable
439 source code, which must be distributed under the terms of
440 Paragraphs 1 and 2 above; or,
442 b) accompany it with a written offer, valid for at least three
443 years, to give any third party free (except for a nominal
444 shipping charge) a complete machine-readable copy of the
445 corresponding source code, to be distributed under the terms of
446 Paragraphs 1 and 2 above; or,
448 c) accompany it with the information you received as to where the
449 corresponding source code may be obtained. (This alternative is
450 allowed only for noncommercial distribution and only if you
451 received the program in object code or executable form alone.)
453 For an executable file, complete source code means all the source code for
454 all modules it contains; but, as a special exception, it need not include
455 source code for modules which are standard libraries that accompany the
456 operating system on which the executable file runs.
458 4. You may not copy, sublicense, distribute or transfer this program
459 except as expressly provided under this License Agreement. Any attempt
460 otherwise to copy, sublicense, distribute or transfer this program is void and
461 your rights to use the program under this License agreement shall be
462 automatically terminated. However, parties who have received computer
463 software programs from you with this License Agreement will not have
464 their licenses terminated so long as such parties remain in full compliance.
466 5. If you wish to incorporate parts of this program into other free
467 programs whose distribution conditions are different, write to the Free
468 Software Foundation at 675 Mass Ave, Cambridge, MA 02139. We have not yet
469 worked out a simple rule that can be stated here, but we will often permit
470 this. We will be guided by the two goals of preserving the free status of
471 all derivatives of our free software and of promoting the sharing and reuse of
475 In other words, you are welcome to use, share and improve this program.
476 You are forbidden to forbid anyone else to use, share and improve
477 what you give them. Help stamp out software-hoarding! */
479 /* This is the parser code that is written into each bison parser
480 when the %semantic_parser declaration is not specified in the grammar.
481 It was written by Richard Stallman by simplifying the hairy parser
482 used when %semantic_parser is specified. */
484 /* Note: there must be only one dollar sign in this file.
485 It is replaced by the list of actions, each action
486 as one case of the switch. */
488 #define yyerrok (yyerrstatus = 0)
489 #define yyclearin (yychar = YYEMPTY)
492 #define YYFAIL goto yyerrlab;
497 #define YYLEX yylex()
501 #define YYLEX yylex(&yylval, &yylloc)
504 /* If nonreentrant, generate the variables here */
508 int yychar
; /* the lookahead symbol */
509 YYSTYPE yylval
; /* the semantic value of the */
510 /* lookahead symbol */
512 YYLTYPE yylloc
; /* location data for the lookahead */
515 int yynerr
; /* number of parse errors so far */
518 int yydebug
= 0; /* nonzero means print parse trace */
521 #endif /* YYIMPURE */
524 /* YYMAXDEPTH indicates the initial size of the parser's stacks */
527 #define YYMAXDEPTH 200
530 /* YYMAXLIMIT is the maximum size the stacks can grow to
531 (effective only if the built-in stack extension method is used). */
534 #define YYMAXLIMIT 10000
538 #line 165 "bison.simple"
542 register int yystate
;
544 register short *yyssp
;
545 register YYSTYPE
*yyvsp
;
547 int yyerrstatus
; /* number of tokens to shift before error messages enabled */
548 int yychar1
; /* lookahead token as an internal (translated) token number */
550 short yyssa
[YYMAXDEPTH
]; /* the state stack */
551 YYSTYPE yyvsa
[YYMAXDEPTH
]; /* the semantic value stack */
552 YYLTYPE yylsa
[YYMAXDEPTH
]; /* the location stack */
554 short *yyss
= yyssa
; /* refer to the stacks thru separate pointers */
555 YYSTYPE
*yyvs
= yyvsa
; /* to allow yyoverflow to reallocate them elsewhere */
556 YYLTYPE
*yyls
= yylsa
;
558 int yymaxdepth
= YYMAXDEPTH
;
573 YYSTYPE yyval
; /* the variable used to return */
574 /* semantic values from the action */
581 fprintf(stderr
, "Starting parse\n");
587 yychar
= YYEMPTY
; /* Cause a token to be read. */
589 /* Initialize stack pointers.
590 Waste one element of value and location stack
591 so that they stay on the same level as the state stack. */
597 /* Push a new state, which is found in yystate . */
598 /* In all cases, when you get here, the value and location stacks
599 have just been pushed. so pushing a state here evens the stacks. */
604 if (yyssp
>= yyss
+ yymaxdepth
- 1)
606 /* Give user a chance to reallocate the stack */
607 /* Use copies of these so that the &'s don't force the real ones into memory. */
608 YYSTYPE
*yyvs1
= yyvs
;
609 YYLTYPE
*yyls1
= yyls
;
612 /* Get the current used size of the three stacks, in elements. */
613 int size
= yyssp
- yyss
+ 1;
616 /* Each stack pointer address is followed by the size of
617 the data in use in that stack, in bytes. */
618 yyoverflow("parser stack overflow",
619 &yyss1
, size
* sizeof (*yyssp
),
620 &yyvs1
, size
* sizeof (*yyvsp
),
621 &yyls1
, size
* sizeof (*yylsp
),
624 yyss
= yyss1
; yyvs
= yyvs1
; yyls
= yyls1
;
625 #else /* no yyoverflow */
626 /* Extend the stack our own way. */
627 if (yymaxdepth
>= YYMAXLIMIT
)
628 yyerror("parser stack overflow");
630 if (yymaxdepth
> YYMAXLIMIT
)
631 yymaxdepth
= YYMAXLIMIT
;
632 yyss
= (short *) alloca (yymaxdepth
* sizeof (*yyssp
));
633 bcopy ((char *)yyss1
, (char *)yyss
, size
* sizeof (*yyssp
));
634 yyls
= (YYLTYPE
*) alloca (yymaxdepth
* sizeof (*yylsp
));
635 bcopy ((char *)yyls1
, (char *)yyls
, size
* sizeof (*yylsp
));
636 yyvs
= (YYSTYPE
*) alloca (yymaxdepth
* sizeof (*yyvsp
));
637 bcopy ((char *)yyvs1
, (char *)yyvs
, size
* sizeof (*yyvsp
));
638 #endif /* no yyoverflow */
640 yyssp
= yyss
+ size
- 1;
641 yylsp
= yyls
+ size
- 1;
642 yyvsp
= yyvs
+ size
- 1;
646 fprintf(stderr
, "Stack size increased to %d\n", yymaxdepth
);
649 if (yyssp
>= yyss
+ yymaxdepth
- 1)
655 fprintf(stderr
, "Entering state %d\n", yystate
);
658 /* Do appropriate processing given the current state. */
659 /* Read a lookahead token if we need one and don't already have one. */
662 /* First try to decide what to do without reference to lookahead token. */
664 yyn
= yypact
[yystate
];
668 /* Not known => get a lookahead token if don't already have one. */
670 /* yychar is either YYEMPTY or YYEOF
671 or a valid token in external form. */
673 if (yychar
== YYEMPTY
)
677 fprintf(stderr
, "Reading a token: ");
682 /* Convert token to internal form (in yychar1) for indexing tables with */
684 if (yychar
<= 0) /* This means end of input. */
687 yychar
= YYEOF
; /* Don't call YYLEX any more */
691 fprintf(stderr
, "Now at end of input.\n");
696 yychar1
= YYTRANSLATE(yychar
);
700 fprintf(stderr
, "Next token is %d (%s)\n", yychar
, yytname
[yychar1
]);
705 if (yyn
< 0 || yyn
> YYLAST
|| yycheck
[yyn
] != yychar1
)
710 /* yyn is what to do for this token type in this state.
711 Negative => reduce, -yyn is rule number.
712 Positive => shift, yyn is new state.
713 New state is final state => don't bother to shift,
715 0, or most negative number => error. */
730 /* Shift the lookahead token. */
734 fprintf(stderr
, "Shifting token %d (%s), ", yychar
, yytname
[yychar1
]);
737 /* Discard the token being shifted unless it is eof. */
744 /* count tokens shifted since error; after three, turn off error status. */
745 if (yyerrstatus
) yyerrstatus
--;
750 /* Do the default action for the current state. */
753 yyn
= yydefact
[yystate
];
757 /* Do a reduction. yyn is the number of a rule to reduce with. */
760 yyval
= yyvsp
[1-yylen
]; /* implement default value of the action */
766 fprintf (stderr
, "Reducing 1 value via line %d, ",
769 fprintf (stderr
, "Reducing %d values via line %d, ",
770 yylen
, yyrline
[yyn
]);
778 #line 158 "expread.y"
779 { write_exp_elt (BINOP_COMMA
); ;
782 #line 163 "expread.y"
783 { write_exp_elt (UNOP_IND
); ;
786 #line 166 "expread.y"
787 { write_exp_elt (UNOP_ADDR
); ;
790 #line 169 "expread.y"
791 { write_exp_elt (UNOP_NEG
); ;
794 #line 173 "expread.y"
795 { write_exp_elt (UNOP_ZEROP
); ;
798 #line 177 "expread.y"
799 { write_exp_elt (UNOP_LOGNOT
); ;
802 #line 181 "expread.y"
803 { write_exp_elt (UNOP_PREINCREMENT
); ;
806 #line 185 "expread.y"
807 { write_exp_elt (UNOP_PREDECREMENT
); ;
810 #line 189 "expread.y"
811 { write_exp_elt (UNOP_POSTINCREMENT
); ;
814 #line 193 "expread.y"
815 { write_exp_elt (UNOP_POSTDECREMENT
); ;
818 #line 197 "expread.y"
819 { write_exp_elt (UNOP_SIZEOF
); ;
822 #line 201 "expread.y"
823 { write_exp_elt (STRUCTOP_PTR
);
824 write_exp_string (yyvsp
[0].sval
);
825 write_exp_elt (STRUCTOP_PTR
); ;
828 #line 207 "expread.y"
829 { write_exp_elt (STRUCTOP_MPTR
); ;
832 #line 211 "expread.y"
833 { write_exp_elt (STRUCTOP_STRUCT
);
834 write_exp_string (yyvsp
[0].sval
);
835 write_exp_elt (STRUCTOP_STRUCT
); ;
838 #line 217 "expread.y"
839 { write_exp_elt (STRUCTOP_MEMBER
); ;
842 #line 221 "expread.y"
843 { write_exp_elt (BINOP_SUBSCRIPT
); ;
846 #line 227 "expread.y"
847 { start_arglist (); ;
850 #line 229 "expread.y"
851 { write_exp_elt (OP_FUNCALL
);
852 write_exp_elt (end_arglist ());
853 write_exp_elt (OP_FUNCALL
); ;
856 #line 238 "expread.y"
860 #line 242 "expread.y"
864 #line 246 "expread.y"
865 { write_exp_elt (UNOP_MEMVAL
);
866 write_exp_elt (yyvsp
[-2].tval
);
867 write_exp_elt (UNOP_MEMVAL
); ;
870 #line 252 "expread.y"
871 { write_exp_elt (UNOP_CAST
);
872 write_exp_elt (yyvsp
[-2].tval
);
873 write_exp_elt (UNOP_CAST
); ;
876 #line 258 "expread.y"
880 #line 264 "expread.y"
881 { write_exp_elt (BINOP_REPEAT
); ;
884 #line 268 "expread.y"
885 { write_exp_elt (BINOP_MUL
); ;
888 #line 272 "expread.y"
889 { write_exp_elt (BINOP_DIV
); ;
892 #line 276 "expread.y"
893 { write_exp_elt (BINOP_REM
); ;
896 #line 280 "expread.y"
897 { write_exp_elt (BINOP_ADD
); ;
900 #line 284 "expread.y"
901 { write_exp_elt (BINOP_SUB
); ;
904 #line 288 "expread.y"
905 { write_exp_elt (BINOP_LSH
); ;
908 #line 292 "expread.y"
909 { write_exp_elt (BINOP_RSH
); ;
912 #line 296 "expread.y"
913 { write_exp_elt (BINOP_EQUAL
); ;
916 #line 300 "expread.y"
917 { write_exp_elt (BINOP_NOTEQUAL
); ;
920 #line 304 "expread.y"
921 { write_exp_elt (BINOP_LEQ
); ;
924 #line 308 "expread.y"
925 { write_exp_elt (BINOP_GEQ
); ;
928 #line 312 "expread.y"
929 { write_exp_elt (BINOP_LESS
); ;
932 #line 316 "expread.y"
933 { write_exp_elt (BINOP_GTR
); ;
936 #line 320 "expread.y"
937 { write_exp_elt (BINOP_LOGAND
); ;
940 #line 324 "expread.y"
941 { write_exp_elt (BINOP_LOGXOR
); ;
944 #line 328 "expread.y"
945 { write_exp_elt (BINOP_LOGIOR
); ;
948 #line 332 "expread.y"
949 { write_exp_elt (BINOP_AND
); ;
952 #line 336 "expread.y"
953 { write_exp_elt (BINOP_OR
); ;
956 #line 340 "expread.y"
957 { write_exp_elt (TERNOP_COND
); ;
960 #line 344 "expread.y"
961 { write_exp_elt (BINOP_ASSIGN
); ;
964 #line 348 "expread.y"
965 { write_exp_elt (BINOP_ASSIGN_MODIFY
);
966 write_exp_elt (yyvsp
[-1].opcode
);
967 write_exp_elt (BINOP_ASSIGN_MODIFY
); ;
970 #line 354 "expread.y"
971 { write_exp_elt (OP_LONG
);
972 write_exp_elt (builtin_type_long
);
973 write_exp_elt (yyvsp
[0].lval
);
974 write_exp_elt (OP_LONG
); ;
977 #line 361 "expread.y"
978 { write_exp_elt (OP_LONG
);
979 write_exp_elt (builtin_type_char
);
980 write_exp_elt (yyvsp
[0].lval
);
981 write_exp_elt (OP_LONG
); ;
984 #line 368 "expread.y"
985 { write_exp_elt (OP_DOUBLE
);
986 write_exp_elt (builtin_type_double
);
987 write_exp_elt (yyvsp
[0].dval
);
988 write_exp_elt (OP_DOUBLE
); ;
991 #line 378 "expread.y"
992 { write_exp_elt (OP_LAST
);
993 write_exp_elt (yyvsp
[0].lval
);
994 write_exp_elt (OP_LAST
); ;
997 #line 384 "expread.y"
998 { write_exp_elt (OP_REGISTER
);
999 write_exp_elt (yyvsp
[0].lval
);
1000 write_exp_elt (OP_REGISTER
); ;
1003 #line 390 "expread.y"
1004 { write_exp_elt (OP_INTERNALVAR
);
1005 write_exp_elt (yyvsp
[0].ivar
);
1006 write_exp_elt (OP_INTERNALVAR
); ;
1009 #line 396 "expread.y"
1010 { write_exp_elt (OP_LONG
);
1011 write_exp_elt (builtin_type_int
);
1012 write_exp_elt ((long) TYPE_LENGTH (yyvsp
[-1].tval
));
1013 write_exp_elt (OP_LONG
); ;
1016 #line 403 "expread.y"
1017 { write_exp_elt (OP_STRING
);
1018 write_exp_string (yyvsp
[0].sval
);
1019 write_exp_elt (OP_STRING
); ;
1022 #line 410 "expread.y"
1023 { write_exp_elt (OP_THIS
);
1024 write_exp_elt (OP_THIS
); ;
1027 #line 417 "expread.y"
1029 struct symtab
*tem
= lookup_symtab (copy_name (yyvsp
[0].sval
));
1033 yyval
.bval
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (tem
), 1);
1036 sym
= lookup_symbol (copy_name (yyvsp
[0].sval
),
1037 expression_context_block
,
1039 if (sym
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1040 yyval
.bval
= SYMBOL_BLOCK_VALUE (sym
);
1042 error ("No file or function \"%s\".",
1043 copy_name (yyvsp
[0].sval
));
1048 #line 438 "expread.y"
1051 = lookup_symbol (copy_name (yyvsp
[0].sval
), yyvsp
[-2].bval
, VAR_NAMESPACE
);
1052 if (!tem
|| SYMBOL_CLASS (tem
) != LOC_BLOCK
)
1053 error ("No function \"%s\" in specified context.",
1054 copy_name (yyvsp
[-2].bval
));
1055 yyval
.bval
= SYMBOL_BLOCK_VALUE (tem
);
1059 #line 449 "expread.y"
1062 sym
= lookup_symbol (copy_name (yyvsp
[0].sval
), yyvsp
[-2].bval
, VAR_NAMESPACE
);
1064 error ("No symbol \"%s\" in specified context.",
1065 copy_name (yyvsp
[0].sval
));
1066 write_exp_elt (OP_VAR_VALUE
);
1067 write_exp_elt (sym
);
1068 write_exp_elt (OP_VAR_VALUE
);
1072 #line 462 "expread.y"
1074 struct type
*type
= yyvsp
[-2].tval
;
1075 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
1076 && TYPE_CODE (type
) != TYPE_CODE_UNION
)
1077 error ("`%s' is not defined as an aggregate type.",
1080 write_exp_elt (OP_SCOPE
);
1081 write_exp_elt (type
);
1082 write_exp_string (yyvsp
[0].sval
);
1083 write_exp_elt (OP_SCOPE
);
1087 #line 475 "expread.y"
1089 char *name
= copy_name (yyvsp
[0].sval
);
1093 sym
= lookup_symbol_2 (name
, 0, VAR_NAMESPACE
);
1096 write_exp_elt (OP_VAR_VALUE
);
1097 write_exp_elt (sym
);
1098 write_exp_elt (OP_VAR_VALUE
);
1101 for (i
= 0; i
< misc_function_count
; i
++)
1102 if (!strcmp (misc_function_vector
[i
].name
, name
))
1105 if (i
< misc_function_count
)
1107 write_exp_elt (OP_LONG
);
1108 write_exp_elt (builtin_type_int
);
1109 write_exp_elt (misc_function_vector
[i
].address
);
1110 write_exp_elt (OP_LONG
);
1111 write_exp_elt (UNOP_MEMVAL
);
1112 write_exp_elt (builtin_type_char
);
1113 write_exp_elt (UNOP_MEMVAL
);
1116 if (symtab_list
== 0)
1117 error ("No symbol table is loaded. Use the \"symbol-file\" command.");
1119 error ("No symbol \"%s\" in current context.", name
);
1123 #line 511 "expread.y"
1124 { struct symbol
*sym
;
1125 sym
= lookup_symbol_1 (copy_name (yyvsp
[0].sval
),
1126 expression_context_block
,
1130 write_exp_elt (OP_VAR_VALUE
);
1131 write_exp_elt (sym
);
1132 write_exp_elt (OP_VAR_VALUE
);
1136 register char *arg
= copy_name (yyvsp
[0].sval
);
1139 /* C++: see if it hangs off of `this'. Must
1140 not inadvertently convert from a method call
1142 v
= (int)value_of_this (0);
1145 val
= check_field (v
, arg
);
1148 write_exp_elt (OP_THIS
);
1149 write_exp_elt (OP_THIS
);
1150 write_exp_elt (STRUCTOP_PTR
);
1151 write_exp_string (yyvsp
[0].sval
);
1152 write_exp_elt (STRUCTOP_PTR
);
1156 sym
= lookup_symbol_2 (arg
, 0, VAR_NAMESPACE
);
1159 write_exp_elt (OP_VAR_VALUE
);
1160 write_exp_elt (sym
);
1161 write_exp_elt (OP_VAR_VALUE
);
1162 break; /* YACC-dependent */
1164 for (i
= 0; i
< misc_function_count
; i
++)
1165 if (!strcmp (misc_function_vector
[i
].name
, arg
))
1168 if (i
< misc_function_count
)
1170 write_exp_elt (OP_LONG
);
1171 write_exp_elt (builtin_type_int
);
1172 write_exp_elt (misc_function_vector
[i
].address
);
1173 write_exp_elt (OP_LONG
);
1174 write_exp_elt (UNOP_MEMVAL
);
1175 write_exp_elt (builtin_type_char
);
1176 write_exp_elt (UNOP_MEMVAL
);
1179 if (symtab_list
== 0)
1180 error ("No symbol table is loaded. Use the \"symbol-file\" command.");
1182 error ("No symbol \"%s\" in current context.",
1183 copy_name (yyvsp
[0].sval
));
1188 #line 577 "expread.y"
1189 { yyval
.tval
= lookup_pointer_type (yyvsp
[-1].tval
); ;
1192 #line 579 "expread.y"
1193 { yyval
.tval
= lookup_reference_type (yyvsp
[-1].tval
); ;
1196 #line 581 "expread.y"
1197 { yyval
.tval
= lookup_member_type (builtin_type_int
, yyvsp
[-2].tval
); ;
1200 #line 583 "expread.y"
1201 { yyval
.tval
= lookup_member_type (yyvsp
[-5].tval
, yyvsp
[-3].tval
); ;
1204 #line 585 "expread.y"
1205 { yyval
.tval
= lookup_member_type (lookup_function_type (yyvsp
[-7].tval
, 0), yyvsp
[-5].tval
); ;
1208 #line 587 "expread.y"
1209 { yyval
.tval
= lookup_member_type (lookup_function_type (yyvsp
[-8].tval
, yyvsp
[-1].tvec
), yyvsp
[-6].tval
);
1210 free (yyvsp
[-1].tvec
); ;
1213 #line 593 "expread.y"
1214 { yyval
.tval
= lookup_typename (copy_name (yyvsp
[0].sval
),
1215 expression_context_block
, 0); ;
1218 #line 596 "expread.y"
1219 { yyval
.tval
= lookup_struct (copy_name (yyvsp
[0].sval
),
1220 expression_context_block
); ;
1223 #line 599 "expread.y"
1224 { yyval
.tval
= lookup_union (copy_name (yyvsp
[0].sval
),
1225 expression_context_block
); ;
1228 #line 602 "expread.y"
1229 { yyval
.tval
= lookup_enum (copy_name (yyvsp
[0].sval
),
1230 expression_context_block
); ;
1233 #line 605 "expread.y"
1234 { yyval
.tval
= lookup_unsigned_typename (copy_name (yyvsp
[0].sval
)); ;
1237 #line 610 "expread.y"
1238 { yyval
.tvec
= (struct type
**)xmalloc (sizeof (struct type
*) * 2);
1239 yyval
.tvec
[0] = (struct type
*)0;
1240 yyval
.tvec
[1] = yyvsp
[0].tval
;
1244 #line 615 "expread.y"
1245 { int len
= sizeof (struct type
*) * ++(yyvsp
[-2].ivec
[0]);
1246 yyval
.tvec
= (struct type
**)xrealloc (yyvsp
[-2].tvec
, len
);
1247 yyval
.tvec
[yyval
.ivec
[0]] = yyvsp
[0].tval
;
1251 /* the action file gets copied in in place of this dollarsign */
1252 #line 303 "bison.simple"
1261 short *ssp1
= yyss
- 1;
1262 fprintf (stderr
, "state stack now", yyssp
-yyss
);
1263 while (ssp1
!= yyssp
)
1264 fprintf (stderr
, " %d", *++ssp1
);
1265 fprintf (stderr
, "\n");
1274 yylsp
->first_line
= yylloc
.first_line
;
1275 yylsp
->first_column
= yylloc
.first_column
;
1276 yylsp
->last_line
= (yylsp
-1)->last_line
;
1277 yylsp
->last_column
= (yylsp
-1)->last_column
;
1282 yylsp
->last_line
= (yylsp
+yylen
-1)->last_line
;
1283 yylsp
->last_column
= (yylsp
+yylen
-1)->last_column
;
1286 /* Now "shift" the result of the reduction.
1287 Determine what state that goes to,
1288 based on the state we popped back to
1289 and the rule number reduced by. */
1293 yystate
= yypgoto
[yyn
- YYNTBASE
] + *yyssp
;
1294 if (yystate
>= 0 && yystate
<= YYLAST
&& yycheck
[yystate
] == *yyssp
)
1295 yystate
= yytable
[yystate
];
1297 yystate
= yydefgoto
[yyn
- YYNTBASE
];
1301 yyerrlab
: /* here on detecting error */
1304 /* If not already recovering from an error, report this error. */
1307 yyerror("parse error");
1310 if (yyerrstatus
== 3)
1312 /* if just tried and failed to reuse lookahead token after an error, discard it. */
1314 /* return failure if at end of input */
1315 if (yychar
== YYEOF
)
1320 fprintf(stderr
, "Discarding token %d (%s).\n", yychar
, yytname
[yychar1
]);
1326 /* Else will try to reuse lookahead token
1327 after shifting the error token. */
1329 yyerrstatus
= 3; /* Each real token shifted decrements this */
1333 yyerrdefault
: /* current state does not do anything special for the error token. */
1336 /* This is wrong; only states that explicitly want error tokens
1337 should shift them. */
1338 yyn
= yydefact
[yystate
]; /* If its default is to accept any token, ok. Otherwise pop it.*/
1339 if (yyn
) goto yydefault
;
1342 yyerrpop
: /* pop the current state because it cannot handle the error token */
1344 if (yyssp
== yyss
) YYERROR
;
1352 short *ssp1
= yyss
- 1;
1353 fprintf (stderr
, "Error: state stack now", yyssp
-yyss
);
1354 while (ssp1
!= yyssp
)
1355 fprintf (stderr
, " %d", *++ssp1
);
1356 fprintf (stderr
, "\n");
1362 yyn
= yypact
[yystate
];
1367 if (yyn
< 0 || yyn
> YYLAST
|| yycheck
[yyn
] != YYTERROR
)
1386 fprintf(stderr
, "Shifting error token, ");
1395 #line 624 "expread.y"
1398 /* Begin counting arguments for a function call,
1399 saving the data about any containing call. */
1404 register struct funcall
*new = (struct funcall
*) xmalloc (sizeof (struct funcall
));
1406 new->next
= funcall_chain
;
1407 new->arglist_len
= arglist_len
;
1409 funcall_chain
= new;
1412 /* Return the number of arguments in a function call just terminated,
1413 and restore the data for the containing function call. */
1418 register int val
= arglist_len
;
1419 register struct funcall
*call
= funcall_chain
;
1420 funcall_chain
= call
->next
;
1421 arglist_len
= call
->arglist_len
;
1426 /* Free everything in the funcall chain.
1427 Used when there is an error inside parsing. */
1432 register struct funcall
*call
, *next
;
1434 for (call
= funcall_chain
; call
; call
= next
)
1441 /* This page contains the functions for adding data to the struct expression
1442 being constructed. */
1444 /* Add one element to the end of the expression. */
1447 write_exp_elt (expelt
)
1448 union exp_element expelt
;
1450 if (expout_ptr
>= expout_size
)
1453 expout
= (struct expression
*) xrealloc (expout
,
1454 sizeof (struct expression
)
1455 + expout_size
* sizeof (union exp_element
));
1457 expout
->elts
[expout_ptr
++] = expelt
;
1460 /* Add a string constant to the end of the expression.
1461 Follow it by its length in bytes, as a separate exp_element. */
1464 write_exp_string (str
)
1467 register int len
= str
.length
;
1469 = (len
+ sizeof (union exp_element
)) / sizeof (union exp_element
);
1471 expout_ptr
+= lenelt
;
1473 if (expout_ptr
>= expout_size
)
1475 expout_size
= max (expout_size
* 2, expout_ptr
+ 10);
1476 expout
= (struct expression
*) xrealloc (expout
,
1477 sizeof (struct expression
)
1478 + expout_size
* sizeof (union exp_element
));
1480 bcopy (str
.ptr
, (char *) &expout
->elts
[expout_ptr
- lenelt
], len
);
1481 ((char *) &expout
->elts
[expout_ptr
- lenelt
])[len
] = 0;
1482 write_exp_elt (len
);
1485 /* During parsing of a C expression, the pointer to the next character
1486 is in this variable. */
1488 static char *lexptr
;
1490 /* Tokens that refer to names do so with explicit pointer and length,
1491 so they can share the storage that lexptr is parsing.
1493 When it is necessary to pass a name to a function that expects
1494 a null-terminated string, the substring is copied out
1495 into a block of storage that namecopy points to.
1497 namecopy is allocated once, guaranteed big enough, for each parsing. */
1499 static char *namecopy
;
1501 /* Current depth in parentheses within the expression. */
1503 static int paren_depth
;
1505 /* Nonzero means stop parsing on first comma (if not within parentheses). */
1507 static int comma_terminates
;
1509 /* Take care of parsing a number (anything that starts with a digit).
1510 Set yylval and return the token type; update lexptr.
1511 LEN is the number of characters in it. */
1513 /*** Needs some error checking for the float case ***/
1519 register char *p
= lexptr
;
1520 register long n
= 0;
1522 register int base
= 10;
1523 register int len
= olen
;
1526 extern double atof ();
1528 for (c
= 0; c
< len
; c
++)
1531 /* It's a float since it contains a point. */
1532 yylval
.dval
= atof (p
);
1537 if (len
>= 3 && (!strncmp (p
, "0x", 2) || !strncmp (p
, "0X", 2)))
1550 if (c
>= '0' && c
<= '9')
1554 if (c
>= 'A' && c
<= 'Z') c
+= 'a' - 'A';
1555 if (base
== 16 && c
>= 'a' && c
<= 'f')
1557 else if (len
== 0 && c
== 'l')
1561 err_copy
= (char *) alloca (olen
+ 1);
1562 bcopy (lexptr
, err_copy
, olen
);
1564 error ("Invalid number \"%s\".", err_copy
);
1578 enum exp_opcode opcode
;
1581 static struct token tokentab3
[] =
1583 {">>=", ASSIGN_MODIFY
, BINOP_RSH
},
1584 {"<<=", ASSIGN_MODIFY
, BINOP_LSH
}
1587 static struct token tokentab2
[] =
1589 {"+=", ASSIGN_MODIFY
, BINOP_ADD
},
1590 {"-=", ASSIGN_MODIFY
, BINOP_SUB
},
1591 {"*=", ASSIGN_MODIFY
, BINOP_MUL
},
1592 {"/=", ASSIGN_MODIFY
, BINOP_DIV
},
1593 {"%=", ASSIGN_MODIFY
, BINOP_REM
},
1594 {"|=", ASSIGN_MODIFY
, BINOP_LOGIOR
},
1595 {"&=", ASSIGN_MODIFY
, BINOP_LOGAND
},
1596 {"^=", ASSIGN_MODIFY
, BINOP_LOGXOR
},
1597 {"++", INCREMENT
, BINOP_END
},
1598 {"--", DECREMENT
, BINOP_END
},
1599 {"->", ARROW
, BINOP_END
},
1600 {"&&", AND
, BINOP_END
},
1601 {"||", OR
, BINOP_END
},
1602 {"::", COLONCOLON
, BINOP_END
},
1603 {"<<", LSH
, BINOP_END
},
1604 {">>", RSH
, BINOP_END
},
1605 {"==", EQUAL
, BINOP_END
},
1606 {"!=", NOTEQUAL
, BINOP_END
},
1607 {"<=", LEQ
, BINOP_END
},
1608 {">=", GEQ
, BINOP_END
}
1611 /* Read one token, getting characters through lexptr. */
1617 register int namelen
;
1619 register char *tokstart
;
1624 /* See if it is a special token of length 3. */
1625 for (i
= 0; i
< sizeof tokentab3
/ sizeof tokentab3
[0]; i
++)
1626 if (!strncmp (tokstart
, tokentab3
[i
].operator, 3))
1629 yylval
.opcode
= tokentab3
[i
].opcode
;
1630 return tokentab3
[i
].token
;
1633 /* See if it is a special token of length 2. */
1634 for (i
= 0; i
< sizeof tokentab2
/ sizeof tokentab2
[0]; i
++)
1635 if (!strncmp (tokstart
, tokentab2
[i
].operator, 2))
1638 yylval
.opcode
= tokentab2
[i
].opcode
;
1639 return tokentab2
[i
].token
;
1642 switch (c
= *tokstart
)
1657 c
= parse_escape (&lexptr
);
1661 error ("Invalid character constant.");
1670 if (paren_depth
== 0)
1677 if (comma_terminates
&& paren_depth
== 0)
1707 for (namelen
= 1; (c
= tokstart
[namelen
]) != '"'; namelen
++)
1710 c
= tokstart
[++namelen
];
1711 if (c
>= '0' && c
<= '9')
1713 c
= tokstart
[++namelen
];
1714 if (c
>= '0' && c
<= '9')
1715 c
= tokstart
[++namelen
];
1718 yylval
.sval
.ptr
= tokstart
+ 1;
1719 yylval
.sval
.length
= namelen
- 1;
1720 lexptr
+= namelen
+ 1;
1723 if (c
>= '0' && c
<= '9')
1727 c
= tokstart
[namelen
],
1728 (c
== '_' || c
== '$' || c
== '.' || (c
>= '0' && c
<= '9')
1729 || (c
>= 'a' && c
<= 'z') || (c
>= 'A' && c
<= 'Z'));
1732 return parse_number (namelen
);
1735 if (!(c
== '_' || c
== '$'
1736 || (c
>= 'a' && c
<= 'z') || (c
>= 'A' && c
<= 'Z')))
1737 error ("Invalid token in expression.");
1739 /* It is a name. See how long it is. */
1742 c
= tokstart
[namelen
],
1743 (c
== '_' || c
== '$' || (c
>= '0' && c
<= '9')
1744 || (c
>= 'a' && c
<= 'z') || (c
>= 'A' && c
<= 'Z'));
1748 /* The token "if" terminates the expression and is NOT
1749 removed from the input stream. */
1750 if (namelen
== 2 && tokstart
[0] == 'i' && tokstart
[1] == 'f')
1757 /* Handle the tokens $digits; also $ (short for $0) and $$ (short for $$1)
1758 and $$digits (equivalent to $<-digits> if you could type that).
1759 Make token type LAST, and put the number (the digits) in yylval. */
1761 if (*tokstart
== '$')
1763 register int negate
= 0;
1765 /* Double dollar means negate the number and add -1 as well.
1766 Thus $$ alone means -1. */
1767 if (namelen
>= 2 && tokstart
[1] == '$')
1774 /* Just dollars (one or two) */
1775 yylval
.lval
= - negate
;
1778 /* Is the rest of the token digits? */
1779 for (; c
< namelen
; c
++)
1780 if (!(tokstart
[c
] >= '0' && tokstart
[c
] <= '9'))
1784 yylval
.lval
= atoi (tokstart
+ 1 + negate
);
1786 yylval
.lval
= - yylval
.lval
;
1791 /* Handle tokens that refer to machine registers:
1792 $ followed by a register name. */
1794 if (*tokstart
== '$')
1795 for (c
= 0; c
< NUM_REGS
; c
++)
1796 if (namelen
- 1 == strlen (reg_names
[c
])
1797 && !strncmp (tokstart
+ 1, reg_names
[c
], namelen
- 1))
1803 if (namelen
== 6 && !strncmp (tokstart
, "struct", 6))
1809 if (!strncmp (tokstart
, "union", 5))
1816 if (!strncmp (tokstart
, "enum", 4))
1820 if (!strncmp (tokstart
, "this", 4))
1825 if (namelen
== 6 && !strncmp (tokstart
, "sizeof", 6))
1829 if (namelen
== 8 && !strncmp (tokstart
, "unsigned", 6))
1833 yylval
.sval
.ptr
= tokstart
;
1834 yylval
.sval
.length
= namelen
;
1836 /* Any other names starting in $ are debugger internal variables. */
1838 if (*tokstart
== '$')
1840 yylval
.ivar
= (struct internalvar
*) lookup_internalvar (copy_name (yylval
.sval
) + 1);
1844 /* Use token-type TYPENAME for symbols that happen to be defined
1845 currently as names of types; NAME for other symbols.
1846 The caller is not constrained to care about the distinction. */
1847 if (lookup_typename (copy_name (yylval
.sval
), expression_context_block
, 1))
1855 error ("Invalid syntax in expression.");
1858 /* Return a null-terminated temporary copy of the name
1859 of a string token. */
1863 struct stoken token
;
1865 bcopy (token
.ptr
, namecopy
, token
.length
);
1866 namecopy
[token
.length
] = 0;
1870 /* Reverse an expression from suffix form (in which it is constructed)
1871 to prefix form (in which we can conveniently print or execute it). */
1873 static void prefixify_subexp ();
1876 prefixify_expression (expr
)
1877 register struct expression
*expr
;
1879 register int len
= sizeof (struct expression
) +
1880 expr
->nelts
* sizeof (union exp_element
);
1881 register struct expression
*temp
;
1882 register int inpos
= expr
->nelts
, outpos
= 0;
1884 temp
= (struct expression
*) alloca (len
);
1886 /* Copy the original expression into temp. */
1887 bcopy (expr
, temp
, len
);
1889 prefixify_subexp (temp
, expr
, inpos
, outpos
);
1892 /* Return the number of exp_elements in the subexpression of EXPR
1893 whose last exp_element is at index ENDPOS - 1 in EXPR. */
1896 length_of_subexp (expr
, endpos
)
1897 register struct expression
*expr
;
1898 register int endpos
;
1900 register int oplen
= 1;
1901 register int args
= 0;
1905 error ("?error in length_of_subexp");
1907 i
= (int) expr
->elts
[endpos
- 1].opcode
;
1913 oplen
= 4 + ((expr
->elts
[endpos
- 2].longconst
1914 + sizeof (union exp_element
))
1915 / sizeof (union exp_element
));
1926 case OP_INTERNALVAR
:
1932 args
= 1 + expr
->elts
[endpos
- 2].longconst
;
1941 case STRUCTOP_STRUCT
:
1945 oplen
= 3 + ((expr
->elts
[endpos
- 2].longconst
1946 + sizeof (union exp_element
))
1947 / sizeof (union exp_element
));
1954 case BINOP_ASSIGN_MODIFY
:
1965 args
= 1 + (i
< (int) BINOP_END
);
1970 oplen
+= length_of_subexp (expr
, endpos
- oplen
);
1977 /* Copy the subexpression ending just before index INEND in INEXPR
1978 into OUTEXPR, starting at index OUTBEG.
1979 In the process, convert it from suffix to prefix form. */
1982 prefixify_subexp (inexpr
, outexpr
, inend
, outbeg
)
1983 register struct expression
*inexpr
;
1984 struct expression
*outexpr
;
1988 register int oplen
= 1;
1989 register int args
= 0;
1992 enum exp_opcode opcode
;
1994 /* Compute how long the last operation is (in OPLEN),
1995 and also how many preceding subexpressions serve as
1996 arguments for it (in ARGS). */
1998 opcode
= inexpr
->elts
[inend
- 1].opcode
;
2003 oplen
= 4 + ((inexpr
->elts
[inend
- 2].longconst
2004 + sizeof (union exp_element
))
2005 / sizeof (union exp_element
));
2016 case OP_INTERNALVAR
:
2022 args
= 1 + inexpr
->elts
[inend
- 2].longconst
;
2031 case STRUCTOP_STRUCT
:
2035 oplen
= 3 + ((inexpr
->elts
[inend
- 2].longconst
2036 + sizeof (union exp_element
))
2037 / sizeof (union exp_element
));
2045 case BINOP_ASSIGN_MODIFY
:
2056 args
= 1 + ((int) opcode
< (int) BINOP_END
);
2059 /* Copy the final operator itself, from the end of the input
2060 to the beginning of the output. */
2062 bcopy (&inexpr
->elts
[inend
], &outexpr
->elts
[outbeg
],
2063 oplen
* sizeof (union exp_element
));
2066 /* Find the lengths of the arg subexpressions. */
2067 arglens
= (int *) alloca (args
* sizeof (int));
2068 for (i
= args
- 1; i
>= 0; i
--)
2070 oplen
= length_of_subexp (inexpr
, inend
);
2075 /* Now copy each subexpression, preserving the order of
2076 the subexpressions, but prefixifying each one.
2077 In this loop, inend starts at the beginning of
2078 the expression this level is working on
2079 and marches forward over the arguments.
2080 outbeg does similarly in the output. */
2081 for (i
= 0; i
< args
; i
++)
2085 prefixify_subexp (inexpr
, outexpr
, inend
, outbeg
);
2090 /* This page contains the two entry points to this file. */
2092 /* Read a C expression from the string *STRINGPTR points to,
2093 parse it, and return a pointer to a struct expression that we malloc.
2094 Use block BLOCK as the lexical context for variable names;
2095 if BLOCK is zero, use the block of the selected stack frame.
2096 Meanwhile, advance *STRINGPTR to point after the expression,
2097 at the first nonwhite character that is not part of the expression
2098 (possibly a null character).
2100 If COMMA is nonzero, stop if a comma is reached. */
2103 parse_c_1 (stringptr
, block
, comma
)
2105 struct block
*block
;
2107 struct cleanup
*old_chain
;
2109 lexptr
= *stringptr
;
2111 comma_terminates
= comma
;
2113 if (lexptr
== 0 || *lexptr
== 0)
2114 error_no_arg ("expression to compute");
2116 old_chain
= make_cleanup (free_funcalls
, 0);
2119 expression_context_block
= block
? block
: get_selected_block ();
2121 namecopy
= (char *) alloca (strlen (lexptr
) + 1);
2124 expout
= (struct expression
*) xmalloc (sizeof (struct expression
)
2125 + expout_size
* sizeof (union exp_element
));
2126 make_cleanup (free_current_contents
, &expout
);
2129 discard_cleanups (old_chain
);
2130 expout
->nelts
= expout_ptr
;
2131 expout
= (struct expression
*)
2133 sizeof (struct expression
)
2134 + expout_ptr
* sizeof (union exp_element
));
2135 prefixify_expression (expout
);
2136 *stringptr
= lexptr
;
2140 /* Parse STRING as an expression, and complain if this fails
2141 to use up all of the contents of STRING. */
2144 parse_c_expression (string
)
2147 register struct expression
*exp
;
2148 exp
= parse_c_1 (&string
, 0, 0);
2150 error ("Junk after end of expression.");
This page took 0.077982 seconds and 5 git commands to generate.