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