]>
Commit | Line | Data |
---|---|---|
e58de8a2 FF |
1 | /* YACC grammar for Chill expressions, for GDB. |
2 | Copyright (C) 1992 Free Software Foundation, Inc. | |
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" |
e58de8a2 FF |
57 | #include "expression.h" |
58 | #include "language.h" | |
59 | #include "value.h" | |
60 | #include "parser-defs.h" | |
22e39759 | 61 | #include "ch-lang.h" |
e58de8a2 | 62 | |
19d0f3f4 FF |
63 | /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc), |
64 | as well as gratuitiously global symbol names, so we can have multiple | |
65 | yacc generated parsers in gdb. Note that these are only the variables | |
66 | produced by yacc. If other parser generators (bison, byacc, etc) produce | |
67 | additional global names that conflict at link time, then those parser | |
68 | generators need to be fixed instead of adding those names to this list. */ | |
69 | ||
e58de8a2 FF |
70 | #define yymaxdepth chill_maxdepth |
71 | #define yyparse chill_parse | |
72 | #define yylex chill_lex | |
73 | #define yyerror chill_error | |
74 | #define yylval chill_lval | |
75 | #define yychar chill_char | |
76 | #define yydebug chill_debug | |
77 | #define yypact chill_pact | |
78 | #define yyr1 chill_r1 | |
79 | #define yyr2 chill_r2 | |
80 | #define yydef chill_def | |
81 | #define yychk chill_chk | |
82 | #define yypgo chill_pgo | |
83 | #define yyact chill_act | |
84 | #define yyexca chill_exca | |
85 | #define yyerrflag chill_errflag | |
86 | #define yynerrs chill_nerrs | |
87 | #define yyps chill_ps | |
88 | #define yypv chill_pv | |
89 | #define yys chill_s | |
90 | #define yy_yys chill_yys | |
91 | #define yystate chill_state | |
92 | #define yytmp chill_tmp | |
93 | #define yyv chill_v | |
94 | #define yy_yyv chill_yyv | |
95 | #define yyval chill_val | |
96 | #define yylloc chill_lloc | |
45fe3db4 FF |
97 | #define yyreds chill_reds /* With YYDEBUG defined */ |
98 | #define yytoks chill_toks /* With YYDEBUG defined */ | |
19d0f3f4 FF |
99 | |
100 | #ifndef YYDEBUG | |
101 | #define YYDEBUG 0 /* Default to no yydebug support */ | |
102 | #endif | |
103 | ||
104 | int | |
105 | yyparse PARAMS ((void)); | |
e58de8a2 FF |
106 | |
107 | static int | |
108 | yylex PARAMS ((void)); | |
109 | ||
22e39759 | 110 | void |
e58de8a2 FF |
111 | yyerror PARAMS ((char *)); |
112 | ||
e58de8a2 FF |
113 | %} |
114 | ||
115 | /* Although the yacc "value" of an expression is not used, | |
116 | since the result is stored in the structure being created, | |
117 | other node types do have values. */ | |
118 | ||
119 | %union | |
120 | { | |
121 | LONGEST lval; | |
122 | unsigned LONGEST ulval; | |
123 | struct { | |
124 | LONGEST val; | |
125 | struct type *type; | |
126 | } typed_val; | |
127 | double dval; | |
128 | struct symbol *sym; | |
129 | struct type *tval; | |
130 | struct stoken sval; | |
131 | struct ttype tsym; | |
132 | struct symtoken ssym; | |
133 | int voidval; | |
134 | struct block *bval; | |
135 | enum exp_opcode opcode; | |
136 | struct internalvar *ivar; | |
137 | ||
138 | struct type **tvec; | |
139 | int *ivec; | |
140 | } | |
141 | ||
e58de8a2 FF |
142 | %token <voidval> FIXME |
143 | ||
144 | %token <typed_val> INTEGER_LITERAL | |
145 | %token <ulval> BOOLEAN_LITERAL | |
2e66cf7d | 146 | %token <typed_val> CHARACTER_LITERAL |
1188fbbf | 147 | %token <dval> FLOAT_LITERAL |
cbd1bdc3 FF |
148 | %token <ssym> GENERAL_PROCEDURE_NAME |
149 | %token <ssym> LOCATION_NAME | |
e58de8a2 FF |
150 | %token <voidval> SET_LITERAL |
151 | %token <voidval> EMPTINESS_LITERAL | |
152 | %token <voidval> CHARACTER_STRING_LITERAL | |
153 | %token <voidval> BIT_STRING_LITERAL | |
154 | ||
155 | %token <voidval> STRING | |
156 | %token <voidval> CONSTANT | |
157 | %token <voidval> '.' | |
158 | %token <voidval> ';' | |
159 | %token <voidval> ':' | |
160 | %token <voidval> CASE | |
161 | %token <voidval> OF | |
162 | %token <voidval> ESAC | |
163 | %token <voidval> LOGIOR | |
164 | %token <voidval> ORIF | |
165 | %token <voidval> LOGXOR | |
166 | %token <voidval> LOGAND | |
167 | %token <voidval> ANDIF | |
168 | %token <voidval> '=' | |
169 | %token <voidval> NOTEQUAL | |
170 | %token <voidval> '>' | |
171 | %token <voidval> GTR | |
172 | %token <voidval> '<' | |
173 | %token <voidval> LEQ | |
174 | %token <voidval> IN | |
175 | %token <voidval> '+' | |
176 | %token <voidval> '-' | |
177 | %token <voidval> '*' | |
178 | %token <voidval> '/' | |
179 | %token <voidval> SLASH_SLASH | |
180 | %token <voidval> MOD | |
181 | %token <voidval> REM | |
182 | %token <voidval> NOT | |
183 | %token <voidval> POINTER | |
184 | %token <voidval> RECEIVE | |
185 | %token <voidval> SC | |
186 | %token <voidval> '[' | |
187 | %token <voidval> ']' | |
188 | %token <voidval> '(' | |
189 | %token <voidval> ')' | |
190 | %token <voidval> UP | |
191 | %token <voidval> IF | |
192 | %token <voidval> THEN | |
193 | %token <voidval> ELSE | |
194 | %token <voidval> FI | |
195 | %token <voidval> ELSIF | |
196 | %token <voidval> ILLEGAL_TOKEN | |
197 | ||
45fe3db4 FF |
198 | /* Tokens which are not Chill tokens used in expressions, but rather GDB |
199 | specific things that we recognize in the same context as Chill tokens | |
200 | (register names for example). */ | |
201 | ||
202 | %token <lval> GDB_REGNAME /* Machine register name */ | |
203 | %token <lval> GDB_LAST /* Value history */ | |
204 | %token <ivar> GDB_VARIABLE /* Convenience variable */ | |
205 | %token <voidval> GDB_ASSIGNMENT /* Assign value to somewhere */ | |
206 | ||
e58de8a2 | 207 | %type <voidval> location |
cbd1bdc3 | 208 | %type <voidval> access_name |
e58de8a2 FF |
209 | %type <voidval> primitive_value |
210 | %type <voidval> location_contents | |
211 | %type <voidval> value_name | |
212 | %type <voidval> literal | |
213 | %type <voidval> tuple | |
214 | %type <voidval> value_string_element | |
215 | %type <voidval> value_string_slice | |
216 | %type <voidval> value_array_element | |
217 | %type <voidval> value_array_slice | |
218 | %type <voidval> value_structure_field | |
219 | %type <voidval> expression_conversion | |
220 | %type <voidval> value_procedure_call | |
221 | %type <voidval> value_built_in_routine_call | |
222 | %type <voidval> start_expression | |
223 | %type <voidval> zero_adic_operator | |
224 | %type <voidval> parenthesised_expression | |
225 | %type <voidval> value | |
226 | %type <voidval> undefined_value | |
227 | %type <voidval> expression | |
228 | %type <voidval> conditional_expression | |
229 | %type <voidval> then_alternative | |
230 | %type <voidval> else_alternative | |
231 | %type <voidval> sub_expression | |
232 | %type <voidval> value_case_alternative | |
233 | %type <voidval> operand_0 | |
234 | %type <voidval> operand_1 | |
235 | %type <voidval> operand_2 | |
236 | %type <voidval> operand_3 | |
237 | %type <voidval> operand_4 | |
238 | %type <voidval> operand_5 | |
239 | %type <voidval> operand_6 | |
240 | %type <voidval> integer_literal_expression | |
241 | %type <voidval> synonym_name | |
242 | %type <voidval> value_enumeration_name | |
243 | %type <voidval> value_do_with_name | |
244 | %type <voidval> value_receive_name | |
e58de8a2 FF |
245 | %type <voidval> string_primitive_value |
246 | %type <voidval> start_element | |
247 | %type <voidval> left_element | |
248 | %type <voidval> right_element | |
249 | %type <voidval> slice_size | |
250 | %type <voidval> array_primitive_value | |
251 | %type <voidval> expression_list | |
252 | %type <voidval> lower_element | |
253 | %type <voidval> upper_element | |
254 | %type <voidval> first_element | |
255 | %type <voidval> structure_primitive_value | |
256 | %type <voidval> field_name | |
257 | %type <voidval> mode_name | |
258 | %type <voidval> boolean_expression | |
259 | %type <voidval> case_selector_list | |
260 | %type <voidval> subexpression | |
261 | %type <voidval> case_label_specification | |
262 | %type <voidval> buffer_location | |
263 | ||
45fe3db4 FF |
264 | %type <voidval> single_assignment_action |
265 | ||
e58de8a2 FF |
266 | %% |
267 | ||
268 | /* Z.200, 5.3.1 */ | |
269 | ||
270 | value : expression | |
271 | { | |
2e66cf7d | 272 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
273 | } |
274 | | undefined_value | |
275 | { | |
2e66cf7d | 276 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
277 | } |
278 | ; | |
279 | ||
280 | undefined_value : FIXME | |
281 | { | |
2e66cf7d | 282 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
283 | } |
284 | ; | |
285 | ||
286 | /* Z.200, 4.2.1 */ | |
287 | ||
cbd1bdc3 FF |
288 | location : access_name |
289 | { | |
290 | $$ = 0; /* FIXME */ | |
291 | } | |
292 | | FIXME | |
293 | { | |
294 | $$ = 0; /* FIXME */ | |
295 | } | |
296 | ; | |
297 | ||
298 | /* Z.200, 4.2.2 */ | |
299 | ||
300 | access_name : LOCATION_NAME | |
301 | { | |
302 | write_exp_elt_opcode (OP_VAR_VALUE); | |
303 | write_exp_elt_sym ($1.sym); | |
304 | write_exp_elt_opcode (OP_VAR_VALUE); | |
305 | } | |
45fe3db4 FF |
306 | | GDB_LAST /* gdb specific */ |
307 | { | |
308 | write_exp_elt_opcode (OP_LAST); | |
309 | write_exp_elt_longcst ($1); | |
310 | write_exp_elt_opcode (OP_LAST); | |
311 | } | |
312 | | GDB_REGNAME /* gdb specific */ | |
313 | { | |
314 | write_exp_elt_opcode (OP_REGISTER); | |
315 | write_exp_elt_longcst ($1); | |
316 | write_exp_elt_opcode (OP_REGISTER); | |
317 | } | |
318 | | GDB_VARIABLE /* gdb specific */ | |
319 | { | |
320 | write_exp_elt_opcode (OP_INTERNALVAR); | |
321 | write_exp_elt_intern ($1); | |
322 | write_exp_elt_opcode (OP_INTERNALVAR); | |
323 | } | |
cbd1bdc3 | 324 | | FIXME |
e58de8a2 | 325 | { |
2e66cf7d | 326 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
327 | } |
328 | ; | |
329 | ||
54bbbfb4 FF |
330 | /* Z.200, 4.2.8 */ |
331 | ||
332 | expression_list : expression | |
333 | { | |
334 | arglist_len = 1; | |
335 | } | |
336 | | expression_list ',' expression | |
337 | { | |
338 | arglist_len++; | |
339 | } | |
340 | ||
e58de8a2 FF |
341 | /* Z.200, 5.2.1 */ |
342 | ||
343 | primitive_value : location_contents | |
344 | { | |
2e66cf7d | 345 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
346 | } |
347 | | value_name | |
348 | { | |
2e66cf7d | 349 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
350 | } |
351 | | literal | |
352 | { | |
2e66cf7d | 353 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
354 | } |
355 | | tuple | |
356 | { | |
2e66cf7d | 357 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
358 | } |
359 | | value_string_element | |
360 | { | |
2e66cf7d | 361 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
362 | } |
363 | | value_string_slice | |
364 | { | |
2e66cf7d | 365 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
366 | } |
367 | | value_array_element | |
368 | { | |
2e66cf7d | 369 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
370 | } |
371 | | value_array_slice | |
372 | { | |
2e66cf7d | 373 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
374 | } |
375 | | value_structure_field | |
376 | { | |
2e66cf7d | 377 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
378 | } |
379 | | expression_conversion | |
380 | { | |
2e66cf7d | 381 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
382 | } |
383 | | value_procedure_call | |
384 | { | |
2e66cf7d | 385 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
386 | } |
387 | | value_built_in_routine_call | |
388 | { | |
2e66cf7d | 389 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
390 | } |
391 | | start_expression | |
392 | { | |
2e66cf7d | 393 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
394 | } |
395 | | zero_adic_operator | |
396 | { | |
2e66cf7d | 397 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
398 | } |
399 | | parenthesised_expression | |
400 | { | |
2e66cf7d | 401 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
402 | } |
403 | ; | |
404 | ||
405 | /* Z.200, 5.2.2 */ | |
406 | ||
407 | location_contents: location | |
408 | { | |
2e66cf7d | 409 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
410 | } |
411 | ; | |
412 | ||
413 | /* Z.200, 5.2.3 */ | |
414 | ||
415 | value_name : synonym_name | |
416 | { | |
2e66cf7d | 417 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
418 | } |
419 | | value_enumeration_name | |
420 | { | |
2e66cf7d | 421 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
422 | } |
423 | | value_do_with_name | |
424 | { | |
2e66cf7d | 425 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
426 | } |
427 | | value_receive_name | |
428 | { | |
2e66cf7d | 429 | $$ = 0; /* FIXME */ |
e58de8a2 | 430 | } |
cbd1bdc3 | 431 | | GENERAL_PROCEDURE_NAME |
e58de8a2 | 432 | { |
cbd1bdc3 FF |
433 | write_exp_elt_opcode (OP_VAR_VALUE); |
434 | write_exp_elt_sym ($1.sym); | |
435 | write_exp_elt_opcode (OP_VAR_VALUE); | |
e58de8a2 FF |
436 | } |
437 | ; | |
438 | ||
439 | /* Z.200, 5.2.4.1 */ | |
440 | ||
441 | literal : INTEGER_LITERAL | |
442 | { | |
2e66cf7d FF |
443 | write_exp_elt_opcode (OP_LONG); |
444 | write_exp_elt_type ($1.type); | |
445 | write_exp_elt_longcst ((LONGEST) ($1.val)); | |
446 | write_exp_elt_opcode (OP_LONG); | |
e58de8a2 FF |
447 | } |
448 | | BOOLEAN_LITERAL | |
449 | { | |
2e66cf7d FF |
450 | write_exp_elt_opcode (OP_BOOL); |
451 | write_exp_elt_longcst ((LONGEST) $1); | |
452 | write_exp_elt_opcode (OP_BOOL); | |
e58de8a2 FF |
453 | } |
454 | | CHARACTER_LITERAL | |
455 | { | |
2e66cf7d FF |
456 | write_exp_elt_opcode (OP_LONG); |
457 | write_exp_elt_type ($1.type); | |
458 | write_exp_elt_longcst ((LONGEST) ($1.val)); | |
459 | write_exp_elt_opcode (OP_LONG); | |
e58de8a2 | 460 | } |
1188fbbf FF |
461 | | FLOAT_LITERAL |
462 | { | |
463 | write_exp_elt_opcode (OP_DOUBLE); | |
464 | write_exp_elt_type (builtin_type_double); | |
465 | write_exp_elt_dblcst ($1); | |
466 | write_exp_elt_opcode (OP_DOUBLE); | |
467 | } | |
e58de8a2 FF |
468 | | SET_LITERAL |
469 | { | |
2e66cf7d | 470 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
471 | } |
472 | | EMPTINESS_LITERAL | |
473 | { | |
2e66cf7d | 474 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
475 | } |
476 | | CHARACTER_STRING_LITERAL | |
477 | { | |
2e66cf7d | 478 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
479 | } |
480 | | BIT_STRING_LITERAL | |
481 | { | |
2e66cf7d | 482 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
483 | } |
484 | ; | |
485 | ||
486 | /* Z.200, 5.2.5 */ | |
487 | ||
488 | tuple : FIXME | |
489 | { | |
2e66cf7d | 490 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
491 | } |
492 | ; | |
493 | ||
494 | ||
495 | /* Z.200, 5.2.6 */ | |
496 | ||
497 | value_string_element: string_primitive_value '(' start_element ')' | |
498 | { | |
2e66cf7d | 499 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
500 | } |
501 | ; | |
502 | ||
503 | /* Z.200, 5.2.7 */ | |
504 | ||
505 | value_string_slice: string_primitive_value '(' left_element ':' right_element ')' | |
506 | { | |
2e66cf7d | 507 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
508 | } |
509 | | string_primitive_value '(' start_element UP slice_size ')' | |
510 | { | |
2e66cf7d | 511 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
512 | } |
513 | ; | |
514 | ||
515 | /* Z.200, 5.2.8 */ | |
516 | ||
54bbbfb4 FF |
517 | value_array_element: array_primitive_value '(' |
518 | /* This is to save the value of arglist_len | |
519 | being accumulated for each dimension. */ | |
520 | { start_arglist (); } | |
521 | expression_list ')' | |
e58de8a2 | 522 | { |
54bbbfb4 FF |
523 | write_exp_elt_opcode (MULTI_SUBSCRIPT); |
524 | write_exp_elt_longcst ((LONGEST) end_arglist ()); | |
525 | write_exp_elt_opcode (MULTI_SUBSCRIPT); | |
e58de8a2 FF |
526 | } |
527 | ; | |
528 | ||
529 | /* Z.200, 5.2.9 */ | |
530 | ||
531 | value_array_slice: array_primitive_value '(' lower_element ':' upper_element ')' | |
532 | { | |
2e66cf7d | 533 | $$ = 0; /* FIXME */ |
e58de8a2 | 534 | } |
a9b37611 | 535 | | array_primitive_value '(' first_element UP slice_size ')' |
e58de8a2 | 536 | { |
2e66cf7d | 537 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
538 | } |
539 | ; | |
540 | ||
541 | /* Z.200, 5.2.10 */ | |
542 | ||
543 | value_structure_field: structure_primitive_value '.' field_name | |
544 | { | |
2e66cf7d | 545 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
546 | } |
547 | ; | |
548 | ||
549 | /* Z.200, 5.2.11 */ | |
550 | ||
551 | expression_conversion: mode_name '(' expression ')' | |
552 | { | |
2e66cf7d | 553 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
554 | } |
555 | ; | |
556 | ||
557 | /* Z.200, 5.2.12 */ | |
558 | ||
559 | value_procedure_call: FIXME | |
560 | { | |
2e66cf7d | 561 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
562 | } |
563 | ; | |
564 | ||
565 | /* Z.200, 5.2.13 */ | |
566 | ||
567 | value_built_in_routine_call: FIXME | |
568 | { | |
2e66cf7d | 569 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
570 | } |
571 | ; | |
572 | ||
573 | /* Z.200, 5.2.14 */ | |
574 | ||
575 | start_expression: FIXME | |
576 | { | |
2e66cf7d | 577 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
578 | } /* Not in GNU-Chill */ |
579 | ; | |
580 | ||
581 | /* Z.200, 5.2.15 */ | |
582 | ||
583 | zero_adic_operator: FIXME | |
584 | { | |
2e66cf7d | 585 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
586 | } |
587 | ; | |
588 | ||
589 | /* Z.200, 5.2.16 */ | |
590 | ||
591 | parenthesised_expression: '(' expression ')' | |
592 | { | |
2e66cf7d | 593 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
594 | } |
595 | ; | |
596 | ||
597 | /* Z.200, 5.3.2 */ | |
598 | ||
599 | expression : operand_0 | |
600 | { | |
2e66cf7d | 601 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
602 | } |
603 | | conditional_expression | |
604 | { | |
2e66cf7d | 605 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
606 | } |
607 | ; | |
608 | ||
609 | conditional_expression : IF boolean_expression then_alternative else_alternative FI | |
610 | { | |
2e66cf7d | 611 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
612 | } |
613 | | CASE case_selector_list OF value_case_alternative '[' ELSE sub_expression ']' ESAC | |
614 | { | |
2e66cf7d | 615 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
616 | } |
617 | ; | |
618 | ||
619 | then_alternative: THEN subexpression | |
620 | { | |
2e66cf7d | 621 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
622 | } |
623 | ; | |
624 | ||
625 | else_alternative: ELSE subexpression | |
626 | { | |
2e66cf7d | 627 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
628 | } |
629 | | ELSIF boolean_expression then_alternative else_alternative | |
630 | { | |
2e66cf7d | 631 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
632 | } |
633 | ; | |
634 | ||
635 | sub_expression : expression | |
636 | { | |
2e66cf7d | 637 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
638 | } |
639 | ; | |
640 | ||
641 | value_case_alternative: case_label_specification ':' sub_expression ';' | |
642 | { | |
2e66cf7d | 643 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
644 | } |
645 | ; | |
646 | ||
647 | /* Z.200, 5.3.3 */ | |
648 | ||
649 | operand_0 : operand_1 | |
650 | { | |
2e66cf7d | 651 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
652 | } |
653 | | operand_0 LOGIOR operand_1 | |
654 | { | |
2e66cf7d | 655 | write_exp_elt_opcode (BINOP_BITWISE_IOR); |
e58de8a2 FF |
656 | } |
657 | | operand_0 ORIF operand_1 | |
658 | { | |
2e66cf7d | 659 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
660 | } |
661 | | operand_0 LOGXOR operand_1 | |
662 | { | |
2e66cf7d | 663 | write_exp_elt_opcode (BINOP_BITWISE_XOR); |
e58de8a2 | 664 | } |
45fe3db4 FF |
665 | | single_assignment_action |
666 | { | |
667 | $$ = 0; /* FIXME */ | |
668 | } | |
e58de8a2 FF |
669 | ; |
670 | ||
671 | /* Z.200, 5.3.4 */ | |
672 | ||
673 | operand_1 : operand_2 | |
674 | { | |
2e66cf7d | 675 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
676 | } |
677 | | operand_1 LOGAND operand_2 | |
678 | { | |
2e66cf7d | 679 | write_exp_elt_opcode (BINOP_BITWISE_AND); |
e58de8a2 FF |
680 | } |
681 | | operand_1 ANDIF operand_2 | |
682 | { | |
2e66cf7d | 683 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
684 | } |
685 | ; | |
686 | ||
687 | /* Z.200, 5.3.5 */ | |
688 | ||
689 | operand_2 : operand_3 | |
690 | { | |
2e66cf7d | 691 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
692 | } |
693 | | operand_2 '=' operand_3 | |
694 | { | |
2e66cf7d | 695 | write_exp_elt_opcode (BINOP_EQUAL); |
e58de8a2 FF |
696 | } |
697 | | operand_2 NOTEQUAL operand_3 | |
698 | { | |
2e66cf7d | 699 | write_exp_elt_opcode (BINOP_NOTEQUAL); |
e58de8a2 FF |
700 | } |
701 | | operand_2 '>' operand_3 | |
702 | { | |
2e66cf7d | 703 | write_exp_elt_opcode (BINOP_GTR); |
e58de8a2 FF |
704 | } |
705 | | operand_2 GTR operand_3 | |
706 | { | |
2e66cf7d | 707 | write_exp_elt_opcode (BINOP_GEQ); |
e58de8a2 FF |
708 | } |
709 | | operand_2 '<' operand_3 | |
710 | { | |
2e66cf7d | 711 | write_exp_elt_opcode (BINOP_LESS); |
e58de8a2 FF |
712 | } |
713 | | operand_2 LEQ operand_3 | |
714 | { | |
2e66cf7d | 715 | write_exp_elt_opcode (BINOP_LEQ); |
e58de8a2 FF |
716 | } |
717 | | operand_2 IN operand_3 | |
718 | { | |
2e66cf7d | 719 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
720 | } |
721 | ; | |
722 | ||
723 | ||
724 | /* Z.200, 5.3.6 */ | |
725 | ||
726 | operand_3 : operand_4 | |
727 | { | |
2e66cf7d | 728 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
729 | } |
730 | | operand_3 '+' operand_4 | |
731 | { | |
2e66cf7d | 732 | write_exp_elt_opcode (BINOP_ADD); |
e58de8a2 FF |
733 | } |
734 | | operand_3 '-' operand_4 | |
735 | { | |
2e66cf7d | 736 | write_exp_elt_opcode (BINOP_SUB); |
e58de8a2 FF |
737 | } |
738 | | operand_3 SLASH_SLASH operand_4 | |
739 | { | |
2e66cf7d | 740 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
741 | } |
742 | ; | |
743 | ||
744 | /* Z.200, 5.3.7 */ | |
745 | ||
746 | operand_4 : operand_5 | |
747 | { | |
2e66cf7d | 748 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
749 | } |
750 | | operand_4 '*' operand_5 | |
751 | { | |
2e66cf7d | 752 | write_exp_elt_opcode (BINOP_MUL); |
e58de8a2 FF |
753 | } |
754 | | operand_4 '/' operand_5 | |
755 | { | |
2e66cf7d | 756 | write_exp_elt_opcode (BINOP_DIV); |
e58de8a2 FF |
757 | } |
758 | | operand_4 MOD operand_5 | |
759 | { | |
2e66cf7d | 760 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
761 | } |
762 | | operand_4 REM operand_5 | |
763 | { | |
2e66cf7d | 764 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
765 | } |
766 | ; | |
767 | ||
768 | /* Z.200, 5.3.8 */ | |
769 | ||
770 | operand_5 : operand_6 | |
771 | { | |
2e66cf7d | 772 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
773 | } |
774 | | '-' operand_6 | |
775 | { | |
2e66cf7d | 776 | write_exp_elt_opcode (UNOP_NEG); |
e58de8a2 FF |
777 | } |
778 | | NOT operand_6 | |
779 | { | |
2e66cf7d | 780 | write_exp_elt_opcode (UNOP_LOGICAL_NOT); |
e58de8a2 FF |
781 | } |
782 | | '(' integer_literal_expression ')' operand_6 | |
783 | { | |
2e66cf7d | 784 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
785 | } |
786 | ; | |
787 | ||
788 | /* Z.200, 5.3.9 */ | |
789 | ||
790 | operand_6 : POINTER location | |
791 | { | |
2e66cf7d | 792 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
793 | } |
794 | | RECEIVE buffer_location | |
795 | { | |
2e66cf7d | 796 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
797 | } |
798 | | primitive_value | |
799 | { | |
2e66cf7d | 800 | $$ = 0; /* FIXME */ |
e58de8a2 FF |
801 | } |
802 | ; | |
803 | ||
804 | ||
45fe3db4 FF |
805 | /* Z.200, 6.2 */ |
806 | ||
807 | single_assignment_action : location GDB_ASSIGNMENT value | |
808 | { | |
809 | write_exp_elt_opcode (BINOP_ASSIGN); | |
810 | } | |
811 | ||
e58de8a2 FF |
812 | /* Z.200, 12.4.3 */ |
813 | /* FIXME: For now we just accept only a single integer literal. */ | |
814 | ||
815 | integer_literal_expression: | |
816 | INTEGER_LITERAL | |
817 | { | |
2e66cf7d | 818 | $$ = 0; |
e58de8a2 FF |
819 | } |
820 | ||
54bbbfb4 FF |
821 | /* Z.200, 12.4.3 */ |
822 | ||
823 | array_primitive_value : primitive_value | |
824 | { | |
825 | $$ = 0; | |
826 | } | |
827 | ||
828 | ||
e58de8a2 | 829 | /* Things which still need productions... */ |
54bbbfb4 | 830 | |
e58de8a2 FF |
831 | synonym_name : FIXME { $$ = 0; } |
832 | value_enumeration_name : FIXME { $$ = 0; } | |
833 | value_do_with_name : FIXME { $$ = 0; } | |
834 | value_receive_name : FIXME { $$ = 0; } | |
e58de8a2 FF |
835 | string_primitive_value : FIXME { $$ = 0; } |
836 | start_element : FIXME { $$ = 0; } | |
837 | left_element : FIXME { $$ = 0; } | |
838 | right_element : FIXME { $$ = 0; } | |
839 | slice_size : FIXME { $$ = 0; } | |
e58de8a2 FF |
840 | lower_element : FIXME { $$ = 0; } |
841 | upper_element : FIXME { $$ = 0; } | |
842 | first_element : FIXME { $$ = 0; } | |
843 | structure_primitive_value: FIXME { $$ = 0; } | |
844 | field_name : FIXME { $$ = 0; } | |
845 | mode_name : FIXME { $$ = 0; } | |
846 | boolean_expression : FIXME { $$ = 0; } | |
847 | case_selector_list : FIXME { $$ = 0; } | |
848 | subexpression : FIXME { $$ = 0; } | |
849 | case_label_specification: FIXME { $$ = 0; } | |
850 | buffer_location : FIXME { $$ = 0; } | |
851 | ||
852 | %% | |
853 | ||
cbd1bdc3 FF |
854 | /* Try to consume a simple name string token. If successful, returns |
855 | a pointer to a nullbyte terminated copy of the name that can be used | |
856 | in symbol table lookups. If not successful, returns NULL. */ | |
857 | ||
858 | static char * | |
859 | match_simple_name_string () | |
860 | { | |
861 | char *tokptr = lexptr; | |
862 | ||
863 | if (isalpha (*tokptr)) | |
864 | { | |
865 | do { | |
866 | tokptr++; | |
867 | } while (isalpha (*tokptr) || isdigit (*tokptr) || (*tokptr == '_')); | |
868 | yylval.sval.ptr = lexptr; | |
869 | yylval.sval.length = tokptr - lexptr; | |
870 | lexptr = tokptr; | |
871 | return (copy_name (yylval.sval)); | |
872 | } | |
873 | return (NULL); | |
874 | } | |
875 | ||
5d074aa9 FF |
876 | /* Start looking for a value composed of valid digits as set by the base |
877 | in use. Note that '_' characters are valid anywhere, in any quantity, | |
878 | and are simply ignored. Since we must find at least one valid digit, | |
879 | or reject this token as an integer literal, we keep track of how many | |
880 | digits we have encountered. */ | |
881 | ||
882 | static int | |
883 | decode_integer_value (base, tokptrptr, ivalptr) | |
884 | int base; | |
885 | char **tokptrptr; | |
886 | int *ivalptr; | |
887 | { | |
888 | char *tokptr = *tokptrptr; | |
889 | int temp; | |
890 | int digits = 0; | |
891 | ||
892 | while (*tokptr != '\0') | |
893 | { | |
894 | temp = tolower (*tokptr); | |
895 | tokptr++; | |
896 | switch (temp) | |
897 | { | |
898 | case '_': | |
899 | continue; | |
900 | case '0': case '1': case '2': case '3': case '4': | |
901 | case '5': case '6': case '7': case '8': case '9': | |
902 | temp -= '0'; | |
903 | break; | |
904 | case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': | |
905 | temp -= 'a'; | |
906 | temp += 10; | |
907 | break; | |
908 | default: | |
909 | temp = base; | |
910 | break; | |
911 | } | |
912 | if (temp < base) | |
913 | { | |
914 | digits++; | |
915 | *ivalptr *= base; | |
916 | *ivalptr += temp; | |
917 | } | |
918 | else | |
919 | { | |
920 | /* Found something not in domain for current base. */ | |
921 | tokptr--; /* Unconsume what gave us indigestion. */ | |
922 | break; | |
923 | } | |
924 | } | |
925 | ||
926 | /* If we didn't find any digits, then we don't have a valid integer | |
927 | value, so reject the entire token. Otherwise, update the lexical | |
928 | scan pointer, and return non-zero for success. */ | |
929 | ||
930 | if (digits == 0) | |
931 | { | |
932 | return (0); | |
933 | } | |
934 | else | |
935 | { | |
936 | *tokptrptr = tokptr; | |
937 | return (1); | |
938 | } | |
939 | } | |
940 | ||
e58de8a2 | 941 | static int |
2e66cf7d | 942 | decode_integer_literal (valptr, tokptrptr) |
5d074aa9 FF |
943 | int *valptr; |
944 | char **tokptrptr; | |
e58de8a2 | 945 | { |
2e66cf7d FF |
946 | char *tokptr = *tokptrptr; |
947 | int base = 0; | |
948 | int ival = 0; | |
2e66cf7d FF |
949 | int explicit_base = 0; |
950 | ||
951 | /* Look for an explicit base specifier, which is optional. */ | |
952 | ||
953 | switch (*tokptr) | |
954 | { | |
955 | case 'd': | |
956 | case 'D': | |
957 | explicit_base++; | |
958 | base = 10; | |
959 | tokptr++; | |
960 | break; | |
961 | case 'b': | |
962 | case 'B': | |
963 | explicit_base++; | |
964 | base = 2; | |
965 | tokptr++; | |
966 | break; | |
967 | case 'h': | |
968 | case 'H': | |
969 | explicit_base++; | |
970 | base = 16; | |
971 | tokptr++; | |
972 | break; | |
973 | case 'o': | |
974 | case 'O': | |
975 | explicit_base++; | |
976 | base = 8; | |
977 | tokptr++; | |
978 | break; | |
979 | default: | |
980 | base = 10; | |
981 | break; | |
982 | } | |
983 | ||
984 | /* If we found an explicit base ensure that the character after the | |
985 | explicit base is a single quote. */ | |
986 | ||
987 | if (explicit_base && (*tokptr++ != '\'')) | |
988 | { | |
989 | return (0); | |
990 | } | |
991 | ||
5d074aa9 FF |
992 | /* Attempt to decode whatever follows as an integer value in the |
993 | indicated base, updating the token pointer in the process and | |
994 | computing the value into ival. Also, if we have an explicit | |
2e66cf7d | 995 | base, then the next character must not be a single quote, or we |
5d074aa9 FF |
996 | have a bitstring literal, so reject the entire token in this case. |
997 | Otherwise, update the lexical scan pointer, and return non-zero | |
998 | for success. */ | |
999 | ||
1000 | if (!decode_integer_value (base, &tokptr, &ival)) | |
2e66cf7d FF |
1001 | { |
1002 | return (0); | |
1003 | } | |
1004 | else if (explicit_base && (*tokptr == '\'')) | |
1005 | { | |
1006 | return (0); | |
1007 | } | |
1008 | else | |
1009 | { | |
1010 | *valptr = ival; | |
1011 | *tokptrptr = tokptr; | |
1012 | return (1); | |
1013 | } | |
1014 | } | |
1015 | ||
1188fbbf FF |
1016 | /* If it wasn't for the fact that floating point values can contain '_' |
1017 | characters, we could just let strtod do all the hard work by letting it | |
1018 | try to consume as much of the current token buffer as possible and | |
1019 | find a legal conversion. Unfortunately we need to filter out the '_' | |
1020 | characters before calling strtod, which we do by copying the other | |
1021 | legal chars to a local buffer to be converted. However since we also | |
1022 | need to keep track of where the last unconsumed character in the input | |
1023 | buffer is, we have transfer only as many characters as may compose a | |
1024 | legal floating point value. */ | |
1025 | ||
1026 | static int | |
1027 | match_float_literal () | |
1028 | { | |
1029 | char *tokptr = lexptr; | |
1030 | char *buf; | |
1031 | char *copy; | |
1032 | char ch; | |
1033 | double dval; | |
1034 | extern double strtod (); | |
1035 | ||
1036 | /* Make local buffer in which to build the string to convert. This is | |
1037 | required because underscores are valid in chill floating point numbers | |
1038 | but not in the string passed to strtod to convert. The string will be | |
1039 | no longer than our input string. */ | |
1040 | ||
1041 | copy = buf = (char *) alloca (strlen (tokptr) + 1); | |
1042 | ||
1043 | /* Transfer all leading digits to the conversion buffer, discarding any | |
1044 | underscores. */ | |
1045 | ||
1046 | while (isdigit (*tokptr) || *tokptr == '_') | |
1047 | { | |
1048 | if (*tokptr != '_') | |
1049 | { | |
1050 | *copy++ = *tokptr; | |
1051 | } | |
1052 | tokptr++; | |
1053 | } | |
1054 | ||
1055 | /* Now accept either a '.', or one of [eEdD]. Dot is legal regardless | |
1056 | of whether we found any leading digits, and we simply accept it and | |
1057 | continue on to look for the fractional part and/or exponent. One of | |
1058 | [eEdD] is legal only if we have seen digits, and means that there | |
1059 | is no fractional part. If we find neither of these, then this is | |
1060 | not a floating point number, so return failure. */ | |
1061 | ||
1062 | switch (*tokptr++) | |
1063 | { | |
1064 | case '.': | |
1065 | /* Accept and then look for fractional part and/or exponent. */ | |
1066 | *copy++ = '.'; | |
1067 | break; | |
1068 | ||
1069 | case 'e': | |
1070 | case 'E': | |
1071 | case 'd': | |
1072 | case 'D': | |
1073 | if (copy == buf) | |
1074 | { | |
1075 | return (0); | |
1076 | } | |
1077 | *copy++ = 'e'; | |
1078 | goto collect_exponent; | |
1079 | break; | |
1080 | ||
1081 | default: | |
1082 | return (0); | |
1083 | break; | |
1084 | } | |
1085 | ||
1086 | /* We found a '.', copy any fractional digits to the conversion buffer, up | |
1087 | to the first nondigit, non-underscore character. */ | |
1088 | ||
1089 | while (isdigit (*tokptr) || *tokptr == '_') | |
1090 | { | |
1091 | if (*tokptr != '_') | |
1092 | { | |
1093 | *copy++ = *tokptr; | |
1094 | } | |
1095 | tokptr++; | |
1096 | } | |
1097 | ||
1098 | /* Look for an exponent, which must start with one of [eEdD]. If none | |
1099 | is found, jump directly to trying to convert what we have collected | |
1100 | so far. */ | |
1101 | ||
1102 | switch (*tokptr) | |
1103 | { | |
1104 | case 'e': | |
1105 | case 'E': | |
1106 | case 'd': | |
1107 | case 'D': | |
1108 | *copy++ = 'e'; | |
1109 | tokptr++; | |
1110 | break; | |
1111 | default: | |
1112 | goto convert_float; | |
1113 | break; | |
1114 | } | |
1115 | ||
1116 | /* Accept an optional '-' or '+' following one of [eEdD]. */ | |
1117 | ||
1118 | collect_exponent: | |
1119 | if (*tokptr == '+' || *tokptr == '-') | |
1120 | { | |
1121 | *copy++ = *tokptr++; | |
1122 | } | |
1123 | ||
1124 | /* Now copy an exponent into the conversion buffer. Note that at the | |
1125 | moment underscores are *not* allowed in exponents. */ | |
1126 | ||
1127 | while (isdigit (*tokptr)) | |
1128 | { | |
1129 | *copy++ = *tokptr++; | |
1130 | } | |
1131 | ||
1132 | /* If we transfered any chars to the conversion buffer, try to interpret its | |
1133 | contents as a floating point value. If any characters remain, then we | |
1134 | must not have a valid floating point string. */ | |
1135 | ||
1136 | convert_float: | |
1137 | *copy = '\0'; | |
1138 | if (copy != buf) | |
1139 | { | |
1140 | dval = strtod (buf, ©); | |
1141 | if (*copy == '\0') | |
1142 | { | |
1143 | yylval.dval = dval; | |
1144 | lexptr = tokptr; | |
1145 | return (FLOAT_LITERAL); | |
1146 | } | |
1147 | } | |
1148 | return (0); | |
1149 | } | |
1150 | ||
2e66cf7d FF |
1151 | /* Recognize a character literal. A character literal is single character |
1152 | or a control sequence, enclosed in single quotes. A control sequence | |
1153 | is a comma separated list of one or more integer literals, enclosed | |
1154 | in parenthesis and introduced with a circumflex character. | |
1155 | ||
1156 | EX: 'a' '^(7)' '^(7,8)' | |
1157 | ||
5d074aa9 FF |
1158 | As a GNU chill extension, the syntax C'xx' is also recognized as a |
1159 | character literal, where xx is a hex value for the character. | |
1160 | ||
2e66cf7d FF |
1161 | Returns CHARACTER_LITERAL if a match is found. |
1162 | */ | |
1163 | ||
1164 | static int | |
1165 | match_character_literal () | |
1166 | { | |
1167 | char *tokptr = lexptr; | |
1168 | int ival = 0; | |
1169 | ||
5d074aa9 | 1170 | if ((tolower (*tokptr) == 'c') && (*(tokptr + 1) == '\'')) |
2e66cf7d | 1171 | { |
5d074aa9 FF |
1172 | /* We have a GNU chill extension form, so skip the leading "C'", |
1173 | decode the hex value, and then ensure that we have a trailing | |
1174 | single quote character. */ | |
2e66cf7d | 1175 | tokptr += 2; |
5d074aa9 | 1176 | if (!decode_integer_value (16, &tokptr, &ival) || (*tokptr != '\'')) |
e58de8a2 | 1177 | { |
2e66cf7d | 1178 | return (0); |
e58de8a2 | 1179 | } |
5d074aa9 | 1180 | tokptr++; |
2e66cf7d | 1181 | } |
5d074aa9 | 1182 | else if (*tokptr == '\'') |
2e66cf7d | 1183 | { |
5d074aa9 | 1184 | tokptr++; |
2e66cf7d | 1185 | |
5d074aa9 FF |
1186 | /* Determine which form we have, either a control sequence or the |
1187 | single character form. */ | |
1188 | ||
1189 | if ((*tokptr == '^') && (*(tokptr + 1) == '(')) | |
1190 | { | |
1191 | /* Match and decode a control sequence. Return zero if we don't | |
1192 | find a valid integer literal, or if the next unconsumed character | |
1193 | after the integer literal is not the trailing ')'. | |
1194 | FIXME: We currently don't handle the multiple integer literal | |
1195 | form. */ | |
1196 | tokptr += 2; | |
1197 | if (!decode_integer_literal (&ival, &tokptr) || (*tokptr++ != ')')) | |
1198 | { | |
1199 | return (0); | |
1200 | } | |
1201 | } | |
1202 | else | |
1203 | { | |
1204 | ival = *tokptr++; | |
1205 | } | |
1206 | ||
1207 | /* The trailing quote has not yet been consumed. If we don't find | |
1208 | it, then we have no match. */ | |
1209 | ||
1210 | if (*tokptr++ != '\'') | |
1211 | { | |
1212 | return (0); | |
1213 | } | |
2e66cf7d | 1214 | } |
aed656ba FF |
1215 | else |
1216 | { | |
1217 | /* Not a character literal. */ | |
1218 | return (0); | |
1219 | } | |
2e66cf7d FF |
1220 | yylval.typed_val.val = ival; |
1221 | yylval.typed_val.type = builtin_type_chill_char; | |
1222 | lexptr = tokptr; | |
1223 | return (CHARACTER_LITERAL); | |
e58de8a2 FF |
1224 | } |
1225 | ||
1226 | /* Recognize an integer literal, as specified in Z.200 sec 5.2.4.2. | |
1227 | Note that according to 5.2.4.2, a single "_" is also a valid integer | |
1228 | literal, however GNU-chill requires there to be at least one "digit" | |
1229 | in any integer literal. */ | |
1230 | ||
1231 | static int | |
2e66cf7d | 1232 | match_integer_literal () |
e58de8a2 | 1233 | { |
2e66cf7d | 1234 | char *tokptr = lexptr; |
ae0afa4b | 1235 | int ival; |
2e66cf7d | 1236 | |
ae0afa4b | 1237 | if (!decode_integer_literal (&ival, &tokptr)) |
2e66cf7d FF |
1238 | { |
1239 | return (0); | |
1240 | } | |
ae0afa4b | 1241 | else |
2e66cf7d FF |
1242 | { |
1243 | yylval.typed_val.val = ival; | |
1244 | yylval.typed_val.type = builtin_type_int; | |
1245 | lexptr = tokptr; | |
1246 | return (INTEGER_LITERAL); | |
1247 | } | |
e58de8a2 FF |
1248 | } |
1249 | ||
45fe3db4 FF |
1250 | /* Recognize tokens that start with '$'. These include: |
1251 | ||
1252 | $regname A native register name or a "standard | |
1253 | register name". | |
1254 | Return token GDB_REGNAME. | |
1255 | ||
1256 | $variable A convenience variable with a name chosen | |
1257 | by the user. | |
1258 | Return token GDB_VARIABLE. | |
1259 | ||
1260 | $digits Value history with index <digits>, starting | |
1261 | from the first value which has index 1. | |
1262 | Return GDB_LAST. | |
1263 | ||
1264 | $$digits Value history with index <digits> relative | |
1265 | to the last value. I.E. $$0 is the last | |
1266 | value, $$1 is the one previous to that, $$2 | |
1267 | is the one previous to $$1, etc. | |
1268 | Return token GDB_LAST. | |
1269 | ||
1270 | $ | $0 | $$0 The last value in the value history. | |
1271 | Return token GDB_LAST. | |
1272 | ||
1273 | $$ An abbreviation for the second to the last | |
1274 | value in the value history, I.E. $$1 | |
1275 | Return token GDB_LAST. | |
1276 | ||
1277 | Note that we currently assume that register names and convenience | |
1278 | variables follow the convention of starting with a letter or '_'. | |
1279 | ||
1280 | */ | |
1281 | ||
1282 | static int | |
1283 | match_dollar_tokens () | |
1284 | { | |
1285 | char *tokptr; | |
1286 | int regno; | |
1287 | int namelength; | |
1288 | int negate; | |
1289 | int ival; | |
1290 | ||
1291 | /* We will always have a successful match, even if it is just for | |
1292 | a single '$', the abbreviation for $$0. So advance lexptr. */ | |
1293 | ||
1294 | tokptr = ++lexptr; | |
1295 | ||
1296 | if (*tokptr == '_' || isalpha (*tokptr)) | |
1297 | { | |
1298 | /* Look for a match with a native register name, usually something | |
1299 | like "r0" for example. */ | |
1300 | ||
1301 | for (regno = 0; regno < NUM_REGS; regno++) | |
1302 | { | |
1303 | namelength = strlen (reg_names[regno]); | |
1304 | if (STREQN (tokptr, reg_names[regno], namelength) | |
1305 | && !isalnum (tokptr[namelength])) | |
1306 | { | |
1307 | yylval.lval = regno; | |
1308 | lexptr += namelength + 1; | |
1309 | return (GDB_REGNAME); | |
1310 | } | |
1311 | } | |
1312 | ||
1313 | /* Look for a match with a standard register name, usually something | |
1314 | like "pc", which gdb always recognizes as the program counter | |
1315 | regardless of what the native register name is. */ | |
1316 | ||
1317 | for (regno = 0; regno < num_std_regs; regno++) | |
1318 | { | |
1319 | namelength = strlen (std_regs[regno].name); | |
1320 | if (STREQN (tokptr, std_regs[regno].name, namelength) | |
1321 | && !isalnum (tokptr[namelength])) | |
1322 | { | |
1323 | yylval.lval = std_regs[regno].regnum; | |
1324 | lexptr += namelength; | |
1325 | return (GDB_REGNAME); | |
1326 | } | |
1327 | } | |
1328 | ||
1329 | /* Attempt to match against a convenience variable. Note that | |
1330 | this will always succeed, because if no variable of that name | |
1331 | already exists, the lookup_internalvar will create one for us. | |
1332 | Also note that both lexptr and tokptr currently point to the | |
1333 | start of the input string we are trying to match, and that we | |
1334 | have already tested the first character for non-numeric, so we | |
1335 | don't have to treat it specially. */ | |
1336 | ||
1337 | while (*tokptr == '_' || isalnum (*tokptr)) | |
1338 | { | |
1339 | tokptr++; | |
1340 | } | |
1341 | yylval.sval.ptr = lexptr; | |
1342 | yylval.sval.length = tokptr - lexptr; | |
1343 | yylval.ivar = lookup_internalvar (copy_name (yylval.sval)); | |
1344 | lexptr = tokptr; | |
1345 | return (GDB_VARIABLE); | |
1346 | } | |
1347 | ||
1348 | /* Since we didn't match against a register name or convenience | |
1349 | variable, our only choice left is a history value. */ | |
1350 | ||
1351 | if (*tokptr == '$') | |
1352 | { | |
1353 | negate = 1; | |
1354 | ival = 1; | |
1355 | tokptr++; | |
1356 | } | |
1357 | else | |
1358 | { | |
1359 | negate = 0; | |
1360 | ival = 0; | |
1361 | } | |
1362 | ||
1363 | /* Attempt to decode more characters as an integer value giving | |
1364 | the index in the history list. If successful, the value will | |
1365 | overwrite ival (currently 0 or 1), and if not, ival will be | |
1366 | left alone, which is good since it is currently correct for | |
1367 | the '$' or '$$' case. */ | |
1368 | ||
1369 | decode_integer_literal (&ival, &tokptr); | |
1370 | yylval.lval = negate ? -ival : ival; | |
1371 | lexptr = tokptr; | |
1372 | return (GDB_LAST); | |
1373 | } | |
1374 | ||
e58de8a2 FF |
1375 | struct token |
1376 | { | |
1377 | char *operator; | |
1378 | int token; | |
1379 | }; | |
1380 | ||
a8a69e63 | 1381 | static const struct token tokentab5[] = |
e58de8a2 FF |
1382 | { |
1383 | { "ANDIF", ANDIF } | |
1384 | }; | |
1385 | ||
a8a69e63 | 1386 | static const struct token tokentab4[] = |
e58de8a2 FF |
1387 | { |
1388 | { "ORIF", ORIF } | |
1389 | }; | |
1390 | ||
a8a69e63 | 1391 | static const struct token tokentab3[] = |
e58de8a2 FF |
1392 | { |
1393 | { "NOT", NOT }, | |
1394 | { "XOR", LOGXOR }, | |
1395 | { "AND", LOGAND } | |
1396 | }; | |
1397 | ||
a8a69e63 | 1398 | static const struct token tokentab2[] = |
e58de8a2 | 1399 | { |
45fe3db4 | 1400 | { ":=", GDB_ASSIGNMENT }, |
e58de8a2 FF |
1401 | { "//", SLASH_SLASH }, |
1402 | { "/=", NOTEQUAL }, | |
1403 | { "<=", LEQ }, | |
1404 | { ">=", GTR }, | |
1405 | { "IN", IN }, | |
1406 | { "OR", LOGIOR } | |
1407 | }; | |
1408 | ||
1409 | /* Read one token, getting characters through lexptr. */ | |
1410 | /* This is where we will check to make sure that the language and the | |
1411 | operators used are compatible. */ | |
1412 | ||
1413 | static int | |
1414 | yylex () | |
1415 | { | |
1416 | unsigned int i; | |
1417 | int token; | |
cbd1bdc3 FF |
1418 | char *simplename; |
1419 | struct symbol *sym; | |
e58de8a2 FF |
1420 | |
1421 | /* Skip over any leading whitespace. */ | |
1422 | while (isspace (*lexptr)) | |
1423 | { | |
1424 | lexptr++; | |
1425 | } | |
1426 | /* Look for special single character cases which can't be the first | |
1427 | character of some other multicharacter token. */ | |
1428 | switch (*lexptr) | |
1429 | { | |
1430 | case '\0': | |
1431 | return (0); | |
54bbbfb4 | 1432 | case ',': |
e58de8a2 | 1433 | case '=': |
e58de8a2 FF |
1434 | case ';': |
1435 | case '!': | |
1436 | case '+': | |
1437 | case '-': | |
1438 | case '*': | |
1439 | case '/': | |
1440 | case '(': | |
1441 | case ')': | |
1442 | case '[': | |
1443 | case ']': | |
1444 | return (*lexptr++); | |
1445 | } | |
1446 | /* Look for characters which start a particular kind of multicharacter | |
45fe3db4 FF |
1447 | token, such as a character literal, register name, convenience |
1448 | variable name, etc. */ | |
e58de8a2 | 1449 | switch (*lexptr) |
2e66cf7d | 1450 | { |
5d074aa9 FF |
1451 | case 'C': |
1452 | case 'c': | |
2e66cf7d FF |
1453 | case '\'': |
1454 | token = match_character_literal (); | |
1455 | if (token != 0) | |
1456 | { | |
1457 | return (token); | |
1458 | } | |
1459 | break; | |
45fe3db4 FF |
1460 | case '$': |
1461 | token = match_dollar_tokens (); | |
1462 | if (token != 0) | |
1463 | { | |
1464 | return (token); | |
1465 | } | |
1466 | break; | |
2e66cf7d | 1467 | } |
e58de8a2 FF |
1468 | /* See if it is a special token of length 5. */ |
1469 | for (i = 0; i < sizeof (tokentab5) / sizeof (tokentab5[0]); i++) | |
1470 | { | |
45fe3db4 | 1471 | if (STREQN (lexptr, tokentab5[i].operator, 5)) |
e58de8a2 FF |
1472 | { |
1473 | lexptr += 5; | |
1474 | return (tokentab5[i].token); | |
1475 | } | |
1476 | } | |
1477 | /* See if it is a special token of length 4. */ | |
1478 | for (i = 0; i < sizeof (tokentab4) / sizeof (tokentab4[0]); i++) | |
1479 | { | |
45fe3db4 | 1480 | if (STREQN (lexptr, tokentab4[i].operator, 4)) |
e58de8a2 FF |
1481 | { |
1482 | lexptr += 4; | |
1483 | return (tokentab4[i].token); | |
1484 | } | |
1485 | } | |
1486 | /* See if it is a special token of length 3. */ | |
1487 | for (i = 0; i < sizeof (tokentab3) / sizeof (tokentab3[0]); i++) | |
1488 | { | |
45fe3db4 | 1489 | if (STREQN (lexptr, tokentab3[i].operator, 3)) |
e58de8a2 FF |
1490 | { |
1491 | lexptr += 3; | |
1492 | return (tokentab3[i].token); | |
1493 | } | |
1494 | } | |
1495 | /* See if it is a special token of length 2. */ | |
1496 | for (i = 0; i < sizeof (tokentab2) / sizeof (tokentab2[0]); i++) | |
1497 | { | |
45fe3db4 | 1498 | if (STREQN (lexptr, tokentab2[i].operator, 2)) |
e58de8a2 FF |
1499 | { |
1500 | lexptr += 2; | |
1501 | return (tokentab2[i].token); | |
1502 | } | |
1503 | } | |
1504 | /* Look for single character cases which which could be the first | |
1505 | character of some other multicharacter token, but aren't, or we | |
1506 | would already have found it. */ | |
1507 | switch (*lexptr) | |
1508 | { | |
45fe3db4 | 1509 | case ':': |
e58de8a2 FF |
1510 | case '/': |
1511 | case '<': | |
1512 | case '>': | |
1513 | return (*lexptr++); | |
1514 | } | |
1515 | /* Look for other special tokens. */ | |
45fe3db4 | 1516 | if (STREQN (lexptr, "TRUE", 4)) /* FIXME: What about lowercase? */ |
e58de8a2 FF |
1517 | { |
1518 | yylval.ulval = 1; | |
1519 | lexptr += 4; | |
1520 | return (BOOLEAN_LITERAL); | |
1521 | } | |
45fe3db4 | 1522 | if (STREQN (lexptr, "FALSE", 5)) /* FIXME: What about lowercase? */ |
e58de8a2 FF |
1523 | { |
1524 | yylval.ulval = 0; | |
1525 | lexptr += 5; | |
1526 | return (BOOLEAN_LITERAL); | |
1527 | } | |
1188fbbf FF |
1528 | /* Look for a float literal before looking for an integer literal, so |
1529 | we match as much of the input stream as possible. */ | |
1530 | token = match_float_literal (); | |
1531 | if (token != 0) | |
1532 | { | |
1533 | return (token); | |
1534 | } | |
2e66cf7d | 1535 | token = match_integer_literal (); |
cbd1bdc3 | 1536 | if (token != 0) |
e58de8a2 FF |
1537 | { |
1538 | return (token); | |
1539 | } | |
cbd1bdc3 FF |
1540 | |
1541 | /* Try to match a simple name string, and if a match is found, then | |
1542 | further classify what sort of name it is and return an appropriate | |
1543 | token. Note that attempting to match a simple name string consumes | |
1544 | the token from lexptr, so we can't back out if we later find that | |
1545 | we can't classify what sort of name it is. */ | |
1546 | ||
1547 | simplename = match_simple_name_string (); | |
1548 | if (simplename != NULL) | |
1549 | { | |
1550 | sym = lookup_symbol (simplename, expression_context_block, | |
1551 | VAR_NAMESPACE, (int *) NULL, | |
1552 | (struct symtab **) NULL); | |
1553 | if (sym != NULL) | |
1554 | { | |
1555 | yylval.ssym.stoken.ptr = NULL; | |
1556 | yylval.ssym.stoken.length = 0; | |
1557 | yylval.ssym.sym = sym; | |
1558 | yylval.ssym.is_a_field_of_this = 0; /* FIXME, C++'ism */ | |
1559 | switch (SYMBOL_CLASS (sym)) | |
1560 | { | |
1561 | case LOC_BLOCK: | |
1562 | /* Found a procedure name. */ | |
1563 | return (GENERAL_PROCEDURE_NAME); | |
1564 | case LOC_STATIC: | |
1565 | /* Found a global or local static variable. */ | |
1566 | return (LOCATION_NAME); | |
a8a69e63 FF |
1567 | case LOC_UNDEF: |
1568 | case LOC_CONST: | |
1569 | case LOC_REGISTER: | |
1570 | case LOC_ARG: | |
1571 | case LOC_REF_ARG: | |
1572 | case LOC_REGPARM: | |
1573 | case LOC_LOCAL: | |
1574 | case LOC_TYPEDEF: | |
1575 | case LOC_LABEL: | |
1576 | case LOC_CONST_BYTES: | |
1577 | case LOC_LOCAL_ARG: | |
1578 | break; | |
cbd1bdc3 FF |
1579 | } |
1580 | } | |
1581 | else if (!have_full_symbols () && !have_partial_symbols ()) | |
1582 | { | |
1583 | error ("No symbol table is loaded. Use the \"file\" command."); | |
1584 | } | |
1585 | else | |
1586 | { | |
1587 | error ("No symbol \"%s\" in current context.", simplename); | |
1588 | } | |
1589 | } | |
1590 | ||
1188fbbf FF |
1591 | /* Catch single character tokens which are not part of some |
1592 | longer token. */ | |
1593 | ||
1594 | switch (*lexptr) | |
1595 | { | |
1596 | case '.': /* Not float for example. */ | |
1597 | return (*lexptr++); | |
1598 | } | |
1599 | ||
e58de8a2 FF |
1600 | return (ILLEGAL_TOKEN); |
1601 | } | |
1602 | ||
22e39759 | 1603 | void |
e58de8a2 FF |
1604 | yyerror (msg) |
1605 | char *msg; /* unused */ | |
1606 | { | |
1607 | printf ("Parsing: %s\n", lexptr); | |
1608 | if (yychar < 256) | |
1609 | { | |
1610 | error ("Invalid syntax in expression near character '%c'.", yychar); | |
1611 | } | |
1612 | else | |
1613 | { | |
1614 | error ("Invalid syntax in expression"); | |
1615 | } | |
1616 | } |