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