Commit | Line | Data |
---|---|---|
e58de8a2 | 1 | /* YACC grammar for Chill expressions, for GDB. |
ba47c66a | 2 | Copyright 1992, 1993, 1994 Free Software Foundation, Inc. |
e58de8a2 FF |
3 | |
4 | This file is part of GDB. | |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | This program is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | ||
20 | /* Parse a Chill expression from text in a string, | |
21 | and return the result as a struct expression pointer. | |
22 | That structure contains arithmetic operations in reverse polish, | |
23 | with constants represented by operations that are followed by special data. | |
24 | See expression.h for the details of the format. | |
25 | What is important here is that it can be built up sequentially | |
26 | during the process of parsing; the lower levels of the tree always | |
27 | come first in the result. | |
28 | ||
29 | Note that malloc's and realloc's in this file are transformed to | |
30 | xmalloc and xrealloc respectively by the same sed command in the | |
31 | makefile that remaps any other malloc/realloc inserted by the parser | |
32 | generator. Doing this with #defines and trying to control the interaction | |
33 | with include files (<malloc.h> and <stdlib.h> for example) just became | |
34 | too messy, particularly when such includes can be inserted at random | |
35 | times by the parser generator. | |
36 | ||
37 | Also note that the language accepted by this parser is more liberal | |
38 | than the one accepted by an actual Chill compiler. For example, the | |
39 | language rule that a simple name string can not be one of the reserved | |
40 | simple name strings is not enforced (e.g "case" is not treated as a | |
41 | reserved name). Another example is that Chill is a strongly typed | |
42 | language, and certain expressions that violate the type constraints | |
43 | may still be evaluated if gdb can do so in a meaningful manner, while | |
44 | such expressions would be rejected by the compiler. The reason for | |
45 | this more liberal behavior is the philosophy that the debugger | |
46 | is intended to be a tool that is used by the programmer when things | |
47 | go wrong, and as such, it should provide as few artificial barriers | |
48 | to it's use as possible. If it can do something meaningful, even | |
49 | something that violates language contraints that are enforced by the | |
50 | compiler, it should do so without complaint. | |
51 | ||
52 | */ | |
53 | ||
54 | %{ | |
55 | ||
e58de8a2 | 56 | #include "defs.h" |
ba47c66a | 57 | #include <string.h> |
00cea52f | 58 | #include <ctype.h> |
e58de8a2 FF |
59 | #include "expression.h" |
60 | #include "language.h" | |
61 | #include "value.h" | |
62 | #include "parser-defs.h" | |
22e39759 | 63 | #include "ch-lang.h" |
100f92e2 JK |
64 | #include "bfd.h" /* Required by objfiles.h. */ |
65 | #include "symfile.h" /* Required by objfiles.h. */ | |
66 | #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */ | |
e58de8a2 | 67 | |
19d0f3f4 FF |
68 | /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc), |
69 | as well as gratuitiously global symbol names, so we can have multiple | |
70 | yacc generated parsers in gdb. Note that these are only the variables | |
71 | produced by yacc. If other parser generators (bison, byacc, etc) produce | |
72 | additional global names that conflict at link time, then those parser | |
73 | generators need to be fixed instead of adding those names to this list. */ | |
74 | ||
e58de8a2 FF |
75 | #define yymaxdepth chill_maxdepth |
76 | #define yyparse chill_parse | |
77 | #define yylex chill_lex | |
78 | #define yyerror chill_error | |
79 | #define yylval chill_lval | |
80 | #define yychar chill_char | |
81 | #define yydebug chill_debug | |
82 | #define yypact chill_pact | |
83 | #define yyr1 chill_r1 | |
84 | #define yyr2 chill_r2 | |
85 | #define yydef chill_def | |
86 | #define yychk chill_chk | |
87 | #define yypgo chill_pgo | |
88 | #define yyact chill_act | |
89 | #define yyexca chill_exca | |
4015bfb9 BK |
90 | #define yyerrflag chill_errflag |
91 | #define yynerrs chill_nerrs | |
e58de8a2 FF |
92 | #define yyps chill_ps |
93 | #define yypv chill_pv | |
94 | #define yys chill_s | |
95 | #define yy_yys chill_yys | |
96 | #define yystate chill_state | |
97 | #define yytmp chill_tmp | |
98 | #define yyv chill_v | |
99 | #define yy_yyv chill_yyv | |
100 | #define yyval chill_val | |
101 | #define yylloc chill_lloc | |
4015bfb9 BK |
102 | #define yyreds chill_reds /* With YYDEBUG defined */ |
103 | #define yytoks chill_toks /* With YYDEBUG defined */ | |
19d0f3f4 FF |
104 | |
105 | #ifndef YYDEBUG | |
106 | #define YYDEBUG 0 /* Default to no yydebug support */ | |
107 | #endif | |
108 | ||
109 | int | |
110 | yyparse PARAMS ((void)); | |
e58de8a2 FF |
111 | |
112 | static int | |
113 | yylex PARAMS ((void)); | |
114 | ||
22e39759 | 115 | void |
e58de8a2 FF |
116 | yyerror PARAMS ((char *)); |
117 | ||
e58de8a2 FF |
118 | %} |
119 | ||
120 | /* Although the yacc "value" of an expression is not used, | |
121 | since the result is stored in the structure being created, | |
122 | other node types do have values. */ | |
123 | ||
124 | %union | |
125 | { | |
126 | LONGEST lval; | |
127 | unsigned LONGEST ulval; | |
128 | struct { | |
129 | LONGEST val; | |
130 | struct type *type; | |
131 | } typed_val; | |
132 | double dval; | |
133 | struct symbol *sym; | |
134 | struct type *tval; | |
135 | struct stoken sval; | |
136 | struct ttype tsym; | |
137 | struct symtoken ssym; | |
138 | int voidval; | |
139 | struct block *bval; | |
140 | enum exp_opcode opcode; | |
141 | struct internalvar *ivar; | |
142 | ||
143 | struct type **tvec; | |
144 | int *ivec; | |
145 | } | |
146 | ||
2fcc38b8 FF |
147 | %token <voidval> FIXME_01 |
148 | %token <voidval> FIXME_02 | |
149 | %token <voidval> FIXME_03 | |
150 | %token <voidval> FIXME_04 | |
151 | %token <voidval> FIXME_05 | |
152 | %token <voidval> FIXME_06 | |
153 | %token <voidval> FIXME_07 | |
154 | %token <voidval> FIXME_08 | |
155 | %token <voidval> FIXME_09 | |
156 | %token <voidval> FIXME_10 | |
157 | %token <voidval> FIXME_11 | |
158 | %token <voidval> FIXME_12 | |
159 | %token <voidval> FIXME_13 | |
160 | %token <voidval> FIXME_14 | |
161 | %token <voidval> FIXME_15 | |
162 | %token <voidval> FIXME_16 | |
163 | %token <voidval> FIXME_17 | |
164 | %token <voidval> FIXME_18 | |
165 | %token <voidval> FIXME_19 | |
166 | %token <voidval> FIXME_20 | |
167 | %token <voidval> FIXME_21 | |
168 | %token <voidval> FIXME_22 | |
2fcc38b8 FF |
169 | %token <voidval> FIXME_24 |
170 | %token <voidval> FIXME_25 | |
171 | %token <voidval> FIXME_26 | |
172 | %token <voidval> FIXME_27 | |
173 | %token <voidval> FIXME_28 | |
174 | %token <voidval> FIXME_29 | |
175 | %token <voidval> FIXME_30 | |
e58de8a2 FF |
176 | |
177 | %token <typed_val> INTEGER_LITERAL | |
178 | %token <ulval> BOOLEAN_LITERAL | |
2e66cf7d | 179 | %token <typed_val> CHARACTER_LITERAL |
1188fbbf | 180 | %token <dval> FLOAT_LITERAL |
cbd1bdc3 FF |
181 | %token <ssym> GENERAL_PROCEDURE_NAME |
182 | %token <ssym> LOCATION_NAME | |
e58de8a2 FF |
183 | %token <voidval> SET_LITERAL |
184 | %token <voidval> EMPTINESS_LITERAL | |
c7da3ed3 | 185 | %token <sval> CHARACTER_STRING_LITERAL |
81028ab0 | 186 | %token <sval> BIT_STRING_LITERAL |
8a177da6 PB |
187 | %token <tsym> TYPENAME |
188 | %token <sval> FIELD_NAME | |
e58de8a2 | 189 | |
e58de8a2 FF |
190 | %token <voidval> '.' |
191 | %token <voidval> ';' | |
192 | %token <voidval> ':' | |
193 | %token <voidval> CASE | |
194 | %token <voidval> OF | |
195 | %token <voidval> ESAC | |
196 | %token <voidval> LOGIOR | |
197 | %token <voidval> ORIF | |
198 | %token <voidval> LOGXOR | |
199 | %token <voidval> LOGAND | |
200 | %token <voidval> ANDIF | |
201 | %token <voidval> '=' | |
202 | %token <voidval> NOTEQUAL | |
203 | %token <voidval> '>' | |
204 | %token <voidval> GTR | |
205 | %token <voidval> '<' | |
206 | %token <voidval> LEQ | |
207 | %token <voidval> IN | |
208 | %token <voidval> '+' | |
209 | %token <voidval> '-' | |
210 | %token <voidval> '*' | |
211 | %token <voidval> '/' | |
212 | %token <voidval> SLASH_SLASH | |
213 | %token <voidval> MOD | |
214 | %token <voidval> REM | |
215 | %token <voidval> NOT | |
216 | %token <voidval> POINTER | |
217 | %token <voidval> RECEIVE | |
e58de8a2 FF |
218 | %token <voidval> '[' |
219 | %token <voidval> ']' | |
220 | %token <voidval> '(' | |
221 | %token <voidval> ')' | |
222 | %token <voidval> UP | |
223 | %token <voidval> IF | |
224 | %token <voidval> THEN | |
225 | %token <voidval> ELSE | |
226 | %token <voidval> FI | |
227 | %token <voidval> ELSIF | |
228 | %token <voidval> ILLEGAL_TOKEN | |
81028ab0 FF |
229 | %token <voidval> NUM |
230 | %token <voidval> PRED | |
231 | %token <voidval> SUCC | |
232 | %token <voidval> ABS | |
233 | %token <voidval> CARD | |
57ffffe3 JG |
234 | %token <voidval> MAX_TOKEN |
235 | %token <voidval> MIN_TOKEN | |
81028ab0 FF |
236 | %token <voidval> SIZE |
237 | %token <voidval> UPPER | |
238 | %token <voidval> LOWER | |
239 | %token <voidval> LENGTH | |
835c2559 | 240 | %token <voidval> ARRAY |
e58de8a2 | 241 | |
45fe3db4 FF |
242 | /* Tokens which are not Chill tokens used in expressions, but rather GDB |
243 | specific things that we recognize in the same context as Chill tokens | |
244 | (register names for example). */ | |
245 | ||
246 | %token <lval> GDB_REGNAME /* Machine register name */ | |
247 | %token <lval> GDB_LAST /* Value history */ | |
248 | %token <ivar> GDB_VARIABLE /* Convenience variable */ | |
249 | %token <voidval> GDB_ASSIGNMENT /* Assign value to somewhere */ | |
250 | ||
cbd1bdc3 | 251 | %type <voidval> access_name |
e58de8a2 | 252 | %type <voidval> primitive_value |
e58de8a2 FF |
253 | %type <voidval> value_name |
254 | %type <voidval> literal | |
255 | %type <voidval> tuple | |
f91a9e05 | 256 | %type <voidval> slice |
e58de8a2 FF |
257 | %type <voidval> expression_conversion |
258 | %type <voidval> value_procedure_call | |
259 | %type <voidval> value_built_in_routine_call | |
81028ab0 | 260 | %type <voidval> chill_value_built_in_routine_call |
e58de8a2 FF |
261 | %type <voidval> start_expression |
262 | %type <voidval> zero_adic_operator | |
263 | %type <voidval> parenthesised_expression | |
264 | %type <voidval> value | |
265 | %type <voidval> undefined_value | |
266 | %type <voidval> expression | |
267 | %type <voidval> conditional_expression | |
268 | %type <voidval> then_alternative | |
269 | %type <voidval> else_alternative | |
270 | %type <voidval> sub_expression | |
271 | %type <voidval> value_case_alternative | |
272 | %type <voidval> operand_0 | |
273 | %type <voidval> operand_1 | |
274 | %type <voidval> operand_2 | |
275 | %type <voidval> operand_3 | |
276 | %type <voidval> operand_4 | |
277 | %type <voidval> operand_5 | |
278 | %type <voidval> operand_6 | |
e58de8a2 FF |
279 | %type <voidval> synonym_name |
280 | %type <voidval> value_enumeration_name | |
281 | %type <voidval> value_do_with_name | |
282 | %type <voidval> value_receive_name | |
e58de8a2 | 283 | %type <voidval> expression_list |
58cda66e | 284 | %type <tval> mode_argument |
81028ab0 FF |
285 | %type <voidval> upper_lower_argument |
286 | %type <voidval> length_argument | |
81028ab0 FF |
287 | %type <voidval> array_mode_name |
288 | %type <voidval> string_mode_name | |
289 | %type <voidval> variant_structure_mode_name | |
e58de8a2 FF |
290 | %type <voidval> boolean_expression |
291 | %type <voidval> case_selector_list | |
292 | %type <voidval> subexpression | |
293 | %type <voidval> case_label_specification | |
294 | %type <voidval> buffer_location | |
45fe3db4 | 295 | %type <voidval> single_assignment_action |
8a177da6 | 296 | %type <tsym> mode_name |
f91a9e05 | 297 | %type <lval> rparen |
45fe3db4 | 298 | |
e58de8a2 FF |
299 | %% |
300 | ||
301 | /* Z.200, 5.3.1 */ | |
302 | ||
f39a2631 | 303 | start : value { } |
8a177da6 PB |
304 | | mode_name |
305 | { write_exp_elt_opcode(OP_TYPE); | |
306 | write_exp_elt_type($1.type); | |
307 | write_exp_elt_opcode(OP_TYPE);} | |
308 | ; | |
309 | ||
e58de8a2 FF |
310 | value : expression |
311 | { | |
2e66cf7d | 312 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
313 | } |
314 | | undefined_value | |
315 | { | |
2e66cf7d | 316 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
317 | } |
318 | ; | |
319 | ||
2fcc38b8 | 320 | undefined_value : FIXME_01 |
e58de8a2 | 321 | { |
2e66cf7d | 322 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
323 | } |
324 | ; | |
325 | ||
cbd1bdc3 FF |
326 | /* Z.200, 4.2.2 */ |
327 | ||
328 | access_name : LOCATION_NAME | |
329 | { | |
330 | write_exp_elt_opcode (OP_VAR_VALUE); | |
479fdd26 | 331 | write_exp_elt_block (NULL); |
cbd1bdc3 FF |
332 | write_exp_elt_sym ($1.sym); |
333 | write_exp_elt_opcode (OP_VAR_VALUE); | |
334 | } | |
45fe3db4 FF |
335 | | GDB_LAST /* gdb specific */ |
336 | { | |
337 | write_exp_elt_opcode (OP_LAST); | |
338 | write_exp_elt_longcst ($1); | |
339 | write_exp_elt_opcode (OP_LAST); | |
340 | } | |
341 | | GDB_REGNAME /* gdb specific */ | |
342 | { | |
343 | write_exp_elt_opcode (OP_REGISTER); | |
344 | write_exp_elt_longcst ($1); | |
345 | write_exp_elt_opcode (OP_REGISTER); | |
346 | } | |
347 | | GDB_VARIABLE /* gdb specific */ | |
348 | { | |
349 | write_exp_elt_opcode (OP_INTERNALVAR); | |
350 | write_exp_elt_intern ($1); | |
351 | write_exp_elt_opcode (OP_INTERNALVAR); | |
352 | } | |
2fcc38b8 | 353 | | FIXME_03 |
e58de8a2 | 354 | { |
2e66cf7d | 355 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
356 | } |
357 | ; | |
358 | ||
54bbbfb4 FF |
359 | /* Z.200, 4.2.8 */ |
360 | ||
361 | expression_list : expression | |
362 | { | |
363 | arglist_len = 1; | |
364 | } | |
365 | | expression_list ',' expression | |
366 | { | |
367 | arglist_len++; | |
368 | } | |
dcda44a0 PB |
369 | ; |
370 | ||
60438e8e PB |
371 | maybe_expression_list: /* EMPTY */ |
372 | { | |
373 | arglist_len = 0; | |
374 | } | |
375 | | expression_list | |
376 | ; | |
377 | ||
54bbbfb4 | 378 | |
e58de8a2 FF |
379 | /* Z.200, 5.2.1 */ |
380 | ||
f91a9e05 | 381 | primitive_value_lparen: primitive_value '(' |
bdef6b60 PB |
382 | /* This is to save the value of arglist_len |
383 | being accumulated for each dimension. */ | |
384 | { start_arglist (); } | |
f91a9e05 PB |
385 | ; |
386 | ||
387 | rparen : ')' | |
388 | { $$ = end_arglist (); } | |
389 | ; | |
390 | ||
391 | primitive_value : | |
392 | access_name | |
60438e8e | 393 | | primitive_value_lparen maybe_expression_list rparen |
e58de8a2 | 394 | { |
bdef6b60 | 395 | write_exp_elt_opcode (MULTI_SUBSCRIPT); |
f91a9e05 | 396 | write_exp_elt_longcst ($3); |
bdef6b60 PB |
397 | write_exp_elt_opcode (MULTI_SUBSCRIPT); |
398 | } | |
399 | | primitive_value FIELD_NAME | |
400 | { write_exp_elt_opcode (STRUCTOP_STRUCT); | |
401 | write_exp_string ($2); | |
402 | write_exp_elt_opcode (STRUCTOP_STRUCT); | |
403 | } | |
404 | | primitive_value POINTER | |
405 | { | |
406 | write_exp_elt_opcode (UNOP_IND); | |
e58de8a2 FF |
407 | } |
408 | | value_name | |
409 | { | |
2e66cf7d | 410 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
411 | } |
412 | | literal | |
413 | { | |
2e66cf7d | 414 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
415 | } |
416 | | tuple | |
417 | { | |
2e66cf7d | 418 | $$ = 0; /* FIXME */ |
e58de8a2 | 419 | } |
f91a9e05 | 420 | | slice |
e58de8a2 | 421 | { |
2e66cf7d | 422 | $$ = 0; /* FIXME */ |
e58de8a2 | 423 | } |
e58de8a2 FF |
424 | | expression_conversion |
425 | { | |
2e66cf7d | 426 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
427 | } |
428 | | value_procedure_call | |
429 | { | |
2e66cf7d | 430 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
431 | } |
432 | | value_built_in_routine_call | |
433 | { | |
2e66cf7d | 434 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
435 | } |
436 | | start_expression | |
437 | { | |
2e66cf7d | 438 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
439 | } |
440 | | zero_adic_operator | |
441 | { | |
2e66cf7d | 442 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
443 | } |
444 | | parenthesised_expression | |
445 | { | |
2e66cf7d | 446 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
447 | } |
448 | ; | |
449 | ||
e58de8a2 FF |
450 | /* Z.200, 5.2.3 */ |
451 | ||
452 | value_name : synonym_name | |
453 | { | |
2e66cf7d | 454 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
455 | } |
456 | | value_enumeration_name | |
457 | { | |
2e66cf7d | 458 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
459 | } |
460 | | value_do_with_name | |
461 | { | |
2e66cf7d | 462 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
463 | } |
464 | | value_receive_name | |
465 | { | |
2e66cf7d | 466 | $$ = 0; /* FIXME */ |
e58de8a2 | 467 | } |
cbd1bdc3 | 468 | | GENERAL_PROCEDURE_NAME |
e58de8a2 | 469 | { |
cbd1bdc3 | 470 | write_exp_elt_opcode (OP_VAR_VALUE); |
479fdd26 | 471 | write_exp_elt_block (NULL); |
cbd1bdc3 FF |
472 | write_exp_elt_sym ($1.sym); |
473 | write_exp_elt_opcode (OP_VAR_VALUE); | |
e58de8a2 FF |
474 | } |
475 | ; | |
476 | ||
477 | /* Z.200, 5.2.4.1 */ | |
478 | ||
479 | literal : INTEGER_LITERAL | |
480 | { | |
2e66cf7d FF |
481 | write_exp_elt_opcode (OP_LONG); |
482 | write_exp_elt_type ($1.type); | |
483 | write_exp_elt_longcst ((LONGEST) ($1.val)); | |
484 | write_exp_elt_opcode (OP_LONG); | |
e58de8a2 FF |
485 | } |
486 | | BOOLEAN_LITERAL | |
487 | { | |
2e66cf7d FF |
488 | write_exp_elt_opcode (OP_BOOL); |
489 | write_exp_elt_longcst ((LONGEST) $1); | |
490 | write_exp_elt_opcode (OP_BOOL); | |
e58de8a2 FF |
491 | } |
492 | | CHARACTER_LITERAL | |
493 | { | |
2e66cf7d FF |
494 | write_exp_elt_opcode (OP_LONG); |
495 | write_exp_elt_type ($1.type); | |
496 | write_exp_elt_longcst ((LONGEST) ($1.val)); | |
497 | write_exp_elt_opcode (OP_LONG); | |
e58de8a2 | 498 | } |
1188fbbf FF |
499 | | FLOAT_LITERAL |
500 | { | |
501 | write_exp_elt_opcode (OP_DOUBLE); | |
502 | write_exp_elt_type (builtin_type_double); | |
503 | write_exp_elt_dblcst ($1); | |
504 | write_exp_elt_opcode (OP_DOUBLE); | |
505 | } | |
e58de8a2 FF |
506 | | SET_LITERAL |
507 | { | |
2e66cf7d | 508 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
509 | } |
510 | | EMPTINESS_LITERAL | |
511 | { | |
2d67c7e9 PB |
512 | struct type *void_ptr_type |
513 | = lookup_pointer_type (builtin_type_void); | |
514 | write_exp_elt_opcode (OP_LONG); | |
515 | write_exp_elt_type (void_ptr_type); | |
516 | write_exp_elt_longcst (0); | |
517 | write_exp_elt_opcode (OP_LONG); | |
e58de8a2 FF |
518 | } |
519 | | CHARACTER_STRING_LITERAL | |
520 | { | |
c7da3ed3 FF |
521 | write_exp_elt_opcode (OP_STRING); |
522 | write_exp_string ($1); | |
523 | write_exp_elt_opcode (OP_STRING); | |
e58de8a2 FF |
524 | } |
525 | | BIT_STRING_LITERAL | |
526 | { | |
81028ab0 FF |
527 | write_exp_elt_opcode (OP_BITSTRING); |
528 | write_exp_bitstring ($1); | |
529 | write_exp_elt_opcode (OP_BITSTRING); | |
e58de8a2 FF |
530 | } |
531 | ; | |
532 | ||
533 | /* Z.200, 5.2.5 */ | |
534 | ||
dcda44a0 PB |
535 | tuple_element : expression |
536 | | named_record_element | |
537 | ; | |
538 | ||
539 | named_record_element: FIELD_NAME ',' named_record_element | |
540 | { write_exp_elt_opcode (OP_LABELED); | |
541 | write_exp_string ($1); | |
542 | write_exp_elt_opcode (OP_LABELED); | |
543 | } | |
544 | | FIELD_NAME ':' expression | |
545 | { write_exp_elt_opcode (OP_LABELED); | |
546 | write_exp_string ($1); | |
547 | write_exp_elt_opcode (OP_LABELED); | |
548 | } | |
549 | ; | |
550 | ||
551 | tuple_elements : tuple_element | |
552 | { | |
553 | arglist_len = 1; | |
554 | } | |
555 | | tuple_elements ',' tuple_element | |
556 | { | |
557 | arglist_len++; | |
558 | } | |
559 | ; | |
560 | ||
f91a9e05 PB |
561 | maybe_tuple_elements : tuple_elements |
562 | | /* EMPTY */ | |
563 | ; | |
564 | ||
2d67c7e9 PB |
565 | tuple : '[' |
566 | { start_arglist (); } | |
f91a9e05 | 567 | maybe_tuple_elements ']' |
e58de8a2 | 568 | { |
2d67c7e9 PB |
569 | write_exp_elt_opcode (OP_ARRAY); |
570 | write_exp_elt_longcst ((LONGEST) 0); | |
571 | write_exp_elt_longcst ((LONGEST) end_arglist () - 1); | |
572 | write_exp_elt_opcode (OP_ARRAY); | |
573 | } | |
574 | | | |
575 | mode_name '[' | |
576 | { start_arglist (); } | |
f91a9e05 | 577 | maybe_tuple_elements ']' |
2d67c7e9 PB |
578 | { |
579 | write_exp_elt_opcode (OP_ARRAY); | |
580 | write_exp_elt_longcst ((LONGEST) 0); | |
581 | write_exp_elt_longcst ((LONGEST) end_arglist () - 1); | |
582 | write_exp_elt_opcode (OP_ARRAY); | |
583 | ||
584 | write_exp_elt_opcode (UNOP_CAST); | |
585 | write_exp_elt_type ($1.type); | |
586 | write_exp_elt_opcode (UNOP_CAST); | |
e58de8a2 FF |
587 | } |
588 | ; | |
589 | ||
590 | ||
591 | /* Z.200, 5.2.6 */ | |
592 | ||
e58de8a2 | 593 | |
f91a9e05 | 594 | slice: primitive_value_lparen expression ':' expression rparen |
e58de8a2 | 595 | { |
f91a9e05 | 596 | write_exp_elt_opcode (TERNOP_SLICE); |
e58de8a2 | 597 | } |
f91a9e05 | 598 | | primitive_value_lparen expression UP expression rparen |
e58de8a2 | 599 | { |
f91a9e05 | 600 | write_exp_elt_opcode (TERNOP_SLICE_COUNT); |
e58de8a2 FF |
601 | } |
602 | ; | |
603 | ||
e58de8a2 FF |
604 | /* Z.200, 5.2.11 */ |
605 | ||
2fcc38b8 | 606 | expression_conversion: mode_name parenthesised_expression |
e58de8a2 | 607 | { |
8a177da6 PB |
608 | write_exp_elt_opcode (UNOP_CAST); |
609 | write_exp_elt_type ($1.type); | |
610 | write_exp_elt_opcode (UNOP_CAST); | |
e58de8a2 | 611 | } |
835c2559 PB |
612 | | ARRAY '(' ')' mode_name parenthesised_expression |
613 | /* This is pseudo-Chill, similar to C's '(TYPE[])EXPR' | |
614 | which casts to an artificial array. */ | |
615 | { | |
616 | struct type *range_type | |
617 | = create_range_type ((struct type *) NULL, | |
618 | builtin_type_int, 0, 0); | |
619 | struct type *array_type | |
620 | = create_array_type ((struct type *) NULL, | |
621 | $4.type, range_type); | |
622 | TYPE_ARRAY_UPPER_BOUND_TYPE(array_type) | |
623 | = BOUND_CANNOT_BE_DETERMINED; | |
624 | write_exp_elt_opcode (UNOP_CAST); | |
625 | write_exp_elt_type (array_type); | |
626 | write_exp_elt_opcode (UNOP_CAST); | |
627 | } | |
e58de8a2 FF |
628 | ; |
629 | ||
630 | /* Z.200, 5.2.12 */ | |
631 | ||
2fcc38b8 | 632 | value_procedure_call: FIXME_05 |
e58de8a2 | 633 | { |
2e66cf7d | 634 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
635 | } |
636 | ; | |
637 | ||
638 | /* Z.200, 5.2.13 */ | |
639 | ||
81028ab0 | 640 | value_built_in_routine_call: chill_value_built_in_routine_call |
e58de8a2 | 641 | { |
2e66cf7d | 642 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
643 | } |
644 | ; | |
645 | ||
646 | /* Z.200, 5.2.14 */ | |
647 | ||
2fcc38b8 | 648 | start_expression: FIXME_06 |
e58de8a2 | 649 | { |
2e66cf7d | 650 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
651 | } /* Not in GNU-Chill */ |
652 | ; | |
653 | ||
654 | /* Z.200, 5.2.15 */ | |
655 | ||
2fcc38b8 | 656 | zero_adic_operator: FIXME_07 |
e58de8a2 | 657 | { |
2e66cf7d | 658 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
659 | } |
660 | ; | |
661 | ||
662 | /* Z.200, 5.2.16 */ | |
663 | ||
664 | parenthesised_expression: '(' expression ')' | |
665 | { | |
2e66cf7d | 666 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
667 | } |
668 | ; | |
669 | ||
670 | /* Z.200, 5.3.2 */ | |
671 | ||
672 | expression : operand_0 | |
673 | { | |
2e66cf7d | 674 | $$ = 0; /* FIXME */ |
e58de8a2 | 675 | } |
8a177da6 PB |
676 | | single_assignment_action |
677 | { | |
678 | $$ = 0; /* FIXME */ | |
679 | } | |
e58de8a2 FF |
680 | | conditional_expression |
681 | { | |
2e66cf7d | 682 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
683 | } |
684 | ; | |
685 | ||
686 | conditional_expression : IF boolean_expression then_alternative else_alternative FI | |
687 | { | |
2e66cf7d | 688 | $$ = 0; /* FIXME */ |
e58de8a2 | 689 | } |
2d67c7e9 | 690 | | CASE case_selector_list OF value_case_alternative ELSE sub_expression ESAC |
e58de8a2 | 691 | { |
2e66cf7d | 692 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
693 | } |
694 | ; | |
695 | ||
696 | then_alternative: THEN subexpression | |
697 | { | |
2e66cf7d | 698 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
699 | } |
700 | ; | |
701 | ||
702 | else_alternative: ELSE subexpression | |
703 | { | |
2e66cf7d | 704 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
705 | } |
706 | | ELSIF boolean_expression then_alternative else_alternative | |
707 | { | |
2e66cf7d | 708 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
709 | } |
710 | ; | |
711 | ||
712 | sub_expression : expression | |
713 | { | |
2e66cf7d | 714 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
715 | } |
716 | ; | |
717 | ||
718 | value_case_alternative: case_label_specification ':' sub_expression ';' | |
719 | { | |
2e66cf7d | 720 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
721 | } |
722 | ; | |
723 | ||
724 | /* Z.200, 5.3.3 */ | |
725 | ||
726 | operand_0 : operand_1 | |
727 | { | |
2e66cf7d | 728 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
729 | } |
730 | | operand_0 LOGIOR operand_1 | |
731 | { | |
2e66cf7d | 732 | write_exp_elt_opcode (BINOP_BITWISE_IOR); |
e58de8a2 FF |
733 | } |
734 | | operand_0 ORIF operand_1 | |
735 | { | |
2e66cf7d | 736 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
737 | } |
738 | | operand_0 LOGXOR operand_1 | |
739 | { | |
2e66cf7d | 740 | write_exp_elt_opcode (BINOP_BITWISE_XOR); |
e58de8a2 FF |
741 | } |
742 | ; | |
743 | ||
744 | /* Z.200, 5.3.4 */ | |
745 | ||
746 | operand_1 : operand_2 | |
747 | { | |
2e66cf7d | 748 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
749 | } |
750 | | operand_1 LOGAND operand_2 | |
751 | { | |
2e66cf7d | 752 | write_exp_elt_opcode (BINOP_BITWISE_AND); |
e58de8a2 FF |
753 | } |
754 | | operand_1 ANDIF operand_2 | |
755 | { | |
2e66cf7d | 756 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
757 | } |
758 | ; | |
759 | ||
760 | /* Z.200, 5.3.5 */ | |
761 | ||
762 | operand_2 : operand_3 | |
763 | { | |
2e66cf7d | 764 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
765 | } |
766 | | operand_2 '=' operand_3 | |
767 | { | |
2e66cf7d | 768 | write_exp_elt_opcode (BINOP_EQUAL); |
e58de8a2 FF |
769 | } |
770 | | operand_2 NOTEQUAL operand_3 | |
771 | { | |
2e66cf7d | 772 | write_exp_elt_opcode (BINOP_NOTEQUAL); |
e58de8a2 FF |
773 | } |
774 | | operand_2 '>' operand_3 | |
775 | { | |
2e66cf7d | 776 | write_exp_elt_opcode (BINOP_GTR); |
e58de8a2 FF |
777 | } |
778 | | operand_2 GTR operand_3 | |
779 | { | |
2e66cf7d | 780 | write_exp_elt_opcode (BINOP_GEQ); |
e58de8a2 FF |
781 | } |
782 | | operand_2 '<' operand_3 | |
783 | { | |
2e66cf7d | 784 | write_exp_elt_opcode (BINOP_LESS); |
e58de8a2 FF |
785 | } |
786 | | operand_2 LEQ operand_3 | |
787 | { | |
2e66cf7d | 788 | write_exp_elt_opcode (BINOP_LEQ); |
e58de8a2 FF |
789 | } |
790 | | operand_2 IN operand_3 | |
791 | { | |
e909f287 | 792 | write_exp_elt_opcode (BINOP_IN); |
e58de8a2 FF |
793 | } |
794 | ; | |
795 | ||
796 | ||
797 | /* Z.200, 5.3.6 */ | |
798 | ||
799 | operand_3 : operand_4 | |
800 | { | |
2e66cf7d | 801 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
802 | } |
803 | | operand_3 '+' operand_4 | |
804 | { | |
2e66cf7d | 805 | write_exp_elt_opcode (BINOP_ADD); |
e58de8a2 FF |
806 | } |
807 | | operand_3 '-' operand_4 | |
808 | { | |
2e66cf7d | 809 | write_exp_elt_opcode (BINOP_SUB); |
e58de8a2 FF |
810 | } |
811 | | operand_3 SLASH_SLASH operand_4 | |
812 | { | |
fcbadaee | 813 | write_exp_elt_opcode (BINOP_CONCAT); |
e58de8a2 FF |
814 | } |
815 | ; | |
816 | ||
817 | /* Z.200, 5.3.7 */ | |
818 | ||
819 | operand_4 : operand_5 | |
820 | { | |
2e66cf7d | 821 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
822 | } |
823 | | operand_4 '*' operand_5 | |
824 | { | |
2e66cf7d | 825 | write_exp_elt_opcode (BINOP_MUL); |
e58de8a2 FF |
826 | } |
827 | | operand_4 '/' operand_5 | |
828 | { | |
2e66cf7d | 829 | write_exp_elt_opcode (BINOP_DIV); |
e58de8a2 FF |
830 | } |
831 | | operand_4 MOD operand_5 | |
832 | { | |
76a0ffb4 | 833 | write_exp_elt_opcode (BINOP_MOD); |
e58de8a2 FF |
834 | } |
835 | | operand_4 REM operand_5 | |
836 | { | |
76a0ffb4 | 837 | write_exp_elt_opcode (BINOP_REM); |
e58de8a2 FF |
838 | } |
839 | ; | |
840 | ||
841 | /* Z.200, 5.3.8 */ | |
842 | ||
843 | operand_5 : operand_6 | |
844 | { | |
2e66cf7d | 845 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
846 | } |
847 | | '-' operand_6 | |
848 | { | |
2e66cf7d | 849 | write_exp_elt_opcode (UNOP_NEG); |
e58de8a2 FF |
850 | } |
851 | | NOT operand_6 | |
852 | { | |
2e66cf7d | 853 | write_exp_elt_opcode (UNOP_LOGICAL_NOT); |
e58de8a2 | 854 | } |
47f366bc | 855 | | parenthesised_expression literal |
8a177da6 PB |
856 | /* We require the string operand to be a literal, to avoid some |
857 | nasty parsing ambiguities. */ | |
e58de8a2 | 858 | { |
2fcc38b8 | 859 | write_exp_elt_opcode (BINOP_CONCAT); |
e58de8a2 FF |
860 | } |
861 | ; | |
862 | ||
863 | /* Z.200, 5.3.9 */ | |
864 | ||
bdef6b60 | 865 | operand_6 : POINTER primitive_value |
e58de8a2 | 866 | { |
8a177da6 | 867 | write_exp_elt_opcode (UNOP_ADDR); |
e58de8a2 FF |
868 | } |
869 | | RECEIVE buffer_location | |
870 | { | |
2e66cf7d | 871 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
872 | } |
873 | | primitive_value | |
874 | { | |
2e66cf7d | 875 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
876 | } |
877 | ; | |
878 | ||
879 | ||
45fe3db4 FF |
880 | /* Z.200, 6.2 */ |
881 | ||
81028ab0 | 882 | single_assignment_action : |
bdef6b60 | 883 | primitive_value GDB_ASSIGNMENT value |
45fe3db4 FF |
884 | { |
885 | write_exp_elt_opcode (BINOP_ASSIGN); | |
886 | } | |
81028ab0 FF |
887 | ; |
888 | ||
889 | /* Z.200, 6.20.3 */ | |
890 | ||
891 | chill_value_built_in_routine_call : | |
892 | NUM '(' expression ')' | |
893 | { | |
894 | $$ = 0; /* FIXME */ | |
895 | } | |
896 | | PRED '(' expression ')' | |
897 | { | |
898 | $$ = 0; /* FIXME */ | |
899 | } | |
900 | | SUCC '(' expression ')' | |
901 | { | |
902 | $$ = 0; /* FIXME */ | |
903 | } | |
904 | | ABS '(' expression ')' | |
905 | { | |
906 | $$ = 0; /* FIXME */ | |
907 | } | |
908 | | CARD '(' expression ')' | |
909 | { | |
910 | $$ = 0; /* FIXME */ | |
911 | } | |
57ffffe3 | 912 | | MAX_TOKEN '(' expression ')' |
81028ab0 FF |
913 | { |
914 | $$ = 0; /* FIXME */ | |
915 | } | |
57ffffe3 | 916 | | MIN_TOKEN '(' expression ')' |
81028ab0 FF |
917 | { |
918 | $$ = 0; /* FIXME */ | |
919 | } | |
58cda66e PB |
920 | | SIZE '(' expression ')' |
921 | { write_exp_elt_opcode (UNOP_SIZEOF); } | |
81028ab0 | 922 | | SIZE '(' mode_argument ')' |
58cda66e PB |
923 | { write_exp_elt_opcode (OP_LONG); |
924 | write_exp_elt_type (builtin_type_int); | |
925 | write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3)); | |
926 | write_exp_elt_opcode (OP_LONG); } | |
81028ab0 FF |
927 | | UPPER '(' upper_lower_argument ')' |
928 | { | |
929 | $$ = 0; /* FIXME */ | |
930 | } | |
931 | | LOWER '(' upper_lower_argument ')' | |
932 | { | |
933 | $$ = 0; /* FIXME */ | |
934 | } | |
935 | | LENGTH '(' length_argument ')' | |
936 | { | |
937 | $$ = 0; /* FIXME */ | |
938 | } | |
939 | ; | |
940 | ||
941 | mode_argument : mode_name | |
942 | { | |
58cda66e | 943 | $$ = $1.type; |
81028ab0 FF |
944 | } |
945 | | array_mode_name '(' expression ')' | |
946 | { | |
947 | $$ = 0; /* FIXME */ | |
948 | } | |
949 | | string_mode_name '(' expression ')' | |
950 | { | |
951 | $$ = 0; /* FIXME */ | |
952 | } | |
953 | | variant_structure_mode_name '(' expression_list ')' | |
954 | { | |
955 | $$ = 0; /* FIXME */ | |
956 | } | |
957 | ; | |
958 | ||
8a177da6 PB |
959 | mode_name : TYPENAME |
960 | ; | |
961 | ||
962 | upper_lower_argument : expression | |
81028ab0 FF |
963 | { |
964 | $$ = 0; /* FIXME */ | |
965 | } | |
966 | | mode_name | |
967 | { | |
968 | $$ = 0; /* FIXME */ | |
969 | } | |
970 | ; | |
971 | ||
8a177da6 | 972 | length_argument : expression |
81028ab0 FF |
973 | { |
974 | $$ = 0; /* FIXME */ | |
975 | } | |
976 | ; | |
45fe3db4 | 977 | |
e58de8a2 | 978 | /* Things which still need productions... */ |
54bbbfb4 | 979 | |
2fcc38b8 FF |
980 | array_mode_name : FIXME_08 { $$ = 0; } |
981 | string_mode_name : FIXME_09 { $$ = 0; } | |
982 | variant_structure_mode_name: FIXME_10 { $$ = 0; } | |
983 | synonym_name : FIXME_11 { $$ = 0; } | |
984 | value_enumeration_name : FIXME_12 { $$ = 0; } | |
985 | value_do_with_name : FIXME_13 { $$ = 0; } | |
986 | value_receive_name : FIXME_14 { $$ = 0; } | |
2fcc38b8 FF |
987 | boolean_expression : FIXME_26 { $$ = 0; } |
988 | case_selector_list : FIXME_27 { $$ = 0; } | |
989 | subexpression : FIXME_28 { $$ = 0; } | |
990 | case_label_specification: FIXME_29 { $$ = 0; } | |
991 | buffer_location : FIXME_30 { $$ = 0; } | |
e58de8a2 FF |
992 | |
993 | %% | |
994 | ||
c7da3ed3 FF |
995 | /* Implementation of a dynamically expandable buffer for processing input |
996 | characters acquired through lexptr and building a value to return in | |
997 | yylval. */ | |
998 | ||
999 | static char *tempbuf; /* Current buffer contents */ | |
1000 | static int tempbufsize; /* Size of allocated buffer */ | |
1001 | static int tempbufindex; /* Current index into buffer */ | |
1002 | ||
1003 | #define GROWBY_MIN_SIZE 64 /* Minimum amount to grow buffer by */ | |
1004 | ||
1005 | #define CHECKBUF(size) \ | |
1006 | do { \ | |
1007 | if (tempbufindex + (size) >= tempbufsize) \ | |
1008 | { \ | |
1009 | growbuf_by_size (size); \ | |
1010 | } \ | |
1011 | } while (0); | |
1012 | ||
1013 | /* Grow the static temp buffer if necessary, including allocating the first one | |
1014 | on demand. */ | |
1015 | ||
1016 | static void | |
1017 | growbuf_by_size (count) | |
1018 | int count; | |
1019 | { | |
1020 | int growby; | |
1021 | ||
1022 | growby = max (count, GROWBY_MIN_SIZE); | |
1023 | tempbufsize += growby; | |
1024 | if (tempbuf == NULL) | |
1025 | { | |
1026 | tempbuf = (char *) malloc (tempbufsize); | |
1027 | } | |
1028 | else | |
1029 | { | |
1030 | tempbuf = (char *) realloc (tempbuf, tempbufsize); | |
1031 | } | |
1032 | } | |
1033 | ||
cbd1bdc3 FF |
1034 | /* Try to consume a simple name string token. If successful, returns |
1035 | a pointer to a nullbyte terminated copy of the name that can be used | |
1036 | in symbol table lookups. If not successful, returns NULL. */ | |
1037 | ||
1038 | static char * | |
1039 | match_simple_name_string () | |
1040 | { | |
1041 | char *tokptr = lexptr; | |
1042 | ||
93dc3414 | 1043 | if (isalpha (*tokptr) || *tokptr == '_') |
cbd1bdc3 | 1044 | { |
5a7c9cce | 1045 | char *result; |
cbd1bdc3 FF |
1046 | do { |
1047 | tokptr++; | |
5a7c9cce | 1048 | } while (isalnum (*tokptr) || (*tokptr == '_')); |
cbd1bdc3 FF |
1049 | yylval.sval.ptr = lexptr; |
1050 | yylval.sval.length = tokptr - lexptr; | |
1051 | lexptr = tokptr; | |
5a7c9cce | 1052 | result = copy_name (yylval.sval); |
5a7c9cce | 1053 | return result; |
cbd1bdc3 FF |
1054 | } |
1055 | return (NULL); | |
1056 | } | |
1057 | ||
5d074aa9 FF |
1058 | /* Start looking for a value composed of valid digits as set by the base |
1059 | in use. Note that '_' characters are valid anywhere, in any quantity, | |
1060 | and are simply ignored. Since we must find at least one valid digit, | |
1061 | or reject this token as an integer literal, we keep track of how many | |
1062 | digits we have encountered. */ | |
1063 | ||
1064 | static int | |
1065 | decode_integer_value (base, tokptrptr, ivalptr) | |
1066 | int base; | |
1067 | char **tokptrptr; | |
1068 | int *ivalptr; | |
1069 | { | |
1070 | char *tokptr = *tokptrptr; | |
1071 | int temp; | |
1072 | int digits = 0; | |
1073 | ||
1074 | while (*tokptr != '\0') | |
1075 | { | |
db2302cb PS |
1076 | temp = *tokptr; |
1077 | if (isupper (temp)) | |
1078 | temp = tolower (temp); | |
5d074aa9 FF |
1079 | tokptr++; |
1080 | switch (temp) | |
1081 | { | |
1082 | case '_': | |
1083 | continue; | |
1084 | case '0': case '1': case '2': case '3': case '4': | |
1085 | case '5': case '6': case '7': case '8': case '9': | |
1086 | temp -= '0'; | |
1087 | break; | |
1088 | case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': | |
1089 | temp -= 'a'; | |
1090 | temp += 10; | |
1091 | break; | |
1092 | default: | |
1093 | temp = base; | |
1094 | break; | |
1095 | } | |
1096 | if (temp < base) | |
1097 | { | |
1098 | digits++; | |
1099 | *ivalptr *= base; | |
1100 | *ivalptr += temp; | |
1101 | } | |
1102 | else | |
1103 | { | |
1104 | /* Found something not in domain for current base. */ | |
1105 | tokptr--; /* Unconsume what gave us indigestion. */ | |
1106 | break; | |
1107 | } | |
1108 | } | |
1109 | ||
1110 | /* If we didn't find any digits, then we don't have a valid integer | |
1111 | value, so reject the entire token. Otherwise, update the lexical | |
1112 | scan pointer, and return non-zero for success. */ | |
1113 | ||
1114 | if (digits == 0) | |
1115 | { | |
1116 | return (0); | |
1117 | } | |
1118 | else | |
1119 | { | |
1120 | *tokptrptr = tokptr; | |
1121 | return (1); | |
1122 | } | |
1123 | } | |
1124 | ||
e58de8a2 | 1125 | static int |
2e66cf7d | 1126 | decode_integer_literal (valptr, tokptrptr) |
5d074aa9 FF |
1127 | int *valptr; |
1128 | char **tokptrptr; | |
e58de8a2 | 1129 | { |
2e66cf7d FF |
1130 | char *tokptr = *tokptrptr; |
1131 | int base = 0; | |
1132 | int ival = 0; | |
2e66cf7d FF |
1133 | int explicit_base = 0; |
1134 | ||
1135 | /* Look for an explicit base specifier, which is optional. */ | |
1136 | ||
1137 | switch (*tokptr) | |
1138 | { | |
1139 | case 'd': | |
1140 | case 'D': | |
1141 | explicit_base++; | |
1142 | base = 10; | |
1143 | tokptr++; | |
1144 | break; | |
1145 | case 'b': | |
1146 | case 'B': | |
1147 | explicit_base++; | |
1148 | base = 2; | |
1149 | tokptr++; | |
1150 | break; | |
1151 | case 'h': | |
1152 | case 'H': | |
1153 | explicit_base++; | |
1154 | base = 16; | |
1155 | tokptr++; | |
1156 | break; | |
1157 | case 'o': | |
1158 | case 'O': | |
1159 | explicit_base++; | |
1160 | base = 8; | |
1161 | tokptr++; | |
1162 | break; | |
1163 | default: | |
1164 | base = 10; | |
1165 | break; | |
1166 | } | |
1167 | ||
1168 | /* If we found an explicit base ensure that the character after the | |
1169 | explicit base is a single quote. */ | |
1170 | ||
1171 | if (explicit_base && (*tokptr++ != '\'')) | |
1172 | { | |
1173 | return (0); | |
1174 | } | |
1175 | ||
5d074aa9 FF |
1176 | /* Attempt to decode whatever follows as an integer value in the |
1177 | indicated base, updating the token pointer in the process and | |
1178 | computing the value into ival. Also, if we have an explicit | |
2e66cf7d | 1179 | base, then the next character must not be a single quote, or we |
5d074aa9 FF |
1180 | have a bitstring literal, so reject the entire token in this case. |
1181 | Otherwise, update the lexical scan pointer, and return non-zero | |
1182 | for success. */ | |
1183 | ||
1184 | if (!decode_integer_value (base, &tokptr, &ival)) | |
2e66cf7d FF |
1185 | { |
1186 | return (0); | |
1187 | } | |
1188 | else if (explicit_base && (*tokptr == '\'')) | |
1189 | { | |
1190 | return (0); | |
1191 | } | |
1192 | else | |
1193 | { | |
1194 | *valptr = ival; | |
1195 | *tokptrptr = tokptr; | |
1196 | return (1); | |
1197 | } | |
1198 | } | |
1199 | ||
1188fbbf FF |
1200 | /* If it wasn't for the fact that floating point values can contain '_' |
1201 | characters, we could just let strtod do all the hard work by letting it | |
1202 | try to consume as much of the current token buffer as possible and | |
1203 | find a legal conversion. Unfortunately we need to filter out the '_' | |
1204 | characters before calling strtod, which we do by copying the other | |
1205 | legal chars to a local buffer to be converted. However since we also | |
1206 | need to keep track of where the last unconsumed character in the input | |
1207 | buffer is, we have transfer only as many characters as may compose a | |
1208 | legal floating point value. */ | |
1209 | ||
1210 | static int | |
1211 | match_float_literal () | |
1212 | { | |
1213 | char *tokptr = lexptr; | |
1214 | char *buf; | |
1215 | char *copy; | |
1188fbbf FF |
1216 | double dval; |
1217 | extern double strtod (); | |
1218 | ||
1219 | /* Make local buffer in which to build the string to convert. This is | |
1220 | required because underscores are valid in chill floating point numbers | |
1221 | but not in the string passed to strtod to convert. The string will be | |
1222 | no longer than our input string. */ | |
1223 | ||
1224 | copy = buf = (char *) alloca (strlen (tokptr) + 1); | |
1225 | ||
1226 | /* Transfer all leading digits to the conversion buffer, discarding any | |
1227 | underscores. */ | |
1228 | ||
1229 | while (isdigit (*tokptr) || *tokptr == '_') | |
1230 | { | |
1231 | if (*tokptr != '_') | |
1232 | { | |
1233 | *copy++ = *tokptr; | |
1234 | } | |
1235 | tokptr++; | |
1236 | } | |
1237 | ||
1238 | /* Now accept either a '.', or one of [eEdD]. Dot is legal regardless | |
1239 | of whether we found any leading digits, and we simply accept it and | |
1240 | continue on to look for the fractional part and/or exponent. One of | |
1241 | [eEdD] is legal only if we have seen digits, and means that there | |
1242 | is no fractional part. If we find neither of these, then this is | |
1243 | not a floating point number, so return failure. */ | |
1244 | ||
1245 | switch (*tokptr++) | |
1246 | { | |
1247 | case '.': | |
1248 | /* Accept and then look for fractional part and/or exponent. */ | |
1249 | *copy++ = '.'; | |
1250 | break; | |
1251 | ||
1252 | case 'e': | |
1253 | case 'E': | |
1254 | case 'd': | |
1255 | case 'D': | |
1256 | if (copy == buf) | |
1257 | { | |
1258 | return (0); | |
1259 | } | |
1260 | *copy++ = 'e'; | |
1261 | goto collect_exponent; | |
1262 | break; | |
1263 | ||
1264 | default: | |
1265 | return (0); | |
1266 | break; | |
1267 | } | |
1268 | ||
1269 | /* We found a '.', copy any fractional digits to the conversion buffer, up | |
1270 | to the first nondigit, non-underscore character. */ | |
1271 | ||
1272 | while (isdigit (*tokptr) || *tokptr == '_') | |
1273 | { | |
1274 | if (*tokptr != '_') | |
1275 | { | |
1276 | *copy++ = *tokptr; | |
1277 | } | |
1278 | tokptr++; | |
1279 | } | |
1280 | ||
1281 | /* Look for an exponent, which must start with one of [eEdD]. If none | |
1282 | is found, jump directly to trying to convert what we have collected | |
1283 | so far. */ | |
1284 | ||
1285 | switch (*tokptr) | |
1286 | { | |
1287 | case 'e': | |
1288 | case 'E': | |
1289 | case 'd': | |
1290 | case 'D': | |
1291 | *copy++ = 'e'; | |
1292 | tokptr++; | |
1293 | break; | |
1294 | default: | |
1295 | goto convert_float; | |
1296 | break; | |
1297 | } | |
1298 | ||
1299 | /* Accept an optional '-' or '+' following one of [eEdD]. */ | |
1300 | ||
1301 | collect_exponent: | |
1302 | if (*tokptr == '+' || *tokptr == '-') | |
1303 | { | |
1304 | *copy++ = *tokptr++; | |
1305 | } | |
1306 | ||
1307 | /* Now copy an exponent into the conversion buffer. Note that at the | |
1308 | moment underscores are *not* allowed in exponents. */ | |
1309 | ||
1310 | while (isdigit (*tokptr)) | |
1311 | { | |
1312 | *copy++ = *tokptr++; | |
1313 | } | |
1314 | ||
1315 | /* If we transfered any chars to the conversion buffer, try to interpret its | |
1316 | contents as a floating point value. If any characters remain, then we | |
1317 | must not have a valid floating point string. */ | |
1318 | ||
1319 | convert_float: | |
1320 | *copy = '\0'; | |
1321 | if (copy != buf) | |
1322 | { | |
1323 | dval = strtod (buf, ©); | |
1324 | if (*copy == '\0') | |
1325 | { | |
1326 | yylval.dval = dval; | |
1327 | lexptr = tokptr; | |
1328 | return (FLOAT_LITERAL); | |
1329 | } | |
1330 | } | |
1331 | return (0); | |
1332 | } | |
1333 | ||
96b6b765 | 1334 | /* Recognize a string literal. A string literal is a sequence |
c7da3ed3 FF |
1335 | of characters enclosed in matching single or double quotes, except that |
1336 | a single character inside single quotes is a character literal, which | |
1337 | we reject as a string literal. To embed the terminator character inside | |
1338 | a string, it is simply doubled (I.E. "this""is""one""string") */ | |
1339 | ||
1340 | static int | |
1341 | match_string_literal () | |
1342 | { | |
1343 | char *tokptr = lexptr; | |
1344 | ||
1345 | for (tempbufindex = 0, tokptr++; *tokptr != '\0'; tokptr++) | |
1346 | { | |
1347 | CHECKBUF (1); | |
1348 | if (*tokptr == *lexptr) | |
1349 | { | |
1350 | if (*(tokptr + 1) == *lexptr) | |
1351 | { | |
1352 | tokptr++; | |
1353 | } | |
1354 | else | |
1355 | { | |
1356 | break; | |
1357 | } | |
1358 | } | |
1359 | tempbuf[tempbufindex++] = *tokptr; | |
1360 | } | |
1361 | if (*tokptr == '\0' /* no terminator */ | |
c7da3ed3 FF |
1362 | || (tempbufindex == 1 && *tokptr == '\'')) /* char literal */ |
1363 | { | |
1364 | return (0); | |
1365 | } | |
1366 | else | |
1367 | { | |
1368 | tempbuf[tempbufindex] = '\0'; | |
1369 | yylval.sval.ptr = tempbuf; | |
1370 | yylval.sval.length = tempbufindex; | |
1371 | lexptr = ++tokptr; | |
1372 | return (CHARACTER_STRING_LITERAL); | |
1373 | } | |
1374 | } | |
1375 | ||
2e66cf7d FF |
1376 | /* Recognize a character literal. A character literal is single character |
1377 | or a control sequence, enclosed in single quotes. A control sequence | |
1378 | is a comma separated list of one or more integer literals, enclosed | |
1379 | in parenthesis and introduced with a circumflex character. | |
1380 | ||
1381 | EX: 'a' '^(7)' '^(7,8)' | |
1382 | ||
5d074aa9 FF |
1383 | As a GNU chill extension, the syntax C'xx' is also recognized as a |
1384 | character literal, where xx is a hex value for the character. | |
1385 | ||
c7da3ed3 FF |
1386 | Note that more than a single character, enclosed in single quotes, is |
1387 | a string literal. | |
1388 | ||
c4413e2c FF |
1389 | Also note that the control sequence form is not in GNU Chill since it |
1390 | is ambiguous with the string literal form using single quotes. I.E. | |
1391 | is '^(7)' a character literal or a string literal. In theory it it | |
1392 | possible to tell by context, but GNU Chill doesn't accept the control | |
1393 | sequence form, so neither do we (for now the code is disabled). | |
1394 | ||
2e66cf7d FF |
1395 | Returns CHARACTER_LITERAL if a match is found. |
1396 | */ | |
1397 | ||
1398 | static int | |
1399 | match_character_literal () | |
1400 | { | |
1401 | char *tokptr = lexptr; | |
1402 | int ival = 0; | |
1403 | ||
db2302cb | 1404 | if ((*tokptr == 'c' || *tokptr == 'C') && (*(tokptr + 1) == '\'')) |
2e66cf7d | 1405 | { |
5d074aa9 FF |
1406 | /* We have a GNU chill extension form, so skip the leading "C'", |
1407 | decode the hex value, and then ensure that we have a trailing | |
1408 | single quote character. */ | |
2e66cf7d | 1409 | tokptr += 2; |
5d074aa9 | 1410 | if (!decode_integer_value (16, &tokptr, &ival) || (*tokptr != '\'')) |
e58de8a2 | 1411 | { |
2e66cf7d | 1412 | return (0); |
e58de8a2 | 1413 | } |
5d074aa9 | 1414 | tokptr++; |
2e66cf7d | 1415 | } |
5d074aa9 | 1416 | else if (*tokptr == '\'') |
2e66cf7d | 1417 | { |
5d074aa9 | 1418 | tokptr++; |
2e66cf7d | 1419 | |
5d074aa9 FF |
1420 | /* Determine which form we have, either a control sequence or the |
1421 | single character form. */ | |
1422 | ||
1423 | if ((*tokptr == '^') && (*(tokptr + 1) == '(')) | |
1424 | { | |
9da75ad3 | 1425 | #if 0 /* Disable, see note above. -fnf */ |
5d074aa9 FF |
1426 | /* Match and decode a control sequence. Return zero if we don't |
1427 | find a valid integer literal, or if the next unconsumed character | |
1428 | after the integer literal is not the trailing ')'. | |
1429 | FIXME: We currently don't handle the multiple integer literal | |
1430 | form. */ | |
1431 | tokptr += 2; | |
1432 | if (!decode_integer_literal (&ival, &tokptr) || (*tokptr++ != ')')) | |
1433 | { | |
1434 | return (0); | |
1435 | } | |
9da75ad3 FF |
1436 | #else |
1437 | return (0); | |
1438 | #endif | |
5d074aa9 FF |
1439 | } |
1440 | else | |
1441 | { | |
1442 | ival = *tokptr++; | |
1443 | } | |
1444 | ||
1445 | /* The trailing quote has not yet been consumed. If we don't find | |
1446 | it, then we have no match. */ | |
1447 | ||
1448 | if (*tokptr++ != '\'') | |
1449 | { | |
1450 | return (0); | |
1451 | } | |
2e66cf7d | 1452 | } |
aed656ba FF |
1453 | else |
1454 | { | |
1455 | /* Not a character literal. */ | |
1456 | return (0); | |
1457 | } | |
2e66cf7d FF |
1458 | yylval.typed_val.val = ival; |
1459 | yylval.typed_val.type = builtin_type_chill_char; | |
1460 | lexptr = tokptr; | |
1461 | return (CHARACTER_LITERAL); | |
e58de8a2 FF |
1462 | } |
1463 | ||
1464 | /* Recognize an integer literal, as specified in Z.200 sec 5.2.4.2. | |
1465 | Note that according to 5.2.4.2, a single "_" is also a valid integer | |
1466 | literal, however GNU-chill requires there to be at least one "digit" | |
1467 | in any integer literal. */ | |
1468 | ||
1469 | static int | |
2e66cf7d | 1470 | match_integer_literal () |
e58de8a2 | 1471 | { |
2e66cf7d | 1472 | char *tokptr = lexptr; |
ae0afa4b | 1473 | int ival; |
2e66cf7d | 1474 | |
ae0afa4b | 1475 | if (!decode_integer_literal (&ival, &tokptr)) |
2e66cf7d FF |
1476 | { |
1477 | return (0); | |
1478 | } | |
ae0afa4b | 1479 | else |
2e66cf7d FF |
1480 | { |
1481 | yylval.typed_val.val = ival; | |
1482 | yylval.typed_val.type = builtin_type_int; | |
1483 | lexptr = tokptr; | |
1484 | return (INTEGER_LITERAL); | |
1485 | } | |
e58de8a2 FF |
1486 | } |
1487 | ||
81028ab0 FF |
1488 | /* Recognize a bit-string literal, as specified in Z.200 sec 5.2.4.8 |
1489 | Note that according to 5.2.4.8, a single "_" is also a valid bit-string | |
1490 | literal, however GNU-chill requires there to be at least one "digit" | |
1491 | in any bit-string literal. */ | |
1492 | ||
1493 | static int | |
1494 | match_bitstring_literal () | |
1495 | { | |
6d34c236 | 1496 | register char *tokptr = lexptr; |
81028ab0 FF |
1497 | int bitoffset = 0; |
1498 | int bitcount = 0; | |
6d34c236 | 1499 | int bits_per_char; |
81028ab0 | 1500 | int digit; |
81028ab0 | 1501 | |
c7da3ed3 | 1502 | tempbufindex = 0; |
6d34c236 PB |
1503 | CHECKBUF (1); |
1504 | tempbuf[0] = 0; | |
c7da3ed3 | 1505 | |
81028ab0 FF |
1506 | /* Look for the required explicit base specifier. */ |
1507 | ||
1508 | switch (*tokptr++) | |
1509 | { | |
1510 | case 'b': | |
1511 | case 'B': | |
6d34c236 | 1512 | bits_per_char = 1; |
81028ab0 FF |
1513 | break; |
1514 | case 'o': | |
1515 | case 'O': | |
6d34c236 | 1516 | bits_per_char = 3; |
81028ab0 FF |
1517 | break; |
1518 | case 'h': | |
1519 | case 'H': | |
6d34c236 | 1520 | bits_per_char = 4; |
81028ab0 FF |
1521 | break; |
1522 | default: | |
1523 | return (0); | |
1524 | break; | |
1525 | } | |
6d34c236 | 1526 | |
81028ab0 FF |
1527 | /* Ensure that the character after the explicit base is a single quote. */ |
1528 | ||
1529 | if (*tokptr++ != '\'') | |
1530 | { | |
1531 | return (0); | |
1532 | } | |
1533 | ||
1534 | while (*tokptr != '\0' && *tokptr != '\'') | |
1535 | { | |
db2302cb PS |
1536 | digit = *tokptr; |
1537 | if (isupper (digit)) | |
1538 | digit = tolower (digit); | |
81028ab0 FF |
1539 | tokptr++; |
1540 | switch (digit) | |
1541 | { | |
1542 | case '_': | |
1543 | continue; | |
1544 | case '0': case '1': case '2': case '3': case '4': | |
1545 | case '5': case '6': case '7': case '8': case '9': | |
1546 | digit -= '0'; | |
1547 | break; | |
1548 | case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': | |
1549 | digit -= 'a'; | |
1550 | digit += 10; | |
1551 | break; | |
1552 | default: | |
1553 | return (0); | |
1554 | break; | |
1555 | } | |
6d34c236 | 1556 | if (digit >= 1 << bits_per_char) |
81028ab0 FF |
1557 | { |
1558 | /* Found something not in domain for current base. */ | |
1559 | return (0); | |
1560 | } | |
1561 | else | |
1562 | { | |
6d34c236 PB |
1563 | /* Extract bits from digit, packing them into the bitstring byte. */ |
1564 | int k = TARGET_BYTE_ORDER == BIG_ENDIAN ? bits_per_char - 1 : 0; | |
1565 | for (; TARGET_BYTE_ORDER == BIG_ENDIAN ? k >= 0 : k < bits_per_char; | |
1566 | TARGET_BYTE_ORDER == BIG_ENDIAN ? k-- : k++) | |
81028ab0 FF |
1567 | { |
1568 | bitcount++; | |
6d34c236 | 1569 | if (digit & (1 << k)) |
81028ab0 | 1570 | { |
6d34c236 PB |
1571 | tempbuf[tempbufindex] |= |
1572 | (TARGET_BYTE_ORDER == BIG_ENDIAN) | |
1573 | ? (1 << (HOST_CHAR_BIT - 1 - bitoffset)) | |
1574 | : (1 << bitoffset); | |
81028ab0 FF |
1575 | } |
1576 | bitoffset++; | |
1577 | if (bitoffset == HOST_CHAR_BIT) | |
1578 | { | |
1579 | bitoffset = 0; | |
1580 | tempbufindex++; | |
6d34c236 PB |
1581 | CHECKBUF(1); |
1582 | tempbuf[tempbufindex] = 0; | |
81028ab0 FF |
1583 | } |
1584 | } | |
1585 | } | |
1586 | } | |
1587 | ||
1588 | /* Verify that we consumed everything up to the trailing single quote, | |
1589 | and that we found some bits (IE not just underbars). */ | |
1590 | ||
1591 | if (*tokptr++ != '\'') | |
1592 | { | |
1593 | return (0); | |
1594 | } | |
1595 | else | |
1596 | { | |
1597 | yylval.sval.ptr = tempbuf; | |
1598 | yylval.sval.length = bitcount; | |
1599 | lexptr = tokptr; | |
1600 | return (BIT_STRING_LITERAL); | |
1601 | } | |
1602 | } | |
1603 | ||
45fe3db4 FF |
1604 | /* Recognize tokens that start with '$'. These include: |
1605 | ||
1606 | $regname A native register name or a "standard | |
1607 | register name". | |
1608 | Return token GDB_REGNAME. | |
1609 | ||
1610 | $variable A convenience variable with a name chosen | |
1611 | by the user. | |
1612 | Return token GDB_VARIABLE. | |
1613 | ||
1614 | $digits Value history with index <digits>, starting | |
1615 | from the first value which has index 1. | |
1616 | Return GDB_LAST. | |
1617 | ||
1618 | $$digits Value history with index <digits> relative | |
1619 | to the last value. I.E. $$0 is the last | |
1620 | value, $$1 is the one previous to that, $$2 | |
1621 | is the one previous to $$1, etc. | |
1622 | Return token GDB_LAST. | |
1623 | ||
1624 | $ | $0 | $$0 The last value in the value history. | |
1625 | Return token GDB_LAST. | |
1626 | ||
1627 | $$ An abbreviation for the second to the last | |
1628 | value in the value history, I.E. $$1 | |
1629 | Return token GDB_LAST. | |
1630 | ||
1631 | Note that we currently assume that register names and convenience | |
1632 | variables follow the convention of starting with a letter or '_'. | |
1633 | ||
1634 | */ | |
1635 | ||
1636 | static int | |
1637 | match_dollar_tokens () | |
1638 | { | |
1639 | char *tokptr; | |
1640 | int regno; | |
1641 | int namelength; | |
1642 | int negate; | |
1643 | int ival; | |
1644 | ||
1645 | /* We will always have a successful match, even if it is just for | |
1646 | a single '$', the abbreviation for $$0. So advance lexptr. */ | |
1647 | ||
1648 | tokptr = ++lexptr; | |
1649 | ||
1650 | if (*tokptr == '_' || isalpha (*tokptr)) | |
1651 | { | |
1652 | /* Look for a match with a native register name, usually something | |
1653 | like "r0" for example. */ | |
1654 | ||
1655 | for (regno = 0; regno < NUM_REGS; regno++) | |
1656 | { | |
1657 | namelength = strlen (reg_names[regno]); | |
1658 | if (STREQN (tokptr, reg_names[regno], namelength) | |
1659 | && !isalnum (tokptr[namelength])) | |
1660 | { | |
1661 | yylval.lval = regno; | |
cba00921 | 1662 | lexptr += namelength; |
45fe3db4 FF |
1663 | return (GDB_REGNAME); |
1664 | } | |
1665 | } | |
1666 | ||
1667 | /* Look for a match with a standard register name, usually something | |
1668 | like "pc", which gdb always recognizes as the program counter | |
1669 | regardless of what the native register name is. */ | |
1670 | ||
1671 | for (regno = 0; regno < num_std_regs; regno++) | |
1672 | { | |
1673 | namelength = strlen (std_regs[regno].name); | |
1674 | if (STREQN (tokptr, std_regs[regno].name, namelength) | |
1675 | && !isalnum (tokptr[namelength])) | |
1676 | { | |
1677 | yylval.lval = std_regs[regno].regnum; | |
1678 | lexptr += namelength; | |
1679 | return (GDB_REGNAME); | |
1680 | } | |
1681 | } | |
1682 | ||
1683 | /* Attempt to match against a convenience variable. Note that | |
1684 | this will always succeed, because if no variable of that name | |
1685 | already exists, the lookup_internalvar will create one for us. | |
1686 | Also note that both lexptr and tokptr currently point to the | |
1687 | start of the input string we are trying to match, and that we | |
1688 | have already tested the first character for non-numeric, so we | |
1689 | don't have to treat it specially. */ | |
1690 | ||
1691 | while (*tokptr == '_' || isalnum (*tokptr)) | |
1692 | { | |
1693 | tokptr++; | |
1694 | } | |
1695 | yylval.sval.ptr = lexptr; | |
1696 | yylval.sval.length = tokptr - lexptr; | |
1697 | yylval.ivar = lookup_internalvar (copy_name (yylval.sval)); | |
1698 | lexptr = tokptr; | |
1699 | return (GDB_VARIABLE); | |
1700 | } | |
1701 | ||
1702 | /* Since we didn't match against a register name or convenience | |
1703 | variable, our only choice left is a history value. */ | |
1704 | ||
1705 | if (*tokptr == '$') | |
1706 | { | |
1707 | negate = 1; | |
1708 | ival = 1; | |
1709 | tokptr++; | |
1710 | } | |
1711 | else | |
1712 | { | |
1713 | negate = 0; | |
1714 | ival = 0; | |
1715 | } | |
1716 | ||
1717 | /* Attempt to decode more characters as an integer value giving | |
1718 | the index in the history list. If successful, the value will | |
1719 | overwrite ival (currently 0 or 1), and if not, ival will be | |
1720 | left alone, which is good since it is currently correct for | |
1721 | the '$' or '$$' case. */ | |
1722 | ||
1723 | decode_integer_literal (&ival, &tokptr); | |
1724 | yylval.lval = negate ? -ival : ival; | |
1725 | lexptr = tokptr; | |
1726 | return (GDB_LAST); | |
1727 | } | |
1728 | ||
e58de8a2 FF |
1729 | struct token |
1730 | { | |
1731 | char *operator; | |
1732 | int token; | |
1733 | }; | |
1734 | ||
5a7c9cce | 1735 | static const struct token idtokentab[] = |
81028ab0 | 1736 | { |
835c2559 | 1737 | { "array", ARRAY }, |
5a7c9cce PB |
1738 | { "length", LENGTH }, |
1739 | { "lower", LOWER }, | |
1740 | { "upper", UPPER }, | |
1741 | { "andif", ANDIF }, | |
1742 | { "pred", PRED }, | |
1743 | { "succ", SUCC }, | |
1744 | { "card", CARD }, | |
1745 | { "size", SIZE }, | |
1746 | { "orif", ORIF }, | |
1747 | { "num", NUM }, | |
1748 | { "abs", ABS }, | |
57ffffe3 JG |
1749 | { "max", MAX_TOKEN }, |
1750 | { "min", MIN_TOKEN }, | |
5a7c9cce PB |
1751 | { "mod", MOD }, |
1752 | { "rem", REM }, | |
1753 | { "not", NOT }, | |
1754 | { "xor", LOGXOR }, | |
1755 | { "and", LOGAND }, | |
1756 | { "in", IN }, | |
2d67c7e9 | 1757 | { "or", LOGIOR }, |
f91a9e05 | 1758 | { "up", UP }, |
2d67c7e9 | 1759 | { "null", EMPTINESS_LITERAL } |
e58de8a2 FF |
1760 | }; |
1761 | ||
a8a69e63 | 1762 | static const struct token tokentab2[] = |
e58de8a2 | 1763 | { |
45fe3db4 | 1764 | { ":=", GDB_ASSIGNMENT }, |
e58de8a2 | 1765 | { "//", SLASH_SLASH }, |
8a177da6 | 1766 | { "->", POINTER }, |
e58de8a2 FF |
1767 | { "/=", NOTEQUAL }, |
1768 | { "<=", LEQ }, | |
5a7c9cce | 1769 | { ">=", GTR } |
e58de8a2 FF |
1770 | }; |
1771 | ||
1772 | /* Read one token, getting characters through lexptr. */ | |
1773 | /* This is where we will check to make sure that the language and the | |
1774 | operators used are compatible. */ | |
1775 | ||
1776 | static int | |
1777 | yylex () | |
1778 | { | |
1779 | unsigned int i; | |
1780 | int token; | |
ad86f717 | 1781 | char *inputname; |
cbd1bdc3 | 1782 | struct symbol *sym; |
e58de8a2 FF |
1783 | |
1784 | /* Skip over any leading whitespace. */ | |
1785 | while (isspace (*lexptr)) | |
1786 | { | |
1787 | lexptr++; | |
1788 | } | |
1789 | /* Look for special single character cases which can't be the first | |
1790 | character of some other multicharacter token. */ | |
1791 | switch (*lexptr) | |
1792 | { | |
1793 | case '\0': | |
1794 | return (0); | |
54bbbfb4 | 1795 | case ',': |
e58de8a2 | 1796 | case '=': |
e58de8a2 FF |
1797 | case ';': |
1798 | case '!': | |
1799 | case '+': | |
e58de8a2 | 1800 | case '*': |
e58de8a2 FF |
1801 | case '(': |
1802 | case ')': | |
1803 | case '[': | |
1804 | case ']': | |
1805 | return (*lexptr++); | |
1806 | } | |
1807 | /* Look for characters which start a particular kind of multicharacter | |
45fe3db4 | 1808 | token, such as a character literal, register name, convenience |
c7da3ed3 | 1809 | variable name, string literal, etc. */ |
e58de8a2 | 1810 | switch (*lexptr) |
2e66cf7d | 1811 | { |
c7da3ed3 FF |
1812 | case '\'': |
1813 | case '\"': | |
96b6b765 | 1814 | /* First try to match a string literal, which is any |
c7da3ed3 FF |
1815 | sequence of characters enclosed in matching single or double |
1816 | quotes, except that a single character inside single quotes | |
1817 | is a character literal, so we have to catch that case also. */ | |
1818 | token = match_string_literal (); | |
1819 | if (token != 0) | |
1820 | { | |
1821 | return (token); | |
1822 | } | |
1823 | if (*lexptr == '\'') | |
1824 | { | |
1825 | token = match_character_literal (); | |
1826 | if (token != 0) | |
1827 | { | |
1828 | return (token); | |
1829 | } | |
1830 | } | |
1831 | break; | |
5d074aa9 FF |
1832 | case 'C': |
1833 | case 'c': | |
2e66cf7d FF |
1834 | token = match_character_literal (); |
1835 | if (token != 0) | |
1836 | { | |
1837 | return (token); | |
1838 | } | |
1839 | break; | |
45fe3db4 FF |
1840 | case '$': |
1841 | token = match_dollar_tokens (); | |
1842 | if (token != 0) | |
1843 | { | |
1844 | return (token); | |
1845 | } | |
1846 | break; | |
2e66cf7d | 1847 | } |
e58de8a2 FF |
1848 | /* See if it is a special token of length 2. */ |
1849 | for (i = 0; i < sizeof (tokentab2) / sizeof (tokentab2[0]); i++) | |
1850 | { | |
45fe3db4 | 1851 | if (STREQN (lexptr, tokentab2[i].operator, 2)) |
e58de8a2 FF |
1852 | { |
1853 | lexptr += 2; | |
1854 | return (tokentab2[i].token); | |
1855 | } | |
1856 | } | |
1857 | /* Look for single character cases which which could be the first | |
1858 | character of some other multicharacter token, but aren't, or we | |
1859 | would already have found it. */ | |
1860 | switch (*lexptr) | |
1861 | { | |
8a177da6 | 1862 | case '-': |
45fe3db4 | 1863 | case ':': |
e58de8a2 FF |
1864 | case '/': |
1865 | case '<': | |
1866 | case '>': | |
1867 | return (*lexptr++); | |
1868 | } | |
1188fbbf FF |
1869 | /* Look for a float literal before looking for an integer literal, so |
1870 | we match as much of the input stream as possible. */ | |
1871 | token = match_float_literal (); | |
81028ab0 FF |
1872 | if (token != 0) |
1873 | { | |
1874 | return (token); | |
1875 | } | |
1876 | token = match_bitstring_literal (); | |
1188fbbf FF |
1877 | if (token != 0) |
1878 | { | |
1879 | return (token); | |
1880 | } | |
2e66cf7d | 1881 | token = match_integer_literal (); |
cbd1bdc3 | 1882 | if (token != 0) |
e58de8a2 FF |
1883 | { |
1884 | return (token); | |
1885 | } | |
cbd1bdc3 FF |
1886 | |
1887 | /* Try to match a simple name string, and if a match is found, then | |
1888 | further classify what sort of name it is and return an appropriate | |
1889 | token. Note that attempting to match a simple name string consumes | |
1890 | the token from lexptr, so we can't back out if we later find that | |
1891 | we can't classify what sort of name it is. */ | |
1892 | ||
ad86f717 | 1893 | inputname = match_simple_name_string (); |
5a7c9cce | 1894 | |
ad86f717 | 1895 | if (inputname != NULL) |
cbd1bdc3 | 1896 | { |
a30e2087 | 1897 | char *simplename = (char*) alloca (strlen (inputname) + 1); |
ad86f717 PB |
1898 | |
1899 | char *dptr = simplename, *sptr = inputname; | |
1900 | for (; *sptr; sptr++) | |
1901 | *dptr++ = isupper (*sptr) ? tolower(*sptr) : *sptr; | |
a30e2087 | 1902 | *dptr = '\0'; |
ad86f717 | 1903 | |
d8f23320 PS |
1904 | /* See if it is a reserved identifier. */ |
1905 | for (i = 0; i < sizeof (idtokentab) / sizeof (idtokentab[0]); i++) | |
1906 | { | |
1907 | if (STREQ (simplename, idtokentab[i].operator)) | |
1908 | { | |
1909 | return (idtokentab[i].token); | |
1910 | } | |
1911 | } | |
1912 | ||
1913 | /* Look for other special tokens. */ | |
1914 | if (STREQ (simplename, "true")) | |
1915 | { | |
1916 | yylval.ulval = 1; | |
1917 | return (BOOLEAN_LITERAL); | |
1918 | } | |
1919 | if (STREQ (simplename, "false")) | |
1920 | { | |
1921 | yylval.ulval = 0; | |
1922 | return (BOOLEAN_LITERAL); | |
1923 | } | |
1924 | ||
ad86f717 | 1925 | sym = lookup_symbol (inputname, expression_context_block, |
cbd1bdc3 FF |
1926 | VAR_NAMESPACE, (int *) NULL, |
1927 | (struct symtab **) NULL); | |
ad86f717 PB |
1928 | if (sym == NULL && strcmp (inputname, simplename) != 0) |
1929 | { | |
1930 | sym = lookup_symbol (simplename, expression_context_block, | |
1931 | VAR_NAMESPACE, (int *) NULL, | |
1932 | (struct symtab **) NULL); | |
1933 | } | |
cbd1bdc3 FF |
1934 | if (sym != NULL) |
1935 | { | |
1936 | yylval.ssym.stoken.ptr = NULL; | |
1937 | yylval.ssym.stoken.length = 0; | |
1938 | yylval.ssym.sym = sym; | |
1939 | yylval.ssym.is_a_field_of_this = 0; /* FIXME, C++'ism */ | |
1940 | switch (SYMBOL_CLASS (sym)) | |
1941 | { | |
1942 | case LOC_BLOCK: | |
1943 | /* Found a procedure name. */ | |
1944 | return (GENERAL_PROCEDURE_NAME); | |
1945 | case LOC_STATIC: | |
1946 | /* Found a global or local static variable. */ | |
1947 | return (LOCATION_NAME); | |
a8a69e63 FF |
1948 | case LOC_REGISTER: |
1949 | case LOC_ARG: | |
1950 | case LOC_REF_ARG: | |
1951 | case LOC_REGPARM: | |
996ccb30 | 1952 | case LOC_REGPARM_ADDR: |
a8a69e63 | 1953 | case LOC_LOCAL: |
76a0ffb4 | 1954 | case LOC_LOCAL_ARG: |
a1c8d76e JK |
1955 | case LOC_BASEREG: |
1956 | case LOC_BASEREG_ARG: | |
76a0ffb4 FF |
1957 | if (innermost_block == NULL |
1958 | || contained_in (block_found, innermost_block)) | |
1959 | { | |
1960 | innermost_block = block_found; | |
1961 | } | |
1962 | return (LOCATION_NAME); | |
1963 | break; | |
1964 | case LOC_CONST: | |
a8a69e63 | 1965 | case LOC_LABEL: |
76a0ffb4 FF |
1966 | return (LOCATION_NAME); |
1967 | break; | |
76a0ffb4 | 1968 | case LOC_TYPEDEF: |
8a177da6 PB |
1969 | yylval.tsym.type = SYMBOL_TYPE (sym); |
1970 | return TYPENAME; | |
1971 | case LOC_UNDEF: | |
a8a69e63 | 1972 | case LOC_CONST_BYTES: |
0848ad1c | 1973 | case LOC_OPTIMIZED_OUT: |
ad86f717 | 1974 | error ("Symbol \"%s\" names no location.", inputname); |
a8a69e63 | 1975 | break; |
cbd1bdc3 FF |
1976 | } |
1977 | } | |
1978 | else if (!have_full_symbols () && !have_partial_symbols ()) | |
1979 | { | |
1980 | error ("No symbol table is loaded. Use the \"file\" command."); | |
1981 | } | |
1982 | else | |
1983 | { | |
ad86f717 | 1984 | error ("No symbol \"%s\" in current context.", inputname); |
cbd1bdc3 FF |
1985 | } |
1986 | } | |
1987 | ||
1188fbbf FF |
1988 | /* Catch single character tokens which are not part of some |
1989 | longer token. */ | |
1990 | ||
1991 | switch (*lexptr) | |
1992 | { | |
1993 | case '.': /* Not float for example. */ | |
8a177da6 PB |
1994 | lexptr++; |
1995 | while (isspace (*lexptr)) lexptr++; | |
ad86f717 PB |
1996 | inputname = match_simple_name_string (); |
1997 | if (!inputname) | |
8a177da6 PB |
1998 | return '.'; |
1999 | return FIELD_NAME; | |
1188fbbf FF |
2000 | } |
2001 | ||
e58de8a2 FF |
2002 | return (ILLEGAL_TOKEN); |
2003 | } | |
2004 | ||
22e39759 | 2005 | void |
e58de8a2 | 2006 | yyerror (msg) |
8db1a922 | 2007 | char *msg; |
e58de8a2 | 2008 | { |
8db1a922 | 2009 | error ("A %s in expression, near `%s'.", (msg ? msg : "error"), lexptr); |
e58de8a2 | 2010 | } |