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