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