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