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 | ||
56 | #include <stdio.h> | |
57 | #include <string.h> | |
58 | #include "defs.h" | |
59 | #include "symtab.h" | |
60 | #include "gdbtypes.h" | |
61 | #include "frame.h" | |
62 | #include "expression.h" | |
63 | #include "language.h" | |
64 | #include "value.h" | |
65 | #include "parser-defs.h" | |
66 | #include "bfd.h" | |
67 | #include "symfile.h" | |
68 | #include "objfiles.h" | |
69 | ||
70 | /* These MUST be included in any grammar file!!!! Please choose unique names! | |
71 | Note that this are a combined list of variables that can be produced | |
72 | by any one of bison, byacc, or yacc. */ | |
73 | #define yymaxdepth chill_maxdepth | |
74 | #define yyparse chill_parse | |
75 | #define yylex chill_lex | |
76 | #define yyerror chill_error | |
77 | #define yylval chill_lval | |
78 | #define yychar chill_char | |
79 | #define yydebug chill_debug | |
80 | #define yypact chill_pact | |
81 | #define yyr1 chill_r1 | |
82 | #define yyr2 chill_r2 | |
83 | #define yydef chill_def | |
84 | #define yychk chill_chk | |
85 | #define yypgo chill_pgo | |
86 | #define yyact chill_act | |
87 | #define yyexca chill_exca | |
88 | #define yyerrflag chill_errflag | |
89 | #define yynerrs chill_nerrs | |
90 | #define yyps chill_ps | |
91 | #define yypv chill_pv | |
92 | #define yys chill_s | |
93 | #define yy_yys chill_yys | |
94 | #define yystate chill_state | |
95 | #define yytmp chill_tmp | |
96 | #define yyv chill_v | |
97 | #define yy_yyv chill_yyv | |
98 | #define yyval chill_val | |
99 | #define yylloc chill_lloc | |
100 | #define yyss chill_yyss /* byacc */ | |
101 | #define yyssp chill_yysp /* byacc */ | |
102 | #define yyvs chill_yyvs /* byacc */ | |
103 | #define yyvsp chill_yyvsp /* byacc */ | |
104 | ||
105 | static int | |
106 | yylex PARAMS ((void)); | |
107 | ||
108 | static void | |
109 | yyerror PARAMS ((char *)); | |
110 | ||
111 | int | |
112 | yyparse PARAMS ((void)); | |
113 | ||
114 | /* #define YYDEBUG 1 */ | |
115 | ||
116 | %} | |
117 | ||
118 | /* Although the yacc "value" of an expression is not used, | |
119 | since the result is stored in the structure being created, | |
120 | other node types do have values. */ | |
121 | ||
122 | %union | |
123 | { | |
124 | LONGEST lval; | |
125 | unsigned LONGEST ulval; | |
126 | struct { | |
127 | LONGEST val; | |
128 | struct type *type; | |
129 | } typed_val; | |
130 | double dval; | |
131 | struct symbol *sym; | |
132 | struct type *tval; | |
133 | struct stoken sval; | |
134 | struct ttype tsym; | |
135 | struct symtoken ssym; | |
136 | int voidval; | |
137 | struct block *bval; | |
138 | enum exp_opcode opcode; | |
139 | struct internalvar *ivar; | |
140 | ||
141 | struct type **tvec; | |
142 | int *ivec; | |
143 | } | |
144 | ||
145 | %{ | |
146 | static int parse_number PARAMS ((void)); | |
147 | %} | |
148 | ||
149 | %token <voidval> FIXME | |
150 | ||
151 | %token <typed_val> INTEGER_LITERAL | |
152 | %token <ulval> BOOLEAN_LITERAL | |
153 | %token <voidval> CHARACTER_LITERAL | |
154 | %token <voidval> SET_LITERAL | |
155 | %token <voidval> EMPTINESS_LITERAL | |
156 | %token <voidval> CHARACTER_STRING_LITERAL | |
157 | %token <voidval> BIT_STRING_LITERAL | |
158 | ||
159 | %token <voidval> STRING | |
160 | %token <voidval> CONSTANT | |
161 | %token <voidval> '.' | |
162 | %token <voidval> ';' | |
163 | %token <voidval> ':' | |
164 | %token <voidval> CASE | |
165 | %token <voidval> OF | |
166 | %token <voidval> ESAC | |
167 | %token <voidval> LOGIOR | |
168 | %token <voidval> ORIF | |
169 | %token <voidval> LOGXOR | |
170 | %token <voidval> LOGAND | |
171 | %token <voidval> ANDIF | |
172 | %token <voidval> '=' | |
173 | %token <voidval> NOTEQUAL | |
174 | %token <voidval> '>' | |
175 | %token <voidval> GTR | |
176 | %token <voidval> '<' | |
177 | %token <voidval> LEQ | |
178 | %token <voidval> IN | |
179 | %token <voidval> '+' | |
180 | %token <voidval> '-' | |
181 | %token <voidval> '*' | |
182 | %token <voidval> '/' | |
183 | %token <voidval> SLASH_SLASH | |
184 | %token <voidval> MOD | |
185 | %token <voidval> REM | |
186 | %token <voidval> NOT | |
187 | %token <voidval> POINTER | |
188 | %token <voidval> RECEIVE | |
189 | %token <voidval> SC | |
190 | %token <voidval> '[' | |
191 | %token <voidval> ']' | |
192 | %token <voidval> '(' | |
193 | %token <voidval> ')' | |
194 | %token <voidval> UP | |
195 | %token <voidval> IF | |
196 | %token <voidval> THEN | |
197 | %token <voidval> ELSE | |
198 | %token <voidval> FI | |
199 | %token <voidval> ELSIF | |
200 | %token <voidval> ILLEGAL_TOKEN | |
201 | ||
202 | %type <voidval> location | |
203 | %type <voidval> primitive_value | |
204 | %type <voidval> location_contents | |
205 | %type <voidval> value_name | |
206 | %type <voidval> literal | |
207 | %type <voidval> tuple | |
208 | %type <voidval> value_string_element | |
209 | %type <voidval> value_string_slice | |
210 | %type <voidval> value_array_element | |
211 | %type <voidval> value_array_slice | |
212 | %type <voidval> value_structure_field | |
213 | %type <voidval> expression_conversion | |
214 | %type <voidval> value_procedure_call | |
215 | %type <voidval> value_built_in_routine_call | |
216 | %type <voidval> start_expression | |
217 | %type <voidval> zero_adic_operator | |
218 | %type <voidval> parenthesised_expression | |
219 | %type <voidval> value | |
220 | %type <voidval> undefined_value | |
221 | %type <voidval> expression | |
222 | %type <voidval> conditional_expression | |
223 | %type <voidval> then_alternative | |
224 | %type <voidval> else_alternative | |
225 | %type <voidval> sub_expression | |
226 | %type <voidval> value_case_alternative | |
227 | %type <voidval> operand_0 | |
228 | %type <voidval> operand_1 | |
229 | %type <voidval> operand_2 | |
230 | %type <voidval> operand_3 | |
231 | %type <voidval> operand_4 | |
232 | %type <voidval> operand_5 | |
233 | %type <voidval> operand_6 | |
234 | %type <voidval> integer_literal_expression | |
235 | %type <voidval> synonym_name | |
236 | %type <voidval> value_enumeration_name | |
237 | %type <voidval> value_do_with_name | |
238 | %type <voidval> value_receive_name | |
239 | %type <voidval> general_procedure_name | |
240 | %type <voidval> string_primitive_value | |
241 | %type <voidval> start_element | |
242 | %type <voidval> left_element | |
243 | %type <voidval> right_element | |
244 | %type <voidval> slice_size | |
245 | %type <voidval> array_primitive_value | |
246 | %type <voidval> expression_list | |
247 | %type <voidval> lower_element | |
248 | %type <voidval> upper_element | |
249 | %type <voidval> first_element | |
250 | %type <voidval> structure_primitive_value | |
251 | %type <voidval> field_name | |
252 | %type <voidval> mode_name | |
253 | %type <voidval> boolean_expression | |
254 | %type <voidval> case_selector_list | |
255 | %type <voidval> subexpression | |
256 | %type <voidval> case_label_specification | |
257 | %type <voidval> buffer_location | |
258 | ||
259 | %% | |
260 | ||
261 | /* Z.200, 5.3.1 */ | |
262 | ||
263 | value : expression | |
264 | { | |
265 | $$ = 0; /* FIXME */ | |
266 | } | |
267 | | undefined_value | |
268 | { | |
269 | $$ = 0; /* FIXME */ | |
270 | } | |
271 | ; | |
272 | ||
273 | undefined_value : FIXME | |
274 | { | |
275 | $$ = 0; /* FIXME */ | |
276 | } | |
277 | ; | |
278 | ||
279 | /* Z.200, 4.2.1 */ | |
280 | ||
281 | location : FIXME | |
282 | { | |
283 | $$ = 0; /* FIXME */ | |
284 | } | |
285 | ; | |
286 | ||
287 | /* Z.200, 5.2.1 */ | |
288 | ||
289 | primitive_value : location_contents | |
290 | { | |
291 | $$ = 0; /* FIXME */ | |
292 | } | |
293 | | value_name | |
294 | { | |
295 | $$ = 0; /* FIXME */ | |
296 | } | |
297 | | literal | |
298 | { | |
299 | $$ = 0; /* FIXME */ | |
300 | } | |
301 | | tuple | |
302 | { | |
303 | $$ = 0; /* FIXME */ | |
304 | } | |
305 | | value_string_element | |
306 | { | |
307 | $$ = 0; /* FIXME */ | |
308 | } | |
309 | | value_string_slice | |
310 | { | |
311 | $$ = 0; /* FIXME */ | |
312 | } | |
313 | | value_array_element | |
314 | { | |
315 | $$ = 0; /* FIXME */ | |
316 | } | |
317 | | value_array_slice | |
318 | { | |
319 | $$ = 0; /* FIXME */ | |
320 | } | |
321 | | value_structure_field | |
322 | { | |
323 | $$ = 0; /* FIXME */ | |
324 | } | |
325 | | expression_conversion | |
326 | { | |
327 | $$ = 0; /* FIXME */ | |
328 | } | |
329 | | value_procedure_call | |
330 | { | |
331 | $$ = 0; /* FIXME */ | |
332 | } | |
333 | | value_built_in_routine_call | |
334 | { | |
335 | $$ = 0; /* FIXME */ | |
336 | } | |
337 | | start_expression | |
338 | { | |
339 | $$ = 0; /* FIXME */ | |
340 | } | |
341 | | zero_adic_operator | |
342 | { | |
343 | $$ = 0; /* FIXME */ | |
344 | } | |
345 | | parenthesised_expression | |
346 | { | |
347 | $$ = 0; /* FIXME */ | |
348 | } | |
349 | ; | |
350 | ||
351 | /* Z.200, 5.2.2 */ | |
352 | ||
353 | location_contents: location | |
354 | { | |
355 | $$ = 0; /* FIXME */ | |
356 | } | |
357 | ; | |
358 | ||
359 | /* Z.200, 5.2.3 */ | |
360 | ||
361 | value_name : synonym_name | |
362 | { | |
363 | $$ = 0; /* FIXME */ | |
364 | } | |
365 | | value_enumeration_name | |
366 | { | |
367 | $$ = 0; /* FIXME */ | |
368 | } | |
369 | | value_do_with_name | |
370 | { | |
371 | $$ = 0; /* FIXME */ | |
372 | } | |
373 | | value_receive_name | |
374 | { | |
375 | $$ = 0; /* FIXME */ | |
376 | } | |
377 | | general_procedure_name | |
378 | { | |
379 | $$ = 0; /* FIXME */ | |
380 | } | |
381 | ; | |
382 | ||
383 | /* Z.200, 5.2.4.1 */ | |
384 | ||
385 | literal : INTEGER_LITERAL | |
386 | { | |
387 | write_exp_elt_opcode (OP_LONG); | |
388 | write_exp_elt_type ($1.type); | |
389 | write_exp_elt_longcst ((LONGEST) ($1.val)); | |
390 | write_exp_elt_opcode (OP_LONG); | |
391 | } | |
392 | | BOOLEAN_LITERAL | |
393 | { | |
394 | write_exp_elt_opcode (OP_BOOL); | |
395 | write_exp_elt_longcst ((LONGEST) $1); | |
396 | write_exp_elt_opcode (OP_BOOL); | |
397 | } | |
398 | | CHARACTER_LITERAL | |
399 | { | |
400 | $$ = 0; /* FIXME */ | |
401 | } | |
402 | | SET_LITERAL | |
403 | { | |
404 | $$ = 0; /* FIXME */ | |
405 | } | |
406 | | EMPTINESS_LITERAL | |
407 | { | |
408 | $$ = 0; /* FIXME */ | |
409 | } | |
410 | | CHARACTER_STRING_LITERAL | |
411 | { | |
412 | $$ = 0; /* FIXME */ | |
413 | } | |
414 | | BIT_STRING_LITERAL | |
415 | { | |
416 | $$ = 0; /* FIXME */ | |
417 | } | |
418 | ; | |
419 | ||
420 | /* Z.200, 5.2.5 */ | |
421 | ||
422 | tuple : FIXME | |
423 | { | |
424 | $$ = 0; /* FIXME */ | |
425 | } | |
426 | ; | |
427 | ||
428 | ||
429 | /* Z.200, 5.2.6 */ | |
430 | ||
431 | value_string_element: string_primitive_value '(' start_element ')' | |
432 | { | |
433 | $$ = 0; /* FIXME */ | |
434 | } | |
435 | ; | |
436 | ||
437 | /* Z.200, 5.2.7 */ | |
438 | ||
439 | value_string_slice: string_primitive_value '(' left_element ':' right_element ')' | |
440 | { | |
441 | $$ = 0; /* FIXME */ | |
442 | } | |
443 | | string_primitive_value '(' start_element UP slice_size ')' | |
444 | { | |
445 | $$ = 0; /* FIXME */ | |
446 | } | |
447 | ; | |
448 | ||
449 | /* Z.200, 5.2.8 */ | |
450 | ||
451 | value_array_element: array_primitive_value '(' expression_list ')' | |
452 | { | |
453 | $$ = 0; /* FIXME */ | |
454 | } | |
455 | ; | |
456 | ||
457 | /* Z.200, 5.2.9 */ | |
458 | ||
459 | value_array_slice: array_primitive_value '(' lower_element ':' upper_element ')' | |
460 | { | |
461 | $$ = 0; /* FIXME */ | |
462 | } | |
463 | | array_primitive_value '(' first_element UP slice_size '(' | |
464 | { | |
465 | $$ = 0; /* FIXME */ | |
466 | } | |
467 | ; | |
468 | ||
469 | /* Z.200, 5.2.10 */ | |
470 | ||
471 | value_structure_field: structure_primitive_value '.' field_name | |
472 | { | |
473 | $$ = 0; /* FIXME */ | |
474 | } | |
475 | ; | |
476 | ||
477 | /* Z.200, 5.2.11 */ | |
478 | ||
479 | expression_conversion: mode_name '(' expression ')' | |
480 | { | |
481 | $$ = 0; /* FIXME */ | |
482 | } | |
483 | ; | |
484 | ||
485 | /* Z.200, 5.2.12 */ | |
486 | ||
487 | value_procedure_call: FIXME | |
488 | { | |
489 | $$ = 0; /* FIXME */ | |
490 | } | |
491 | ; | |
492 | ||
493 | /* Z.200, 5.2.13 */ | |
494 | ||
495 | value_built_in_routine_call: FIXME | |
496 | { | |
497 | $$ = 0; /* FIXME */ | |
498 | } | |
499 | ; | |
500 | ||
501 | /* Z.200, 5.2.14 */ | |
502 | ||
503 | start_expression: FIXME | |
504 | { | |
505 | $$ = 0; /* FIXME */ | |
506 | } /* Not in GNU-Chill */ | |
507 | ; | |
508 | ||
509 | /* Z.200, 5.2.15 */ | |
510 | ||
511 | zero_adic_operator: FIXME | |
512 | { | |
513 | $$ = 0; /* FIXME */ | |
514 | } | |
515 | ; | |
516 | ||
517 | /* Z.200, 5.2.16 */ | |
518 | ||
519 | parenthesised_expression: '(' expression ')' | |
520 | { | |
521 | $$ = 0; /* FIXME */ | |
522 | } | |
523 | ; | |
524 | ||
525 | /* Z.200, 5.3.2 */ | |
526 | ||
527 | expression : operand_0 | |
528 | { | |
529 | $$ = 0; /* FIXME */ | |
530 | } | |
531 | | conditional_expression | |
532 | { | |
533 | $$ = 0; /* FIXME */ | |
534 | } | |
535 | ; | |
536 | ||
537 | conditional_expression : IF boolean_expression then_alternative else_alternative FI | |
538 | { | |
539 | $$ = 0; /* FIXME */ | |
540 | } | |
541 | | CASE case_selector_list OF value_case_alternative '[' ELSE sub_expression ']' ESAC | |
542 | { | |
543 | $$ = 0; /* FIXME */ | |
544 | } | |
545 | ; | |
546 | ||
547 | then_alternative: THEN subexpression | |
548 | { | |
549 | $$ = 0; /* FIXME */ | |
550 | } | |
551 | ; | |
552 | ||
553 | else_alternative: ELSE subexpression | |
554 | { | |
555 | $$ = 0; /* FIXME */ | |
556 | } | |
557 | | ELSIF boolean_expression then_alternative else_alternative | |
558 | { | |
559 | $$ = 0; /* FIXME */ | |
560 | } | |
561 | ; | |
562 | ||
563 | sub_expression : expression | |
564 | { | |
565 | $$ = 0; /* FIXME */ | |
566 | } | |
567 | ; | |
568 | ||
569 | value_case_alternative: case_label_specification ':' sub_expression ';' | |
570 | { | |
571 | $$ = 0; /* FIXME */ | |
572 | } | |
573 | ; | |
574 | ||
575 | /* Z.200, 5.3.3 */ | |
576 | ||
577 | operand_0 : operand_1 | |
578 | { | |
579 | $$ = 0; /* FIXME */ | |
580 | } | |
581 | | operand_0 LOGIOR operand_1 | |
582 | { | |
583 | write_exp_elt_opcode (BINOP_BITWISE_IOR); | |
584 | } | |
585 | | operand_0 ORIF operand_1 | |
586 | { | |
587 | $$ = 0; /* FIXME */ | |
588 | } | |
589 | | operand_0 LOGXOR operand_1 | |
590 | { | |
591 | write_exp_elt_opcode (BINOP_BITWISE_XOR); | |
592 | } | |
593 | ; | |
594 | ||
595 | /* Z.200, 5.3.4 */ | |
596 | ||
597 | operand_1 : operand_2 | |
598 | { | |
599 | $$ = 0; /* FIXME */ | |
600 | } | |
601 | | operand_1 LOGAND operand_2 | |
602 | { | |
603 | write_exp_elt_opcode (BINOP_BITWISE_AND); | |
604 | } | |
605 | | operand_1 ANDIF operand_2 | |
606 | { | |
607 | $$ = 0; /* FIXME */ | |
608 | } | |
609 | ; | |
610 | ||
611 | /* Z.200, 5.3.5 */ | |
612 | ||
613 | operand_2 : operand_3 | |
614 | { | |
615 | $$ = 0; /* FIXME */ | |
616 | } | |
617 | | operand_2 '=' operand_3 | |
618 | { | |
619 | write_exp_elt_opcode (BINOP_EQUAL); | |
620 | } | |
621 | | operand_2 NOTEQUAL operand_3 | |
622 | { | |
623 | write_exp_elt_opcode (BINOP_NOTEQUAL); | |
624 | } | |
625 | | operand_2 '>' operand_3 | |
626 | { | |
627 | write_exp_elt_opcode (BINOP_GTR); | |
628 | } | |
629 | | operand_2 GTR operand_3 | |
630 | { | |
631 | write_exp_elt_opcode (BINOP_GEQ); | |
632 | } | |
633 | | operand_2 '<' operand_3 | |
634 | { | |
635 | write_exp_elt_opcode (BINOP_LESS); | |
636 | } | |
637 | | operand_2 LEQ operand_3 | |
638 | { | |
639 | write_exp_elt_opcode (BINOP_LEQ); | |
640 | } | |
641 | | operand_2 IN operand_3 | |
642 | { | |
643 | $$ = 0; /* FIXME */ | |
644 | } | |
645 | ; | |
646 | ||
647 | ||
648 | /* Z.200, 5.3.6 */ | |
649 | ||
650 | operand_3 : operand_4 | |
651 | { | |
652 | $$ = 0; /* FIXME */ | |
653 | } | |
654 | | operand_3 '+' operand_4 | |
655 | { | |
656 | write_exp_elt_opcode (BINOP_ADD); | |
657 | } | |
658 | | operand_3 '-' operand_4 | |
659 | { | |
660 | write_exp_elt_opcode (BINOP_SUB); | |
661 | } | |
662 | | operand_3 SLASH_SLASH operand_4 | |
663 | { | |
664 | $$ = 0; /* FIXME */ | |
665 | } | |
666 | ; | |
667 | ||
668 | /* Z.200, 5.3.7 */ | |
669 | ||
670 | operand_4 : operand_5 | |
671 | { | |
672 | $$ = 0; /* FIXME */ | |
673 | } | |
674 | | operand_4 '*' operand_5 | |
675 | { | |
676 | write_exp_elt_opcode (BINOP_MUL); | |
677 | } | |
678 | | operand_4 '/' operand_5 | |
679 | { | |
680 | write_exp_elt_opcode (BINOP_DIV); | |
681 | } | |
682 | | operand_4 MOD operand_5 | |
683 | { | |
684 | $$ = 0; /* FIXME */ | |
685 | } | |
686 | | operand_4 REM operand_5 | |
687 | { | |
688 | $$ = 0; /* FIXME */ | |
689 | } | |
690 | ; | |
691 | ||
692 | /* Z.200, 5.3.8 */ | |
693 | ||
694 | operand_5 : operand_6 | |
695 | { | |
696 | $$ = 0; /* FIXME */ | |
697 | } | |
698 | | '-' operand_6 | |
699 | { | |
700 | write_exp_elt_opcode (UNOP_NEG); | |
701 | } | |
702 | | NOT operand_6 | |
703 | { | |
704 | write_exp_elt_opcode (UNOP_LOGICAL_NOT); | |
705 | } | |
706 | | '(' integer_literal_expression ')' operand_6 | |
707 | { | |
708 | $$ = 0; /* FIXME */ | |
709 | } | |
710 | ; | |
711 | ||
712 | /* Z.200, 5.3.9 */ | |
713 | ||
714 | operand_6 : POINTER location | |
715 | { | |
716 | $$ = 0; /* FIXME */ | |
717 | } | |
718 | | RECEIVE buffer_location | |
719 | { | |
720 | $$ = 0; /* FIXME */ | |
721 | } | |
722 | | primitive_value | |
723 | { | |
724 | $$ = 0; /* FIXME */ | |
725 | } | |
726 | ; | |
727 | ||
728 | ||
729 | /* Z.200, 12.4.3 */ | |
730 | /* FIXME: For now we just accept only a single integer literal. */ | |
731 | ||
732 | integer_literal_expression: | |
733 | INTEGER_LITERAL | |
734 | { | |
735 | $$ = 0; | |
736 | } | |
737 | ||
738 | /* Things which still need productions... */ | |
739 | synonym_name : FIXME { $$ = 0; } | |
740 | value_enumeration_name : FIXME { $$ = 0; } | |
741 | value_do_with_name : FIXME { $$ = 0; } | |
742 | value_receive_name : FIXME { $$ = 0; } | |
743 | general_procedure_name : FIXME { $$ = 0; } | |
744 | string_primitive_value : FIXME { $$ = 0; } | |
745 | start_element : FIXME { $$ = 0; } | |
746 | left_element : FIXME { $$ = 0; } | |
747 | right_element : FIXME { $$ = 0; } | |
748 | slice_size : FIXME { $$ = 0; } | |
749 | array_primitive_value : FIXME { $$ = 0; } | |
750 | expression_list : FIXME { $$ = 0; } | |
751 | lower_element : FIXME { $$ = 0; } | |
752 | upper_element : FIXME { $$ = 0; } | |
753 | first_element : FIXME { $$ = 0; } | |
754 | structure_primitive_value: FIXME { $$ = 0; } | |
755 | field_name : FIXME { $$ = 0; } | |
756 | mode_name : FIXME { $$ = 0; } | |
757 | boolean_expression : FIXME { $$ = 0; } | |
758 | case_selector_list : FIXME { $$ = 0; } | |
759 | subexpression : FIXME { $$ = 0; } | |
760 | case_label_specification: FIXME { $$ = 0; } | |
761 | buffer_location : FIXME { $$ = 0; } | |
762 | ||
763 | %% | |
764 | ||
765 | /* Recognize a character literal. */ | |
766 | ||
767 | static int | |
768 | decode_character_literal () | |
769 | { | |
770 | char *tokptr = lexptr; | |
771 | int ival = 0; | |
772 | ||
773 | if (*tokptr++ != '\'') | |
774 | { | |
775 | return (0); | |
776 | } | |
777 | ||
778 | if (*tokptr != '\\') | |
779 | { | |
780 | ival = *++tokptr; | |
781 | tokptr++; | |
782 | } | |
783 | else | |
784 | { | |
785 | ||
786 | } | |
787 | if (*++tokptr != '\'') | |
788 | { | |
789 | return (0); | |
790 | } | |
791 | yylval.typed_val.val = ival; | |
792 | yylval.typed_val.type = builtin_type_int; | |
793 | lexptr = tokptr; | |
794 | return (CHARACTER_LITERAL); | |
795 | } | |
796 | ||
797 | /* Recognize an integer literal, as specified in Z.200 sec 5.2.4.2. | |
798 | Note that according to 5.2.4.2, a single "_" is also a valid integer | |
799 | literal, however GNU-chill requires there to be at least one "digit" | |
800 | in any integer literal. */ | |
801 | ||
802 | static int | |
803 | decode_integer_literal () | |
804 | { | |
805 | char *tokptr = lexptr; | |
806 | int ival = 0; | |
807 | int base = 0; | |
808 | int digits = 0; | |
809 | int temp; | |
810 | ||
811 | /* Look for an explicit base specifier, which is optional. */ | |
812 | ||
813 | switch (*tokptr) | |
814 | { | |
815 | case 'd': | |
816 | case 'D': | |
817 | base = 10; | |
818 | tokptr++; | |
819 | break; | |
820 | case 'b': | |
821 | case 'B': | |
822 | base = 2; | |
823 | tokptr++; | |
824 | break; | |
825 | case 'h': | |
826 | case 'H': | |
827 | base = 16; | |
828 | tokptr++; | |
829 | break; | |
830 | case 'o': | |
831 | case 'O': | |
832 | base = 8; | |
833 | tokptr++; | |
834 | break; | |
835 | } | |
836 | ||
837 | /* If we found no explicit base then default to 10, otherwise ensure | |
838 | that the character after the explicit base is a single quote. */ | |
839 | ||
840 | if (base == 0) | |
841 | { | |
842 | base = 10; | |
843 | } | |
844 | else | |
845 | { | |
846 | if (*tokptr++ != '\'') | |
847 | { | |
848 | return (0); | |
849 | } | |
850 | } | |
851 | ||
852 | /* Start looking for a value composed of valid digits as set by the base | |
853 | in use. Note that '_' characters are valid anywhere, in any quantity, | |
854 | and are simply ignored. Since we must find at least one valid digit, | |
855 | or reject this token as an integer literal, we keep track of how many | |
856 | digits we have encountered. */ | |
857 | ||
858 | while (*tokptr != '\0') | |
859 | { | |
860 | temp = tolower (*tokptr); | |
861 | tokptr++; | |
862 | switch (temp) | |
863 | { | |
864 | case '_': | |
865 | continue; | |
866 | case '0': case '1': case '2': case '3': case '4': | |
867 | case '5': case '6': case '7': case '8': case '9': | |
868 | temp -= '0'; | |
869 | break; | |
870 | case 'a': case 'b': case 'c': case 'd': case 'e': | |
871 | case 'f': | |
872 | temp -= 'a'; | |
873 | temp += 10; | |
874 | break; | |
875 | default: | |
876 | temp = base; | |
877 | break; | |
878 | } | |
879 | if (temp < base) | |
880 | { | |
881 | digits++; | |
882 | ival *= base; | |
883 | ival += temp; | |
884 | } | |
885 | else | |
886 | { | |
887 | /* Found something not in domain for current base. */ | |
888 | tokptr--; /* Unconsume what gave us indigestion. */ | |
889 | break; | |
890 | } | |
891 | } | |
892 | ||
893 | /* If we didn't find any digits, then we don't have a valid integer | |
894 | literal, so reject the entire token. Otherwise, set up the parser | |
895 | variables, advance the current lexical scan pointer, and return the | |
896 | INTEGER_LITERAL token. */ | |
897 | ||
898 | if (digits == 0) | |
899 | { | |
900 | return (0); | |
901 | } | |
902 | else | |
903 | { | |
904 | yylval.typed_val.val = ival; | |
905 | yylval.typed_val.type = builtin_type_int; | |
906 | lexptr = tokptr; | |
907 | return (INTEGER_LITERAL); | |
908 | } | |
909 | } | |
910 | ||
911 | static void convert_float () | |
912 | { | |
913 | #if 0 | |
914 | extern double strtod (); | |
915 | double d; | |
916 | char tmp[256]; | |
917 | char *p = yytext, *p1 = tmp; | |
918 | char c; | |
919 | ||
920 | while (c = *p++) | |
921 | { | |
922 | switch (c) | |
923 | { | |
924 | case '_': | |
925 | break; | |
926 | case 'E': | |
927 | case 'd': | |
928 | case 'D': | |
929 | *p1++ = 'e'; | |
930 | break; | |
931 | default: | |
932 | *p1++ = c; | |
933 | break; | |
934 | } | |
935 | } | |
936 | *p1 = '\0'; | |
937 | d = strtod (tmp, &p1); | |
938 | if (*p1) | |
939 | { | |
940 | /* add error handling here */ | |
941 | ; | |
942 | } | |
943 | yylval.dval = d; | |
944 | #endif | |
945 | } | |
946 | ||
947 | /* Take care of parsing a number (anything that starts with a digit). | |
948 | Set yylval and return the token type; update lexptr. | |
949 | LEN is the number of characters in it. */ | |
950 | ||
951 | /*** Needs some error checking for the float case ***/ | |
952 | ||
953 | static int | |
954 | parse_number () | |
955 | { | |
956 | } | |
957 | ||
958 | struct token | |
959 | { | |
960 | char *operator; | |
961 | int token; | |
962 | }; | |
963 | ||
964 | const static struct token tokentab5[] = | |
965 | { | |
966 | { "ANDIF", ANDIF } | |
967 | }; | |
968 | ||
969 | const static struct token tokentab4[] = | |
970 | { | |
971 | { "ORIF", ORIF } | |
972 | }; | |
973 | ||
974 | const static struct token tokentab3[] = | |
975 | { | |
976 | { "NOT", NOT }, | |
977 | { "XOR", LOGXOR }, | |
978 | { "AND", LOGAND } | |
979 | }; | |
980 | ||
981 | const static struct token tokentab2[] = | |
982 | { | |
983 | { "//", SLASH_SLASH }, | |
984 | { "/=", NOTEQUAL }, | |
985 | { "<=", LEQ }, | |
986 | { ">=", GTR }, | |
987 | { "IN", IN }, | |
988 | { "OR", LOGIOR } | |
989 | }; | |
990 | ||
991 | /* Read one token, getting characters through lexptr. */ | |
992 | /* This is where we will check to make sure that the language and the | |
993 | operators used are compatible. */ | |
994 | ||
995 | static int | |
996 | yylex () | |
997 | { | |
998 | unsigned int i; | |
999 | int token; | |
1000 | ||
1001 | /* Skip over any leading whitespace. */ | |
1002 | while (isspace (*lexptr)) | |
1003 | { | |
1004 | lexptr++; | |
1005 | } | |
1006 | /* Look for special single character cases which can't be the first | |
1007 | character of some other multicharacter token. */ | |
1008 | switch (*lexptr) | |
1009 | { | |
1010 | case '\0': | |
1011 | return (0); | |
1012 | case '.': | |
1013 | case '=': | |
1014 | case ':': | |
1015 | case ';': | |
1016 | case '!': | |
1017 | case '+': | |
1018 | case '-': | |
1019 | case '*': | |
1020 | case '/': | |
1021 | case '(': | |
1022 | case ')': | |
1023 | case '[': | |
1024 | case ']': | |
1025 | return (*lexptr++); | |
1026 | } | |
1027 | /* Look for characters which start a particular kind of multicharacter | |
1028 | token, such as a character literal. */ | |
1029 | switch (*lexptr) | |
1030 | { | |
1031 | case '\'': | |
1032 | if ((token = decode_character_literal ()) != 0) | |
1033 | { | |
1034 | return (token); | |
1035 | } | |
1036 | break; | |
1037 | } | |
1038 | /* See if it is a special token of length 5. */ | |
1039 | for (i = 0; i < sizeof (tokentab5) / sizeof (tokentab5[0]); i++) | |
1040 | { | |
1041 | if (strncmp (lexptr, tokentab5[i].operator, 5) == 0) | |
1042 | { | |
1043 | lexptr += 5; | |
1044 | return (tokentab5[i].token); | |
1045 | } | |
1046 | } | |
1047 | /* See if it is a special token of length 4. */ | |
1048 | for (i = 0; i < sizeof (tokentab4) / sizeof (tokentab4[0]); i++) | |
1049 | { | |
1050 | if (strncmp (lexptr, tokentab4[i].operator, 4) == 0) | |
1051 | { | |
1052 | lexptr += 4; | |
1053 | return (tokentab4[i].token); | |
1054 | } | |
1055 | } | |
1056 | /* See if it is a special token of length 3. */ | |
1057 | for (i = 0; i < sizeof (tokentab3) / sizeof (tokentab3[0]); i++) | |
1058 | { | |
1059 | if (strncmp (lexptr, tokentab3[i].operator, 3) == 0) | |
1060 | { | |
1061 | lexptr += 3; | |
1062 | return (tokentab3[i].token); | |
1063 | } | |
1064 | } | |
1065 | /* See if it is a special token of length 2. */ | |
1066 | for (i = 0; i < sizeof (tokentab2) / sizeof (tokentab2[0]); i++) | |
1067 | { | |
1068 | if (strncmp (lexptr, tokentab2[i].operator, 2) == 0) | |
1069 | { | |
1070 | lexptr += 2; | |
1071 | return (tokentab2[i].token); | |
1072 | } | |
1073 | } | |
1074 | /* Look for single character cases which which could be the first | |
1075 | character of some other multicharacter token, but aren't, or we | |
1076 | would already have found it. */ | |
1077 | switch (*lexptr) | |
1078 | { | |
1079 | case '/': | |
1080 | case '<': | |
1081 | case '>': | |
1082 | return (*lexptr++); | |
1083 | } | |
1084 | /* Look for other special tokens. */ | |
1085 | if (strncmp (lexptr, "TRUE", 4) == 0) /* FIXME: What about lowercase? */ | |
1086 | { | |
1087 | yylval.ulval = 1; | |
1088 | lexptr += 4; | |
1089 | return (BOOLEAN_LITERAL); | |
1090 | } | |
1091 | if (strncmp (lexptr, "FALSE", 5) == 0) /* FIXME: What about lowercase? */ | |
1092 | { | |
1093 | yylval.ulval = 0; | |
1094 | lexptr += 5; | |
1095 | return (BOOLEAN_LITERAL); | |
1096 | } | |
1097 | if ((token = decode_integer_literal ()) != 0) | |
1098 | { | |
1099 | return (token); | |
1100 | } | |
1101 | return (ILLEGAL_TOKEN); | |
1102 | } | |
1103 | ||
1104 | static void | |
1105 | yyerror (msg) | |
1106 | char *msg; /* unused */ | |
1107 | { | |
1108 | printf ("Parsing: %s\n", lexptr); | |
1109 | if (yychar < 256) | |
1110 | { | |
1111 | error ("Invalid syntax in expression near character '%c'.", yychar); | |
1112 | } | |
1113 | else | |
1114 | { | |
1115 | error ("Invalid syntax in expression"); | |
1116 | } | |
1117 | } | |
1118 | ||
1119 | \f | |
1120 | /* Table of operators and their precedences for printing expressions. */ | |
1121 | ||
1122 | const static struct op_print chill_op_print_tab[] = { | |
1123 | {"AND", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0}, | |
1124 | {"OR", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0}, | |
1125 | {"NOT", UNOP_LOGICAL_NOT, PREC_PREFIX, 0}, | |
1126 | {"MOD", BINOP_REM, PREC_MUL, 0}, | |
1127 | {":=", BINOP_ASSIGN, PREC_ASSIGN, 1}, | |
1128 | {"=", BINOP_EQUAL, PREC_EQUAL, 0}, | |
1129 | {"/=", BINOP_NOTEQUAL, PREC_EQUAL, 0}, | |
1130 | {"<=", BINOP_LEQ, PREC_ORDER, 0}, | |
1131 | {">=", BINOP_GEQ, PREC_ORDER, 0}, | |
1132 | {">", BINOP_GTR, PREC_ORDER, 0}, | |
1133 | {"<", BINOP_LESS, PREC_ORDER, 0}, | |
1134 | {"+", BINOP_ADD, PREC_ADD, 0}, | |
1135 | {"-", BINOP_SUB, PREC_ADD, 0}, | |
1136 | {"*", BINOP_MUL, PREC_MUL, 0}, | |
1137 | {"/", BINOP_DIV, PREC_MUL, 0}, | |
1138 | {"-", UNOP_NEG, PREC_PREFIX, 0}, | |
1139 | {NULL, 0, 0, 0} | |
1140 | }; | |
1141 | ||
1142 | \f | |
1143 | /* The built-in types of Chill. */ | |
1144 | ||
1145 | struct type *builtin_type_chill_bool; | |
1146 | struct type *builtin_type_chill_long; | |
1147 | struct type *builtin_type_chill_ulong; | |
1148 | struct type *builtin_type_chill_real; | |
1149 | ||
1150 | struct type ** const (chill_builtin_types[]) = | |
1151 | { | |
1152 | &builtin_type_chill_bool, | |
1153 | &builtin_type_chill_long, | |
1154 | &builtin_type_chill_ulong, | |
1155 | &builtin_type_chill_real, | |
1156 | 0 | |
1157 | }; | |
1158 | ||
1159 | const struct language_defn chill_language_defn = { | |
1160 | "chill", | |
1161 | language_chill, | |
1162 | chill_builtin_types, | |
1163 | range_check_on, | |
1164 | type_check_on, | |
1165 | chill_parse, /* parser */ | |
1166 | chill_error, /* parser error function */ | |
1167 | &BUILTIN_TYPE_LONGEST, /* longest signed integral type */ | |
1168 | &BUILTIN_TYPE_UNSIGNED_LONGEST,/* longest unsigned integral type */ | |
1169 | &builtin_type_chill_real, /* longest floating point type */ | |
1170 | "0x%x", "0x%", "x", /* Hex format, prefix, suffix */ | |
1171 | "0%o", "0%", "o", /* Octal format, prefix, suffix */ | |
1172 | chill_op_print_tab, /* expression operators for printing */ | |
1173 | LANG_MAGIC | |
1174 | }; | |
1175 | ||
1176 | /* Initialization for Chill */ | |
1177 | ||
1178 | void | |
1179 | _initialize_chill_exp () | |
1180 | { | |
1181 | builtin_type_chill_bool = | |
1182 | init_type (TYPE_CODE_BOOL, TARGET_INT_BIT / TARGET_CHAR_BIT, | |
1183 | TYPE_FLAG_UNSIGNED, | |
1184 | "BOOL", (struct objfile *) NULL); | |
1185 | builtin_type_chill_long = | |
1186 | init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT, | |
1187 | 0, | |
1188 | "LONG", (struct objfile *) NULL); | |
1189 | builtin_type_chill_ulong = | |
1190 | init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT, | |
1191 | TYPE_FLAG_UNSIGNED, | |
1192 | "ULONG", (struct objfile *) NULL); | |
1193 | builtin_type_chill_real = | |
1194 | init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, | |
1195 | 0, | |
1196 | "LONG_REAL", (struct objfile *) NULL); | |
1197 | ||
1198 | add_language (&chill_language_defn); | |
1199 | } |