* c-valprint.c (cp_print_class_member): Add extern decl.
[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 $$ = 0; /* FIXME */
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 Returns CHARACTER_LITERAL if a match is found.
1371 */
1372
1373 static int
1374 match_character_literal ()
1375 {
1376 char *tokptr = lexptr;
1377 int ival = 0;
1378
1379 if ((tolower (*tokptr) == 'c') && (*(tokptr + 1) == '\''))
1380 {
1381 /* We have a GNU chill extension form, so skip the leading "C'",
1382 decode the hex value, and then ensure that we have a trailing
1383 single quote character. */
1384 tokptr += 2;
1385 if (!decode_integer_value (16, &tokptr, &ival) || (*tokptr != '\''))
1386 {
1387 return (0);
1388 }
1389 tokptr++;
1390 }
1391 else if (*tokptr == '\'')
1392 {
1393 tokptr++;
1394
1395 /* Determine which form we have, either a control sequence or the
1396 single character form. */
1397
1398 if ((*tokptr == '^') && (*(tokptr + 1) == '('))
1399 {
1400 /* Match and decode a control sequence. Return zero if we don't
1401 find a valid integer literal, or if the next unconsumed character
1402 after the integer literal is not the trailing ')'.
1403 FIXME: We currently don't handle the multiple integer literal
1404 form. */
1405 tokptr += 2;
1406 if (!decode_integer_literal (&ival, &tokptr) || (*tokptr++ != ')'))
1407 {
1408 return (0);
1409 }
1410 }
1411 else
1412 {
1413 ival = *tokptr++;
1414 }
1415
1416 /* The trailing quote has not yet been consumed. If we don't find
1417 it, then we have no match. */
1418
1419 if (*tokptr++ != '\'')
1420 {
1421 return (0);
1422 }
1423 }
1424 else
1425 {
1426 /* Not a character literal. */
1427 return (0);
1428 }
1429 yylval.typed_val.val = ival;
1430 yylval.typed_val.type = builtin_type_chill_char;
1431 lexptr = tokptr;
1432 return (CHARACTER_LITERAL);
1433 }
1434
1435 /* Recognize an integer literal, as specified in Z.200 sec 5.2.4.2.
1436 Note that according to 5.2.4.2, a single "_" is also a valid integer
1437 literal, however GNU-chill requires there to be at least one "digit"
1438 in any integer literal. */
1439
1440 static int
1441 match_integer_literal ()
1442 {
1443 char *tokptr = lexptr;
1444 int ival;
1445
1446 if (!decode_integer_literal (&ival, &tokptr))
1447 {
1448 return (0);
1449 }
1450 else
1451 {
1452 yylval.typed_val.val = ival;
1453 yylval.typed_val.type = builtin_type_int;
1454 lexptr = tokptr;
1455 return (INTEGER_LITERAL);
1456 }
1457 }
1458
1459 /* Recognize a bit-string literal, as specified in Z.200 sec 5.2.4.8
1460 Note that according to 5.2.4.8, a single "_" is also a valid bit-string
1461 literal, however GNU-chill requires there to be at least one "digit"
1462 in any bit-string literal. */
1463
1464 static int
1465 match_bitstring_literal ()
1466 {
1467 char *tokptr = lexptr;
1468 int mask;
1469 int bitoffset = 0;
1470 int bitcount = 0;
1471 int base;
1472 int digit;
1473
1474 tempbufindex = 0;
1475
1476 /* Look for the required explicit base specifier. */
1477
1478 switch (*tokptr++)
1479 {
1480 case 'b':
1481 case 'B':
1482 base = 2;
1483 break;
1484 case 'o':
1485 case 'O':
1486 base = 8;
1487 break;
1488 case 'h':
1489 case 'H':
1490 base = 16;
1491 break;
1492 default:
1493 return (0);
1494 break;
1495 }
1496
1497 /* Ensure that the character after the explicit base is a single quote. */
1498
1499 if (*tokptr++ != '\'')
1500 {
1501 return (0);
1502 }
1503
1504 while (*tokptr != '\0' && *tokptr != '\'')
1505 {
1506 digit = tolower (*tokptr);
1507 tokptr++;
1508 switch (digit)
1509 {
1510 case '_':
1511 continue;
1512 case '0': case '1': case '2': case '3': case '4':
1513 case '5': case '6': case '7': case '8': case '9':
1514 digit -= '0';
1515 break;
1516 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
1517 digit -= 'a';
1518 digit += 10;
1519 break;
1520 default:
1521 return (0);
1522 break;
1523 }
1524 if (digit >= base)
1525 {
1526 /* Found something not in domain for current base. */
1527 return (0);
1528 }
1529 else
1530 {
1531 /* Extract bits from digit, starting with the msbit appropriate for
1532 the current base, and packing them into the bitstring byte,
1533 starting at the lsbit. */
1534 for (mask = (base >> 1); mask > 0; mask >>= 1)
1535 {
1536 bitcount++;
1537 CHECKBUF (1);
1538 if (digit & mask)
1539 {
1540 tempbuf[tempbufindex] |= (1 << bitoffset);
1541 }
1542 bitoffset++;
1543 if (bitoffset == HOST_CHAR_BIT)
1544 {
1545 bitoffset = 0;
1546 tempbufindex++;
1547 }
1548 }
1549 }
1550 }
1551
1552 /* Verify that we consumed everything up to the trailing single quote,
1553 and that we found some bits (IE not just underbars). */
1554
1555 if (*tokptr++ != '\'')
1556 {
1557 return (0);
1558 }
1559 else
1560 {
1561 yylval.sval.ptr = tempbuf;
1562 yylval.sval.length = bitcount;
1563 lexptr = tokptr;
1564 return (BIT_STRING_LITERAL);
1565 }
1566 }
1567
1568 /* Recognize tokens that start with '$'. These include:
1569
1570 $regname A native register name or a "standard
1571 register name".
1572 Return token GDB_REGNAME.
1573
1574 $variable A convenience variable with a name chosen
1575 by the user.
1576 Return token GDB_VARIABLE.
1577
1578 $digits Value history with index <digits>, starting
1579 from the first value which has index 1.
1580 Return GDB_LAST.
1581
1582 $$digits Value history with index <digits> relative
1583 to the last value. I.E. $$0 is the last
1584 value, $$1 is the one previous to that, $$2
1585 is the one previous to $$1, etc.
1586 Return token GDB_LAST.
1587
1588 $ | $0 | $$0 The last value in the value history.
1589 Return token GDB_LAST.
1590
1591 $$ An abbreviation for the second to the last
1592 value in the value history, I.E. $$1
1593 Return token GDB_LAST.
1594
1595 Note that we currently assume that register names and convenience
1596 variables follow the convention of starting with a letter or '_'.
1597
1598 */
1599
1600 static int
1601 match_dollar_tokens ()
1602 {
1603 char *tokptr;
1604 int regno;
1605 int namelength;
1606 int negate;
1607 int ival;
1608
1609 /* We will always have a successful match, even if it is just for
1610 a single '$', the abbreviation for $$0. So advance lexptr. */
1611
1612 tokptr = ++lexptr;
1613
1614 if (*tokptr == '_' || isalpha (*tokptr))
1615 {
1616 /* Look for a match with a native register name, usually something
1617 like "r0" for example. */
1618
1619 for (regno = 0; regno < NUM_REGS; regno++)
1620 {
1621 namelength = strlen (reg_names[regno]);
1622 if (STREQN (tokptr, reg_names[regno], namelength)
1623 && !isalnum (tokptr[namelength]))
1624 {
1625 yylval.lval = regno;
1626 lexptr += namelength + 1;
1627 return (GDB_REGNAME);
1628 }
1629 }
1630
1631 /* Look for a match with a standard register name, usually something
1632 like "pc", which gdb always recognizes as the program counter
1633 regardless of what the native register name is. */
1634
1635 for (regno = 0; regno < num_std_regs; regno++)
1636 {
1637 namelength = strlen (std_regs[regno].name);
1638 if (STREQN (tokptr, std_regs[regno].name, namelength)
1639 && !isalnum (tokptr[namelength]))
1640 {
1641 yylval.lval = std_regs[regno].regnum;
1642 lexptr += namelength;
1643 return (GDB_REGNAME);
1644 }
1645 }
1646
1647 /* Attempt to match against a convenience variable. Note that
1648 this will always succeed, because if no variable of that name
1649 already exists, the lookup_internalvar will create one for us.
1650 Also note that both lexptr and tokptr currently point to the
1651 start of the input string we are trying to match, and that we
1652 have already tested the first character for non-numeric, so we
1653 don't have to treat it specially. */
1654
1655 while (*tokptr == '_' || isalnum (*tokptr))
1656 {
1657 tokptr++;
1658 }
1659 yylval.sval.ptr = lexptr;
1660 yylval.sval.length = tokptr - lexptr;
1661 yylval.ivar = lookup_internalvar (copy_name (yylval.sval));
1662 lexptr = tokptr;
1663 return (GDB_VARIABLE);
1664 }
1665
1666 /* Since we didn't match against a register name or convenience
1667 variable, our only choice left is a history value. */
1668
1669 if (*tokptr == '$')
1670 {
1671 negate = 1;
1672 ival = 1;
1673 tokptr++;
1674 }
1675 else
1676 {
1677 negate = 0;
1678 ival = 0;
1679 }
1680
1681 /* Attempt to decode more characters as an integer value giving
1682 the index in the history list. If successful, the value will
1683 overwrite ival (currently 0 or 1), and if not, ival will be
1684 left alone, which is good since it is currently correct for
1685 the '$' or '$$' case. */
1686
1687 decode_integer_literal (&ival, &tokptr);
1688 yylval.lval = negate ? -ival : ival;
1689 lexptr = tokptr;
1690 return (GDB_LAST);
1691 }
1692
1693 struct token
1694 {
1695 char *operator;
1696 int token;
1697 };
1698
1699 static const struct token tokentab6[] =
1700 {
1701 { "LENGTH", LENGTH }
1702 };
1703
1704 static const struct token tokentab5[] =
1705 {
1706 { "LOWER", LOWER },
1707 { "UPPER", UPPER },
1708 { "ANDIF", ANDIF }
1709 };
1710
1711 static const struct token tokentab4[] =
1712 {
1713 { "PRED", PRED },
1714 { "SUCC", SUCC },
1715 { "CARD", CARD },
1716 { "SIZE", SIZE },
1717 { "ORIF", ORIF }
1718 };
1719
1720 static const struct token tokentab3[] =
1721 {
1722 { "NUM", NUM },
1723 { "ABS", ABS },
1724 { "MAX", MAX },
1725 { "MIN", MIN },
1726 { "MOD", MOD },
1727 { "REM", REM },
1728 { "NOT", NOT },
1729 { "XOR", LOGXOR },
1730 { "AND", LOGAND }
1731 };
1732
1733 static const struct token tokentab2[] =
1734 {
1735 { ":=", GDB_ASSIGNMENT },
1736 { "//", SLASH_SLASH },
1737 { "/=", NOTEQUAL },
1738 { "<=", LEQ },
1739 { ">=", GTR },
1740 { "IN", IN },
1741 { "OR", LOGIOR }
1742 };
1743
1744 /* Read one token, getting characters through lexptr. */
1745 /* This is where we will check to make sure that the language and the
1746 operators used are compatible. */
1747
1748 static int
1749 yylex ()
1750 {
1751 unsigned int i;
1752 int token;
1753 char *simplename;
1754 struct symbol *sym;
1755
1756 /* Skip over any leading whitespace. */
1757 while (isspace (*lexptr))
1758 {
1759 lexptr++;
1760 }
1761 /* Look for special single character cases which can't be the first
1762 character of some other multicharacter token. */
1763 switch (*lexptr)
1764 {
1765 case '\0':
1766 return (0);
1767 case ',':
1768 case '=':
1769 case ';':
1770 case '!':
1771 case '+':
1772 case '-':
1773 case '*':
1774 case '/':
1775 case '(':
1776 case ')':
1777 case '[':
1778 case ']':
1779 return (*lexptr++);
1780 }
1781 /* Look for characters which start a particular kind of multicharacter
1782 token, such as a character literal, register name, convenience
1783 variable name, string literal, etc. */
1784 switch (*lexptr)
1785 {
1786 case '\'':
1787 case '\"':
1788 /* First try to match a string literal, which is any nonzero
1789 sequence of characters enclosed in matching single or double
1790 quotes, except that a single character inside single quotes
1791 is a character literal, so we have to catch that case also. */
1792 token = match_string_literal ();
1793 if (token != 0)
1794 {
1795 return (token);
1796 }
1797 if (*lexptr == '\'')
1798 {
1799 token = match_character_literal ();
1800 if (token != 0)
1801 {
1802 return (token);
1803 }
1804 }
1805 break;
1806 case 'C':
1807 case 'c':
1808 token = match_character_literal ();
1809 if (token != 0)
1810 {
1811 return (token);
1812 }
1813 break;
1814 case '$':
1815 token = match_dollar_tokens ();
1816 if (token != 0)
1817 {
1818 return (token);
1819 }
1820 break;
1821 }
1822 /* See if it is a special token of length 6. */
1823 for (i = 0; i < sizeof (tokentab6) / sizeof (tokentab6[0]); i++)
1824 {
1825 if (STREQN (lexptr, tokentab6[i].operator, 6))
1826 {
1827 lexptr += 6;
1828 return (tokentab6[i].token);
1829 }
1830 }
1831 /* See if it is a special token of length 5. */
1832 for (i = 0; i < sizeof (tokentab5) / sizeof (tokentab5[0]); i++)
1833 {
1834 if (STREQN (lexptr, tokentab5[i].operator, 5))
1835 {
1836 lexptr += 5;
1837 return (tokentab5[i].token);
1838 }
1839 }
1840 /* See if it is a special token of length 4. */
1841 for (i = 0; i < sizeof (tokentab4) / sizeof (tokentab4[0]); i++)
1842 {
1843 if (STREQN (lexptr, tokentab4[i].operator, 4))
1844 {
1845 lexptr += 4;
1846 return (tokentab4[i].token);
1847 }
1848 }
1849 /* See if it is a special token of length 3. */
1850 for (i = 0; i < sizeof (tokentab3) / sizeof (tokentab3[0]); i++)
1851 {
1852 if (STREQN (lexptr, tokentab3[i].operator, 3))
1853 {
1854 lexptr += 3;
1855 return (tokentab3[i].token);
1856 }
1857 }
1858 /* See if it is a special token of length 2. */
1859 for (i = 0; i < sizeof (tokentab2) / sizeof (tokentab2[0]); i++)
1860 {
1861 if (STREQN (lexptr, tokentab2[i].operator, 2))
1862 {
1863 lexptr += 2;
1864 return (tokentab2[i].token);
1865 }
1866 }
1867 /* Look for single character cases which which could be the first
1868 character of some other multicharacter token, but aren't, or we
1869 would already have found it. */
1870 switch (*lexptr)
1871 {
1872 case ':':
1873 case '/':
1874 case '<':
1875 case '>':
1876 return (*lexptr++);
1877 }
1878 /* Look for other special tokens. */
1879 if (STREQN (lexptr, "TRUE", 4)) /* FIXME: What about lowercase? */
1880 {
1881 yylval.ulval = 1;
1882 lexptr += 4;
1883 return (BOOLEAN_LITERAL);
1884 }
1885 if (STREQN (lexptr, "FALSE", 5)) /* FIXME: What about lowercase? */
1886 {
1887 yylval.ulval = 0;
1888 lexptr += 5;
1889 return (BOOLEAN_LITERAL);
1890 }
1891 /* Look for a float literal before looking for an integer literal, so
1892 we match as much of the input stream as possible. */
1893 token = match_float_literal ();
1894 if (token != 0)
1895 {
1896 return (token);
1897 }
1898 token = match_bitstring_literal ();
1899 if (token != 0)
1900 {
1901 return (token);
1902 }
1903 token = match_integer_literal ();
1904 if (token != 0)
1905 {
1906 return (token);
1907 }
1908
1909 /* Try to match a simple name string, and if a match is found, then
1910 further classify what sort of name it is and return an appropriate
1911 token. Note that attempting to match a simple name string consumes
1912 the token from lexptr, so we can't back out if we later find that
1913 we can't classify what sort of name it is. */
1914
1915 simplename = match_simple_name_string ();
1916 if (simplename != NULL)
1917 {
1918 sym = lookup_symbol (simplename, expression_context_block,
1919 VAR_NAMESPACE, (int *) NULL,
1920 (struct symtab **) NULL);
1921 if (sym != NULL)
1922 {
1923 yylval.ssym.stoken.ptr = NULL;
1924 yylval.ssym.stoken.length = 0;
1925 yylval.ssym.sym = sym;
1926 yylval.ssym.is_a_field_of_this = 0; /* FIXME, C++'ism */
1927 switch (SYMBOL_CLASS (sym))
1928 {
1929 case LOC_BLOCK:
1930 /* Found a procedure name. */
1931 return (GENERAL_PROCEDURE_NAME);
1932 case LOC_STATIC:
1933 /* Found a global or local static variable. */
1934 return (LOCATION_NAME);
1935 case LOC_REGISTER:
1936 case LOC_ARG:
1937 case LOC_REF_ARG:
1938 case LOC_REGPARM:
1939 case LOC_LOCAL:
1940 case LOC_LOCAL_ARG:
1941 if (innermost_block == NULL
1942 || contained_in (block_found, innermost_block))
1943 {
1944 innermost_block = block_found;
1945 }
1946 return (LOCATION_NAME);
1947 break;
1948 case LOC_CONST:
1949 case LOC_LABEL:
1950 return (LOCATION_NAME);
1951 break;
1952 case LOC_UNDEF:
1953 case LOC_TYPEDEF:
1954 case LOC_CONST_BYTES:
1955 error ("Symbol \"%s\" names no location.", simplename);
1956 break;
1957 }
1958 }
1959 else if (!have_full_symbols () && !have_partial_symbols ())
1960 {
1961 error ("No symbol table is loaded. Use the \"file\" command.");
1962 }
1963 else
1964 {
1965 error ("No symbol \"%s\" in current context.", simplename);
1966 }
1967 }
1968
1969 /* Catch single character tokens which are not part of some
1970 longer token. */
1971
1972 switch (*lexptr)
1973 {
1974 case '.': /* Not float for example. */
1975 return (*lexptr++);
1976 }
1977
1978 return (ILLEGAL_TOKEN);
1979 }
1980
1981 void
1982 yyerror (msg)
1983 char *msg; /* unused */
1984 {
1985 printf ("Parsing: %s\n", lexptr);
1986 if (yychar < 256)
1987 {
1988 error ("Invalid syntax in expression near character '%c'.", yychar);
1989 }
1990 else
1991 {
1992 error ("Invalid syntax in expression");
1993 }
1994 }