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