]> Git Repo - binutils.git/blob - gdb/ch-exp.y
use waitpid instead of wait4
[binutils.git] / gdb / ch-exp.y
1 /* YACC grammar for Chill expressions, for GDB.
2    Copyright (C) 1992 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
20 /* Parse a Chill expression from text in a string,
21    and return the result as a  struct expression  pointer.
22    That structure contains arithmetic operations in reverse polish,
23    with constants represented by operations that are followed by special data.
24    See expression.h for the details of the format.
25    What is important here is that it can be built up sequentially
26    during the process of parsing; the lower levels of the tree always
27    come first in the result.
28
29    Note that malloc's and realloc's in this file are transformed to
30    xmalloc and xrealloc respectively by the same sed command in the
31    makefile that remaps any other malloc/realloc inserted by the parser
32    generator.  Doing this with #defines and trying to control the interaction
33    with include files (<malloc.h> and <stdlib.h> for example) just became
34    too messy, particularly when such includes can be inserted at random
35    times by the parser generator.
36
37    Also note that the language accepted by this parser is more liberal
38    than the one accepted by an actual Chill compiler.  For example, the
39    language rule that a simple name string can not be one of the reserved
40    simple name strings is not enforced (e.g "case" is not treated as a
41    reserved name).  Another example is that Chill is a strongly typed
42    language, and certain expressions that violate the type constraints
43    may still be evaluated if gdb can do so in a meaningful manner, while
44    such expressions would be rejected by the compiler.  The reason for
45    this more liberal behavior is the philosophy that the debugger
46    is intended to be a tool that is used by the programmer when things
47    go wrong, and as such, it should provide as few artificial barriers
48    to it's use as possible.  If it can do something meaningful, even
49    something that violates language contraints that are enforced by the
50    compiler, it should do so without complaint.
51
52  */
53    
54 %{
55
56 #include "defs.h"
57 #include "expression.h"
58 #include "language.h"
59 #include "value.h"
60 #include "parser-defs.h"
61 #include "ch-lang.h"
62
63 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
64    as well as gratuitiously global symbol names, so we can have multiple
65    yacc generated parsers in gdb.  Note that these are only the variables
66    produced by yacc.  If other parser generators (bison, byacc, etc) produce
67    additional global names that conflict at link time, then those parser
68    generators need to be fixed instead of adding those names to this list. */
69
70 #define yymaxdepth chill_maxdepth
71 #define yyparse chill_parse
72 #define yylex   chill_lex
73 #define yyerror chill_error
74 #define yylval  chill_lval
75 #define yychar  chill_char
76 #define yydebug chill_debug
77 #define yypact  chill_pact
78 #define yyr1    chill_r1
79 #define yyr2    chill_r2
80 #define yydef   chill_def
81 #define yychk   chill_chk
82 #define yypgo   chill_pgo
83 #define yyact   chill_act
84 #define yyexca  chill_exca
85 #define yyerrflag chill_errflag
86 #define yynerrs chill_nerrs
87 #define yyps    chill_ps
88 #define yypv    chill_pv
89 #define yys     chill_s
90 #define yy_yys  chill_yys
91 #define yystate chill_state
92 #define yytmp   chill_tmp
93 #define yyv     chill_v
94 #define yy_yyv  chill_yyv
95 #define yyval   chill_val
96 #define yylloc  chill_lloc
97 #define yyreds  chill_reds              /* With YYDEBUG defined */
98 #define yytoks  chill_toks              /* With YYDEBUG defined */
99
100 #ifndef YYDEBUG
101 #define YYDEBUG 0               /* Default to no yydebug support */
102 #endif
103
104 int
105 yyparse PARAMS ((void));
106
107 static int
108 yylex PARAMS ((void));
109
110 void
111 yyerror PARAMS ((char *));
112
113 %}
114
115 /* Although the yacc "value" of an expression is not used,
116    since the result is stored in the structure being created,
117    other node types do have values.  */
118
119 %union
120   {
121     LONGEST lval;
122     unsigned LONGEST ulval;
123     struct {
124       LONGEST val;
125       struct type *type;
126     } typed_val;
127     double dval;
128     struct symbol *sym;
129     struct type *tval;
130     struct stoken sval;
131     struct ttype tsym;
132     struct symtoken ssym;
133     int voidval;
134     struct block *bval;
135     enum exp_opcode opcode;
136     struct internalvar *ivar;
137
138     struct type **tvec;
139     int *ivec;
140   }
141
142 %token <voidval> FIXME
143
144 %token <typed_val>      INTEGER_LITERAL
145 %token <ulval>          BOOLEAN_LITERAL
146 %token <typed_val>      CHARACTER_LITERAL
147 %token <dval>           FLOAT_LITERAL
148 %token <ssym>           GENERAL_PROCEDURE_NAME
149 %token <ssym>           LOCATION_NAME
150 %token <voidval>        SET_LITERAL
151 %token <voidval>        EMPTINESS_LITERAL
152 %token <voidval>        CHARACTER_STRING_LITERAL
153 %token <voidval>        BIT_STRING_LITERAL
154
155 %token <voidval>        STRING
156 %token <voidval>        CONSTANT
157 %token <voidval>        '.'
158 %token <voidval>        ';'
159 %token <voidval>        ':'
160 %token <voidval>        CASE
161 %token <voidval>        OF
162 %token <voidval>        ESAC
163 %token <voidval>        LOGIOR
164 %token <voidval>        ORIF
165 %token <voidval>        LOGXOR
166 %token <voidval>        LOGAND
167 %token <voidval>        ANDIF
168 %token <voidval>        '='
169 %token <voidval>        NOTEQUAL
170 %token <voidval>        '>'
171 %token <voidval>        GTR
172 %token <voidval>        '<'
173 %token <voidval>        LEQ
174 %token <voidval>        IN
175 %token <voidval>        '+'
176 %token <voidval>        '-'
177 %token <voidval>        '*'
178 %token <voidval>        '/'
179 %token <voidval>        SLASH_SLASH
180 %token <voidval>        MOD
181 %token <voidval>        REM
182 %token <voidval>        NOT
183 %token <voidval>        POINTER
184 %token <voidval>        RECEIVE
185 %token <voidval>        SC
186 %token <voidval>        '['
187 %token <voidval>        ']'
188 %token <voidval>        '('
189 %token <voidval>        ')'
190 %token <voidval>        UP
191 %token <voidval>        IF
192 %token <voidval>        THEN
193 %token <voidval>        ELSE
194 %token <voidval>        FI
195 %token <voidval>        ELSIF
196 %token <voidval>        ILLEGAL_TOKEN
197
198 /* Tokens which are not Chill tokens used in expressions, but rather GDB
199    specific things that we recognize in the same context as Chill tokens
200    (register names for example). */
201
202 %token <lval>           GDB_REGNAME     /* Machine register name */
203 %token <lval>           GDB_LAST        /* Value history */
204 %token <ivar>           GDB_VARIABLE    /* Convenience variable */
205 %token <voidval>        GDB_ASSIGNMENT  /* Assign value to somewhere */
206
207 %type <voidval>         location
208 %type <voidval>         access_name
209 %type <voidval>         primitive_value
210 %type <voidval>         location_contents
211 %type <voidval>         value_name
212 %type <voidval>         literal
213 %type <voidval>         tuple
214 %type <voidval>         value_string_element
215 %type <voidval>         value_string_slice
216 %type <voidval>         value_array_element
217 %type <voidval>         value_array_slice
218 %type <voidval>         value_structure_field
219 %type <voidval>         expression_conversion
220 %type <voidval>         value_procedure_call
221 %type <voidval>         value_built_in_routine_call
222 %type <voidval>         start_expression
223 %type <voidval>         zero_adic_operator
224 %type <voidval>         parenthesised_expression
225 %type <voidval>         value
226 %type <voidval>         undefined_value
227 %type <voidval>         expression
228 %type <voidval>         conditional_expression
229 %type <voidval>         then_alternative
230 %type <voidval>         else_alternative
231 %type <voidval>         sub_expression
232 %type <voidval>         value_case_alternative
233 %type <voidval>         operand_0
234 %type <voidval>         operand_1
235 %type <voidval>         operand_2
236 %type <voidval>         operand_3
237 %type <voidval>         operand_4
238 %type <voidval>         operand_5
239 %type <voidval>         operand_6
240 %type <voidval>         integer_literal_expression
241 %type <voidval>         synonym_name
242 %type <voidval>         value_enumeration_name
243 %type <voidval>         value_do_with_name
244 %type <voidval>         value_receive_name
245 %type <voidval>         string_primitive_value
246 %type <voidval>         start_element
247 %type <voidval>         left_element
248 %type <voidval>         right_element
249 %type <voidval>         slice_size
250 %type <voidval>         array_primitive_value
251 %type <voidval>         expression_list
252 %type <voidval>         lower_element
253 %type <voidval>         upper_element
254 %type <voidval>         first_element
255 %type <voidval>         structure_primitive_value
256 %type <voidval>         field_name
257 %type <voidval>         mode_name
258 %type <voidval>         boolean_expression
259 %type <voidval>         case_selector_list
260 %type <voidval>         subexpression
261 %type <voidval>         case_label_specification
262 %type <voidval>         buffer_location
263
264 %type <voidval>         single_assignment_action
265
266 %%
267
268 /* Z.200, 5.3.1 */
269
270 value           :       expression
271                         {
272                           $$ = 0;       /* FIXME */
273                         }
274                 |       undefined_value
275                         {
276                           $$ = 0;       /* FIXME */
277                         }
278                 ;
279
280 undefined_value :       FIXME
281                         {
282                           $$ = 0;       /* FIXME */
283                         }
284                 ;
285
286 /* Z.200, 4.2.1 */
287
288 location        :       access_name
289                         {
290                           $$ = 0;       /* FIXME */
291                         }
292                 |       FIXME
293                         {
294                           $$ = 0;       /* FIXME */
295                         }
296                 ;
297
298 /* Z.200, 4.2.2 */
299
300 access_name     :       LOCATION_NAME
301                         {
302                           write_exp_elt_opcode (OP_VAR_VALUE);
303                           write_exp_elt_sym ($1.sym);
304                           write_exp_elt_opcode (OP_VAR_VALUE);
305                         }
306                 |       GDB_LAST                /* gdb specific */
307                         {
308                           write_exp_elt_opcode (OP_LAST);
309                           write_exp_elt_longcst ($1);
310                           write_exp_elt_opcode (OP_LAST); 
311                         }
312                 |       GDB_REGNAME             /* gdb specific */
313                         {
314                           write_exp_elt_opcode (OP_REGISTER);
315                           write_exp_elt_longcst ($1);
316                           write_exp_elt_opcode (OP_REGISTER); 
317                         }
318                 |       GDB_VARIABLE    /* gdb specific */
319                         {
320                           write_exp_elt_opcode (OP_INTERNALVAR);
321                           write_exp_elt_intern ($1);
322                           write_exp_elt_opcode (OP_INTERNALVAR); 
323                         }
324                 |       FIXME
325                         {
326                           $$ = 0;       /* FIXME */
327                         }
328                 ;
329
330 /* Z.200, 4.2.8 */
331
332 expression_list :       expression
333                         {
334                           arglist_len = 1;
335                         }
336                 |       expression_list ',' expression
337                         {
338                           arglist_len++;
339                         }
340
341 /* Z.200, 5.2.1 */
342
343 primitive_value :       location_contents
344                         {
345                           $$ = 0;       /* FIXME */
346                         }
347                 |       value_name
348                         {
349                           $$ = 0;       /* FIXME */
350                         }
351                 |       literal
352                         {
353                           $$ = 0;       /* FIXME */
354                         }
355                 |       tuple
356                         {
357                           $$ = 0;       /* FIXME */
358                         }
359                 |       value_string_element
360                         {
361                           $$ = 0;       /* FIXME */
362                         }
363                 |       value_string_slice
364                         {
365                           $$ = 0;       /* FIXME */
366                         }
367                 |       value_array_element
368                         {
369                           $$ = 0;       /* FIXME */
370                         }
371                 |       value_array_slice
372                         {
373                           $$ = 0;       /* FIXME */
374                         }
375                 |       value_structure_field
376                         {
377                           $$ = 0;       /* FIXME */
378                         }
379                 |       expression_conversion
380                         {
381                           $$ = 0;       /* FIXME */
382                         }
383                 |       value_procedure_call
384                         {
385                           $$ = 0;       /* FIXME */
386                         }
387                 |       value_built_in_routine_call
388                         {
389                           $$ = 0;       /* FIXME */
390                         }
391                 |       start_expression
392                         {
393                           $$ = 0;       /* FIXME */
394                         }
395                 |       zero_adic_operator
396                         {
397                           $$ = 0;       /* FIXME */
398                         }
399                 |       parenthesised_expression
400                         {
401                           $$ = 0;       /* FIXME */
402                         }
403                 ;
404
405 /* Z.200, 5.2.2 */
406
407 location_contents:      location
408                         {
409                           $$ = 0;       /* FIXME */
410                         }
411                 ;
412
413 /* Z.200, 5.2.3 */
414
415 value_name      :       synonym_name
416                         {
417                           $$ = 0;       /* FIXME */
418                         }
419                 |       value_enumeration_name
420                         {
421                           $$ = 0;       /* FIXME */
422                         }
423                 |       value_do_with_name
424                         {
425                           $$ = 0;       /* FIXME */
426                         }
427                 |       value_receive_name
428                         {
429                           $$ = 0;       /* FIXME */
430                         }
431                 |       GENERAL_PROCEDURE_NAME
432                         {
433                           write_exp_elt_opcode (OP_VAR_VALUE);
434                           write_exp_elt_sym ($1.sym);
435                           write_exp_elt_opcode (OP_VAR_VALUE);
436                         }
437                 ;
438
439 /* Z.200, 5.2.4.1 */
440
441 literal         :       INTEGER_LITERAL
442                         {
443                           write_exp_elt_opcode (OP_LONG);
444                           write_exp_elt_type ($1.type);
445                           write_exp_elt_longcst ((LONGEST) ($1.val));
446                           write_exp_elt_opcode (OP_LONG);
447                         }
448                 |       BOOLEAN_LITERAL
449                         {
450                           write_exp_elt_opcode (OP_BOOL);
451                           write_exp_elt_longcst ((LONGEST) $1);
452                           write_exp_elt_opcode (OP_BOOL);
453                         }
454                 |       CHARACTER_LITERAL
455                         {
456                           write_exp_elt_opcode (OP_LONG);
457                           write_exp_elt_type ($1.type);
458                           write_exp_elt_longcst ((LONGEST) ($1.val));
459                           write_exp_elt_opcode (OP_LONG);
460                         }
461                 |       FLOAT_LITERAL
462                         {
463                           write_exp_elt_opcode (OP_DOUBLE);
464                           write_exp_elt_type (builtin_type_double);
465                           write_exp_elt_dblcst ($1);
466                           write_exp_elt_opcode (OP_DOUBLE);
467                         }
468                 |       SET_LITERAL
469                         {
470                           $$ = 0;       /* FIXME */
471                         }
472                 |       EMPTINESS_LITERAL
473                         {
474                           $$ = 0;       /* FIXME */
475                         }
476                 |       CHARACTER_STRING_LITERAL
477                         {
478                           $$ = 0;       /* FIXME */
479                         }
480                 |       BIT_STRING_LITERAL
481                         {
482                           $$ = 0;       /* FIXME */
483                         }
484                 ;
485
486 /* Z.200, 5.2.5 */
487
488 tuple           :       FIXME
489                         {
490                           $$ = 0;       /* FIXME */
491                         }
492                 ;
493
494
495 /* Z.200, 5.2.6 */
496
497 value_string_element:   string_primitive_value '(' start_element ')'
498                         {
499                           $$ = 0;       /* FIXME */
500                         }
501                 ;
502
503 /* Z.200, 5.2.7 */
504
505 value_string_slice:     string_primitive_value '(' left_element ':' right_element ')'
506                         {
507                           $$ = 0;       /* FIXME */
508                         }
509                 |       string_primitive_value '(' start_element UP slice_size ')'
510                         {
511                           $$ = 0;       /* FIXME */
512                         }
513                 ;
514
515 /* Z.200, 5.2.8 */
516
517 value_array_element:    array_primitive_value '('
518                                 /* This is to save the value of arglist_len
519                                    being accumulated for each dimension. */
520                                 { start_arglist (); }
521                         expression_list ')'
522                         {
523                           write_exp_elt_opcode (MULTI_SUBSCRIPT);
524                           write_exp_elt_longcst ((LONGEST) end_arglist ());
525                           write_exp_elt_opcode (MULTI_SUBSCRIPT);
526                         }
527                 ;
528
529 /* Z.200, 5.2.9 */
530
531 value_array_slice:      array_primitive_value '(' lower_element ':' upper_element ')'
532                         {
533                           $$ = 0;       /* FIXME */
534                         }
535                 |       array_primitive_value '(' first_element UP slice_size ')'
536                         {
537                           $$ = 0;       /* FIXME */
538                         }
539                 ;
540
541 /* Z.200, 5.2.10 */
542
543 value_structure_field:  structure_primitive_value '.' field_name
544                         {
545                           $$ = 0;       /* FIXME */
546                         }
547                 ;
548
549 /* Z.200, 5.2.11 */
550
551 expression_conversion:  mode_name '(' expression ')'
552                         {
553                           $$ = 0;       /* FIXME */
554                         }
555                 ;
556
557 /* Z.200, 5.2.12 */
558
559 value_procedure_call:   FIXME
560                         {
561                           $$ = 0;       /* FIXME */
562                         }
563                 ;
564
565 /* Z.200, 5.2.13 */
566
567 value_built_in_routine_call:    FIXME
568                         {
569                           $$ = 0;       /* FIXME */
570                         }
571                 ;
572
573 /* Z.200, 5.2.14 */
574
575 start_expression:       FIXME
576                         {
577                           $$ = 0;       /* FIXME */
578                         }       /* Not in GNU-Chill */
579                 ;
580
581 /* Z.200, 5.2.15 */
582
583 zero_adic_operator:     FIXME
584                         {
585                           $$ = 0;       /* FIXME */
586                         }
587                 ;
588
589 /* Z.200, 5.2.16 */
590
591 parenthesised_expression:       '(' expression ')'
592                         {
593                           $$ = 0;       /* FIXME */
594                         }
595                 ;
596
597 /* Z.200, 5.3.2 */
598
599 expression      :       operand_0
600                         {
601                           $$ = 0;       /* FIXME */
602                         }
603                 |       conditional_expression
604                         {
605                           $$ = 0;       /* FIXME */
606                         }
607                 ;
608
609 conditional_expression : IF boolean_expression then_alternative else_alternative FI
610                         {
611                           $$ = 0;       /* FIXME */
612                         }
613                 |       CASE case_selector_list OF value_case_alternative '[' ELSE sub_expression ']' ESAC
614                         {
615                           $$ = 0;       /* FIXME */
616                         }
617                 ;
618
619 then_alternative:       THEN subexpression
620                         {
621                           $$ = 0;       /* FIXME */
622                         }
623                 ;
624
625 else_alternative:       ELSE subexpression
626                         {
627                           $$ = 0;       /* FIXME */
628                         }
629                 |       ELSIF boolean_expression then_alternative else_alternative
630                         {
631                           $$ = 0;       /* FIXME */
632                         }
633                 ;
634
635 sub_expression  :       expression
636                         {
637                           $$ = 0;       /* FIXME */
638                         }
639                 ;
640
641 value_case_alternative: case_label_specification ':' sub_expression ';'
642                         {
643                           $$ = 0;       /* FIXME */
644                         }
645                 ;
646
647 /* Z.200, 5.3.3 */
648
649 operand_0       :       operand_1
650                         {
651                           $$ = 0;       /* FIXME */
652                         }
653                 |       operand_0 LOGIOR operand_1
654                         {
655                           write_exp_elt_opcode (BINOP_BITWISE_IOR);
656                         }
657                 |       operand_0 ORIF operand_1
658                         {
659                           $$ = 0;       /* FIXME */
660                         }
661                 |       operand_0 LOGXOR operand_1
662                         {
663                           write_exp_elt_opcode (BINOP_BITWISE_XOR);
664                         }
665                 |       single_assignment_action
666                         {
667                           $$ = 0;       /* FIXME */
668                         }
669                 ;
670
671 /* Z.200, 5.3.4 */
672
673 operand_1       :       operand_2
674                         {
675                           $$ = 0;       /* FIXME */
676                         }
677                 |       operand_1 LOGAND operand_2
678                         {
679                           write_exp_elt_opcode (BINOP_BITWISE_AND);
680                         }
681                 |       operand_1 ANDIF operand_2
682                         {
683                           $$ = 0;       /* FIXME */
684                         }
685                 ;
686
687 /* Z.200, 5.3.5 */
688
689 operand_2       :       operand_3
690                         {
691                           $$ = 0;       /* FIXME */
692                         }
693                 |       operand_2 '=' operand_3
694                         {
695                           write_exp_elt_opcode (BINOP_EQUAL);
696                         }
697                 |       operand_2 NOTEQUAL operand_3
698                         {
699                           write_exp_elt_opcode (BINOP_NOTEQUAL);
700                         }
701                 |       operand_2 '>' operand_3
702                         {
703                           write_exp_elt_opcode (BINOP_GTR);
704                         }
705                 |       operand_2 GTR operand_3
706                         {
707                           write_exp_elt_opcode (BINOP_GEQ);
708                         }
709                 |       operand_2 '<' operand_3
710                         {
711                           write_exp_elt_opcode (BINOP_LESS);
712                         }
713                 |       operand_2 LEQ operand_3
714                         {
715                           write_exp_elt_opcode (BINOP_LEQ);
716                         }
717                 |       operand_2 IN operand_3
718                         {
719                           $$ = 0;       /* FIXME */
720                         }
721                 ;
722
723
724 /* Z.200, 5.3.6 */
725
726 operand_3       :       operand_4
727                         {
728                           $$ = 0;       /* FIXME */
729                         }
730                 |       operand_3 '+' operand_4
731                         {
732                           write_exp_elt_opcode (BINOP_ADD);
733                         }
734                 |       operand_3 '-' operand_4
735                         {
736                           write_exp_elt_opcode (BINOP_SUB);
737                         }
738                 |       operand_3 SLASH_SLASH operand_4
739                         {
740                           $$ = 0;       /* FIXME */
741                         }
742                 ;
743
744 /* Z.200, 5.3.7 */
745
746 operand_4       :       operand_5
747                         {
748                           $$ = 0;       /* FIXME */
749                         }
750                 |       operand_4 '*' operand_5
751                         {
752                           write_exp_elt_opcode (BINOP_MUL);
753                         }
754                 |       operand_4 '/' operand_5
755                         {
756                           write_exp_elt_opcode (BINOP_DIV);
757                         }
758                 |       operand_4 MOD operand_5
759                         {
760                           write_exp_elt_opcode (BINOP_MOD);
761                         }
762                 |       operand_4 REM operand_5
763                         {
764                           write_exp_elt_opcode (BINOP_REM);
765                         }
766                 ;
767
768 /* Z.200, 5.3.8 */
769
770 operand_5       :       operand_6
771                         {
772                           $$ = 0;       /* FIXME */
773                         }
774                 |       '-' operand_6
775                         {
776                           write_exp_elt_opcode (UNOP_NEG);
777                         }
778                 |       NOT operand_6
779                         {
780                           write_exp_elt_opcode (UNOP_LOGICAL_NOT);
781                         }
782                 |       '(' integer_literal_expression ')' operand_6
783                         {
784                           $$ = 0;       /* FIXME */
785                         }
786                 ;
787
788 /* Z.200, 5.3.9 */
789
790 operand_6       :       POINTER location
791                         {
792                           $$ = 0;       /* FIXME */
793                         }
794                 |       RECEIVE buffer_location
795                         {
796                           $$ = 0;       /* FIXME */
797                         }
798                 |       primitive_value
799                         {
800                           $$ = 0;       /* FIXME */
801                         }
802                 ;
803
804
805 /* Z.200, 6.2 */
806
807 single_assignment_action :      location GDB_ASSIGNMENT value
808                         {
809                           write_exp_elt_opcode (BINOP_ASSIGN);
810                         }
811
812 /* Z.200, 12.4.3 */
813 /* FIXME:  For now we just accept only a single integer literal. */
814
815 integer_literal_expression:
816                         INTEGER_LITERAL
817                         {
818                           $$ = 0;
819                         }
820
821 /* Z.200, 12.4.3 */
822
823 array_primitive_value : primitive_value
824                         {
825                           $$ = 0;
826                         }
827
828
829 /* Things which still need productions... */
830
831 synonym_name            :       FIXME { $$ = 0; }
832 value_enumeration_name  :       FIXME { $$ = 0; }
833 value_do_with_name      :       FIXME { $$ = 0; }
834 value_receive_name      :       FIXME { $$ = 0; }
835 string_primitive_value  :       FIXME { $$ = 0; }
836 start_element           :       FIXME { $$ = 0; }
837 left_element            :       FIXME { $$ = 0; }
838 right_element           :       FIXME { $$ = 0; }
839 slice_size              :       FIXME { $$ = 0; }
840 lower_element           :       FIXME { $$ = 0; }
841 upper_element           :       FIXME { $$ = 0; }
842 first_element           :       FIXME { $$ = 0; }
843 structure_primitive_value:      FIXME { $$ = 0; }
844 field_name              :       FIXME { $$ = 0; }
845 mode_name               :       FIXME { $$ = 0; }
846 boolean_expression      :       FIXME { $$ = 0; }
847 case_selector_list      :       FIXME { $$ = 0; }
848 subexpression           :       FIXME { $$ = 0; }
849 case_label_specification:       FIXME { $$ = 0; }
850 buffer_location         :       FIXME { $$ = 0; }
851
852 %%
853
854 /* Try to consume a simple name string token.  If successful, returns
855    a pointer to a nullbyte terminated copy of the name that can be used
856    in symbol table lookups.  If not successful, returns NULL. */
857
858 static char *
859 match_simple_name_string ()
860 {
861   char *tokptr = lexptr;
862
863   if (isalpha (*tokptr))
864     {
865       do {
866         tokptr++;
867       } while (isalpha (*tokptr) || isdigit (*tokptr) || (*tokptr == '_'));
868       yylval.sval.ptr = lexptr;
869       yylval.sval.length = tokptr - lexptr;
870       lexptr = tokptr;
871       return (copy_name (yylval.sval));
872     }
873   return (NULL);
874 }
875
876 /* Start looking for a value composed of valid digits as set by the base
877    in use.  Note that '_' characters are valid anywhere, in any quantity,
878    and are simply ignored.  Since we must find at least one valid digit,
879    or reject this token as an integer literal, we keep track of how many
880    digits we have encountered. */
881   
882 static int
883 decode_integer_value (base, tokptrptr, ivalptr)
884   int base;
885   char **tokptrptr;
886   int *ivalptr;
887 {
888   char *tokptr = *tokptrptr;
889   int temp;
890   int digits = 0;
891
892   while (*tokptr != '\0')
893     {
894       temp = tolower (*tokptr);
895       tokptr++;
896       switch (temp)
897         {
898         case '_':
899           continue;
900         case '0':  case '1':  case '2':  case '3':  case '4':
901         case '5':  case '6':  case '7':  case '8':  case '9':
902           temp -= '0';
903           break;
904         case 'a':  case 'b':  case 'c':  case 'd':  case 'e': case 'f':
905           temp -= 'a';
906           temp += 10;
907           break;
908         default:
909           temp = base;
910           break;
911         }
912       if (temp < base)
913         {
914           digits++;
915           *ivalptr *= base;
916           *ivalptr += temp;
917         }
918       else
919         {
920           /* Found something not in domain for current base. */
921           tokptr--;     /* Unconsume what gave us indigestion. */
922           break;
923         }
924     }
925   
926   /* If we didn't find any digits, then we don't have a valid integer
927      value, so reject the entire token.  Otherwise, update the lexical
928      scan pointer, and return non-zero for success. */
929   
930   if (digits == 0)
931     {
932       return (0);
933     }
934   else
935     {
936       *tokptrptr = tokptr;
937       return (1);
938     }
939 }
940
941 static int
942 decode_integer_literal (valptr, tokptrptr)
943   int *valptr;
944   char **tokptrptr;
945 {
946   char *tokptr = *tokptrptr;
947   int base = 0;
948   int ival = 0;
949   int explicit_base = 0;
950   
951   /* Look for an explicit base specifier, which is optional. */
952   
953   switch (*tokptr)
954     {
955     case 'd':
956     case 'D':
957       explicit_base++;
958       base = 10;
959       tokptr++;
960       break;
961     case 'b':
962     case 'B':
963       explicit_base++;
964       base = 2;
965       tokptr++;
966       break;
967     case 'h':
968     case 'H':
969       explicit_base++;
970       base = 16;
971       tokptr++;
972       break;
973     case 'o':
974     case 'O':
975       explicit_base++;
976       base = 8;
977       tokptr++;
978       break;
979     default:
980       base = 10;
981       break;
982     }
983   
984   /* If we found an explicit base ensure that the character after the
985      explicit base is a single quote. */
986   
987   if (explicit_base && (*tokptr++ != '\''))
988     {
989       return (0);
990     }
991   
992   /* Attempt to decode whatever follows as an integer value in the
993      indicated base, updating the token pointer in the process and
994      computing the value into ival.  Also, if we have an explicit
995      base, then the next character must not be a single quote, or we
996      have a bitstring literal, so reject the entire token in this case.
997      Otherwise, update the lexical scan pointer, and return non-zero
998      for success. */
999
1000   if (!decode_integer_value (base, &tokptr, &ival))
1001     {
1002       return (0);
1003     }
1004   else if (explicit_base && (*tokptr == '\''))
1005     {
1006       return (0);
1007     }
1008   else
1009     {
1010       *valptr = ival;
1011       *tokptrptr = tokptr;
1012       return (1);
1013     }
1014 }
1015
1016 /*  If it wasn't for the fact that floating point values can contain '_'
1017     characters, we could just let strtod do all the hard work by letting it
1018     try to consume as much of the current token buffer as possible and
1019     find a legal conversion.  Unfortunately we need to filter out the '_'
1020     characters before calling strtod, which we do by copying the other
1021     legal chars to a local buffer to be converted.  However since we also
1022     need to keep track of where the last unconsumed character in the input
1023     buffer is, we have transfer only as many characters as may compose a
1024     legal floating point value. */
1025     
1026 static int
1027 match_float_literal ()
1028 {
1029   char *tokptr = lexptr;
1030   char *buf;
1031   char *copy;
1032   char ch;
1033   double dval;
1034   extern double strtod ();
1035   
1036   /* Make local buffer in which to build the string to convert.  This is
1037      required because underscores are valid in chill floating point numbers
1038      but not in the string passed to strtod to convert.  The string will be
1039      no longer than our input string. */
1040      
1041   copy = buf = (char *) alloca (strlen (tokptr) + 1);
1042
1043   /* Transfer all leading digits to the conversion buffer, discarding any
1044      underscores. */
1045
1046   while (isdigit (*tokptr) || *tokptr == '_')
1047     {
1048       if (*tokptr != '_')
1049         {
1050           *copy++ = *tokptr;
1051         }
1052       tokptr++;
1053     }
1054
1055   /* Now accept either a '.', or one of [eEdD].  Dot is legal regardless
1056      of whether we found any leading digits, and we simply accept it and
1057      continue on to look for the fractional part and/or exponent.  One of
1058      [eEdD] is legal only if we have seen digits, and means that there
1059      is no fractional part.  If we find neither of these, then this is
1060      not a floating point number, so return failure. */
1061
1062   switch (*tokptr++)
1063     {
1064       case '.':
1065         /* Accept and then look for fractional part and/or exponent. */
1066         *copy++ = '.';
1067         break;
1068
1069       case 'e':
1070       case 'E':
1071       case 'd':
1072       case 'D':
1073         if (copy == buf)
1074           {
1075             return (0);
1076           }
1077         *copy++ = 'e';
1078         goto collect_exponent;
1079         break;
1080
1081       default:
1082         return (0);
1083         break;
1084     }
1085
1086   /* We found a '.', copy any fractional digits to the conversion buffer, up
1087      to the first nondigit, non-underscore character. */
1088
1089   while (isdigit (*tokptr) || *tokptr == '_')
1090     {
1091       if (*tokptr != '_')
1092         {
1093           *copy++ = *tokptr;
1094         }
1095       tokptr++;
1096     }
1097
1098   /* Look for an exponent, which must start with one of [eEdD].  If none
1099      is found, jump directly to trying to convert what we have collected
1100      so far. */
1101
1102   switch (*tokptr)
1103     {
1104       case 'e':
1105       case 'E':
1106       case 'd':
1107       case 'D':
1108         *copy++ = 'e';
1109         tokptr++;
1110         break;
1111       default:
1112         goto convert_float;
1113         break;
1114     }
1115
1116   /* Accept an optional '-' or '+' following one of [eEdD]. */
1117
1118   collect_exponent:
1119   if (*tokptr == '+' || *tokptr == '-')
1120     {
1121       *copy++ = *tokptr++;
1122     }
1123
1124   /* Now copy an exponent into the conversion buffer.  Note that at the 
1125      moment underscores are *not* allowed in exponents. */
1126
1127   while (isdigit (*tokptr))
1128     {
1129       *copy++ = *tokptr++;
1130     }
1131
1132   /* If we transfered any chars to the conversion buffer, try to interpret its
1133      contents as a floating point value.  If any characters remain, then we
1134      must not have a valid floating point string. */
1135
1136   convert_float:
1137   *copy = '\0';
1138   if (copy != buf)
1139       {
1140         dval = strtod (buf, &copy);
1141         if (*copy == '\0')
1142           {
1143             yylval.dval = dval;
1144             lexptr = tokptr;
1145             return (FLOAT_LITERAL);
1146           }
1147       }
1148   return (0);
1149 }
1150
1151 /* Recognize a character literal.  A character literal is single character
1152    or a control sequence, enclosed in single quotes.  A control sequence
1153    is a comma separated list of one or more integer literals, enclosed
1154    in parenthesis and introduced with a circumflex character.
1155
1156    EX:  'a'  '^(7)'  '^(7,8)'
1157
1158    As a GNU chill extension, the syntax C'xx' is also recognized as a 
1159    character literal, where xx is a hex value for the character.
1160
1161    Returns CHARACTER_LITERAL if a match is found.
1162    */
1163
1164 static int
1165 match_character_literal ()
1166 {
1167   char *tokptr = lexptr;
1168   int ival = 0;
1169   
1170   if ((tolower (*tokptr) == 'c') && (*(tokptr + 1) == '\''))
1171     {
1172       /* We have a GNU chill extension form, so skip the leading "C'",
1173          decode the hex value, and then ensure that we have a trailing
1174          single quote character. */
1175       tokptr += 2;
1176       if (!decode_integer_value (16, &tokptr, &ival) || (*tokptr != '\''))
1177         {
1178           return (0);
1179         }
1180       tokptr++;
1181     }
1182   else if (*tokptr == '\'')
1183     {
1184       tokptr++;
1185
1186       /* Determine which form we have, either a control sequence or the
1187          single character form. */
1188       
1189       if ((*tokptr == '^') && (*(tokptr + 1) == '('))
1190         {
1191           /* Match and decode a control sequence.  Return zero if we don't
1192              find a valid integer literal, or if the next unconsumed character
1193              after the integer literal is not the trailing ')'.
1194              FIXME:  We currently don't handle the multiple integer literal
1195              form. */
1196           tokptr += 2;
1197           if (!decode_integer_literal (&ival, &tokptr) || (*tokptr++ != ')'))
1198             {
1199               return (0);
1200             }
1201         }
1202       else
1203         {
1204           ival = *tokptr++;
1205         }
1206       
1207       /* The trailing quote has not yet been consumed.  If we don't find
1208          it, then we have no match. */
1209       
1210       if (*tokptr++ != '\'')
1211         {
1212           return (0);
1213         }
1214     }
1215   else
1216     {
1217       /* Not a character literal. */
1218       return (0);
1219     }
1220   yylval.typed_val.val = ival;
1221   yylval.typed_val.type = builtin_type_chill_char;
1222   lexptr = tokptr;
1223   return (CHARACTER_LITERAL);
1224 }
1225
1226 /* Recognize an integer literal, as specified in Z.200 sec 5.2.4.2.
1227    Note that according to 5.2.4.2, a single "_" is also a valid integer
1228    literal, however GNU-chill requires there to be at least one "digit"
1229    in any integer literal. */
1230
1231 static int
1232 match_integer_literal ()
1233 {
1234   char *tokptr = lexptr;
1235   int ival;
1236   
1237   if (!decode_integer_literal (&ival, &tokptr))
1238     {
1239       return (0);
1240     }
1241   else 
1242     {
1243       yylval.typed_val.val = ival;
1244       yylval.typed_val.type = builtin_type_int;
1245       lexptr = tokptr;
1246       return (INTEGER_LITERAL);
1247     }
1248 }
1249
1250 /* Recognize tokens that start with '$'.  These include:
1251
1252         $regname        A native register name or a "standard
1253                         register name".
1254                         Return token GDB_REGNAME.
1255
1256         $variable       A convenience variable with a name chosen
1257                         by the user.
1258                         Return token GDB_VARIABLE.
1259
1260         $digits         Value history with index <digits>, starting
1261                         from the first value which has index 1.
1262                         Return GDB_LAST.
1263
1264         $$digits        Value history with index <digits> relative
1265                         to the last value.  I.E. $$0 is the last
1266                         value, $$1 is the one previous to that, $$2
1267                         is the one previous to $$1, etc.
1268                         Return token GDB_LAST.
1269
1270         $ | $0 | $$0    The last value in the value history.
1271                         Return token GDB_LAST.
1272
1273         $$              An abbreviation for the second to the last
1274                         value in the value history, I.E. $$1
1275                         Return token GDB_LAST.
1276
1277     Note that we currently assume that register names and convenience
1278     variables follow the convention of starting with a letter or '_'.
1279
1280    */
1281
1282 static int
1283 match_dollar_tokens ()
1284 {
1285   char *tokptr;
1286   int regno;
1287   int namelength;
1288   int negate;
1289   int ival;
1290
1291   /* We will always have a successful match, even if it is just for
1292      a single '$', the abbreviation for $$0.  So advance lexptr. */
1293
1294   tokptr = ++lexptr;
1295
1296   if (*tokptr == '_' || isalpha (*tokptr))
1297     {
1298       /* Look for a match with a native register name, usually something
1299          like "r0" for example. */
1300
1301       for (regno = 0; regno < NUM_REGS; regno++)
1302         {
1303           namelength = strlen (reg_names[regno]);
1304           if (STREQN (tokptr, reg_names[regno], namelength)
1305               && !isalnum (tokptr[namelength]))
1306             {
1307               yylval.lval = regno;
1308               lexptr += namelength + 1;
1309               return (GDB_REGNAME);
1310             }
1311         }
1312
1313       /* Look for a match with a standard register name, usually something
1314          like "pc", which gdb always recognizes as the program counter
1315          regardless of what the native register name is. */
1316
1317       for (regno = 0; regno < num_std_regs; regno++)
1318         {
1319           namelength = strlen (std_regs[regno].name);
1320           if (STREQN (tokptr, std_regs[regno].name, namelength)
1321               && !isalnum (tokptr[namelength]))
1322             {
1323               yylval.lval = std_regs[regno].regnum;
1324               lexptr += namelength;
1325               return (GDB_REGNAME);
1326             }
1327         }
1328
1329       /* Attempt to match against a convenience variable.  Note that
1330          this will always succeed, because if no variable of that name
1331          already exists, the lookup_internalvar will create one for us.
1332          Also note that both lexptr and tokptr currently point to the
1333          start of the input string we are trying to match, and that we
1334          have already tested the first character for non-numeric, so we
1335          don't have to treat it specially. */
1336
1337       while (*tokptr == '_' || isalnum (*tokptr))
1338         {
1339           tokptr++;
1340         }
1341       yylval.sval.ptr = lexptr;
1342       yylval.sval.length = tokptr - lexptr;
1343       yylval.ivar = lookup_internalvar (copy_name (yylval.sval));
1344       lexptr = tokptr;
1345       return (GDB_VARIABLE);
1346     }
1347
1348   /* Since we didn't match against a register name or convenience
1349      variable, our only choice left is a history value. */
1350
1351   if (*tokptr == '$')
1352     {
1353       negate = 1;
1354       ival = 1;
1355       tokptr++;
1356     }
1357   else
1358     {
1359       negate = 0;
1360       ival = 0;
1361     }
1362
1363   /* Attempt to decode more characters as an integer value giving
1364      the index in the history list.  If successful, the value will
1365      overwrite ival (currently 0 or 1), and if not, ival will be
1366      left alone, which is good since it is currently correct for
1367      the '$' or '$$' case. */
1368
1369   decode_integer_literal (&ival, &tokptr);
1370   yylval.lval = negate ? -ival : ival;
1371   lexptr = tokptr;
1372   return (GDB_LAST);
1373 }
1374
1375 struct token
1376 {
1377   char *operator;
1378   int token;
1379 };
1380
1381 static const struct token tokentab5[] =
1382 {
1383     { "ANDIF", ANDIF }
1384 };
1385
1386 static const struct token tokentab4[] =
1387 {
1388     { "ORIF", ORIF }
1389 };
1390
1391 static const struct token tokentab3[] =
1392 {
1393     { "MOD", MOD },
1394     { "REM", REM },
1395     { "NOT", NOT },
1396     { "XOR", LOGXOR },
1397     { "AND", LOGAND }
1398 };
1399
1400 static const struct token tokentab2[] =
1401 {
1402     { ":=", GDB_ASSIGNMENT },
1403     { "//", SLASH_SLASH },
1404     { "/=", NOTEQUAL },
1405     { "<=", LEQ },
1406     { ">=", GTR },
1407     { "IN", IN },
1408     { "OR", LOGIOR }
1409 };
1410
1411 /* Read one token, getting characters through lexptr.  */
1412 /* This is where we will check to make sure that the language and the
1413    operators used are compatible.  */
1414
1415 static int
1416 yylex ()
1417 {
1418     unsigned int i;
1419     int token;
1420     char *simplename;
1421     struct symbol *sym;
1422
1423     /* Skip over any leading whitespace. */
1424     while (isspace (*lexptr))
1425         {
1426             lexptr++;
1427         }
1428     /* Look for special single character cases which can't be the first
1429        character of some other multicharacter token. */
1430     switch (*lexptr)
1431         {
1432             case '\0':
1433                 return (0);
1434             case ',':
1435             case '=':
1436             case ';':
1437             case '!':
1438             case '+':
1439             case '-':
1440             case '*':
1441             case '/':
1442             case '(':
1443             case ')':
1444             case '[':
1445             case ']':
1446                 return (*lexptr++);
1447         }
1448     /* Look for characters which start a particular kind of multicharacter
1449        token, such as a character literal, register name, convenience
1450        variable name, etc. */
1451     switch (*lexptr)
1452       {
1453         case 'C':
1454         case 'c':
1455         case '\'':
1456           token = match_character_literal ();
1457           if (token != 0)
1458             {
1459               return (token);
1460             }
1461           break;
1462         case '$':
1463           token = match_dollar_tokens ();
1464           if (token != 0)
1465             {
1466               return (token);
1467             }
1468           break;
1469       }
1470     /* See if it is a special token of length 5.  */
1471     for (i = 0; i < sizeof (tokentab5) / sizeof (tokentab5[0]); i++)
1472         {
1473             if (STREQN (lexptr, tokentab5[i].operator, 5))
1474                 {
1475                     lexptr += 5;
1476                     return (tokentab5[i].token);
1477                 }
1478         }
1479     /* See if it is a special token of length 4.  */
1480     for (i = 0; i < sizeof (tokentab4) / sizeof (tokentab4[0]); i++)
1481         {
1482             if (STREQN (lexptr, tokentab4[i].operator, 4))
1483                 {
1484                     lexptr += 4;
1485                     return (tokentab4[i].token);
1486                 }
1487         }
1488     /* See if it is a special token of length 3.  */
1489     for (i = 0; i < sizeof (tokentab3) / sizeof (tokentab3[0]); i++)
1490         {
1491             if (STREQN (lexptr, tokentab3[i].operator, 3))
1492                 {
1493                     lexptr += 3;
1494                     return (tokentab3[i].token);
1495                 }
1496         }
1497     /* See if it is a special token of length 2.  */
1498     for (i = 0; i < sizeof (tokentab2) / sizeof (tokentab2[0]); i++)
1499         {
1500             if (STREQN (lexptr, tokentab2[i].operator, 2))
1501                 {
1502                     lexptr += 2;
1503                     return (tokentab2[i].token);
1504                 }
1505         }
1506     /* Look for single character cases which which could be the first
1507        character of some other multicharacter token, but aren't, or we
1508        would already have found it. */
1509     switch (*lexptr)
1510         {
1511             case ':':
1512             case '/':
1513             case '<':
1514             case '>':
1515                 return (*lexptr++);
1516         }
1517     /* Look for other special tokens. */
1518     if (STREQN (lexptr, "TRUE", 4)) /* FIXME:  What about lowercase? */
1519         {
1520             yylval.ulval = 1;
1521             lexptr += 4;
1522             return (BOOLEAN_LITERAL);
1523         }
1524     if (STREQN (lexptr, "FALSE", 5)) /* FIXME:  What about lowercase? */
1525         {
1526             yylval.ulval = 0;
1527             lexptr += 5;
1528             return (BOOLEAN_LITERAL);
1529         }
1530     /* Look for a float literal before looking for an integer literal, so
1531        we match as much of the input stream as possible. */
1532     token = match_float_literal ();
1533     if (token != 0)
1534         {
1535             return (token);
1536         }
1537     token = match_integer_literal ();
1538     if (token != 0)
1539         {
1540             return (token);
1541         }
1542
1543     /* Try to match a simple name string, and if a match is found, then
1544        further classify what sort of name it is and return an appropriate
1545        token.  Note that attempting to match a simple name string consumes
1546        the token from lexptr, so we can't back out if we later find that
1547        we can't classify what sort of name it is. */
1548
1549     simplename = match_simple_name_string ();
1550     if (simplename != NULL)
1551       {
1552         sym = lookup_symbol (simplename, expression_context_block,
1553                              VAR_NAMESPACE, (int *) NULL,
1554                              (struct symtab **) NULL);
1555         if (sym != NULL)
1556           {
1557             yylval.ssym.stoken.ptr = NULL;
1558             yylval.ssym.stoken.length = 0;
1559             yylval.ssym.sym = sym;
1560             yylval.ssym.is_a_field_of_this = 0; /* FIXME, C++'ism */
1561             switch (SYMBOL_CLASS (sym))
1562               {
1563               case LOC_BLOCK:
1564                 /* Found a procedure name. */
1565                 return (GENERAL_PROCEDURE_NAME);
1566               case LOC_STATIC:
1567                 /* Found a global or local static variable. */
1568                 return (LOCATION_NAME);
1569               case LOC_REGISTER:
1570               case LOC_ARG:
1571               case LOC_REF_ARG:
1572               case LOC_REGPARM:
1573               case LOC_LOCAL:
1574               case LOC_LOCAL_ARG:
1575                 if (innermost_block == NULL
1576                     || contained_in (block_found, innermost_block))
1577                   {
1578                     innermost_block = block_found;
1579                   }
1580                 return (LOCATION_NAME);
1581                 break;
1582               case LOC_CONST:
1583               case LOC_LABEL:
1584                 return (LOCATION_NAME);
1585                 break;
1586               case LOC_UNDEF:
1587               case LOC_TYPEDEF:
1588               case LOC_CONST_BYTES:
1589                 error ("Symbol \"%s\" names no location.", simplename);
1590                 break;
1591               }
1592           }
1593         else if (!have_full_symbols () && !have_partial_symbols ())
1594           {
1595             error ("No symbol table is loaded.  Use the \"file\" command.");
1596           }
1597         else
1598           {
1599             error ("No symbol \"%s\" in current context.", simplename);
1600           }
1601       }
1602
1603     /* Catch single character tokens which are not part of some
1604        longer token. */
1605
1606     switch (*lexptr)
1607       {
1608         case '.':                       /* Not float for example. */
1609           return (*lexptr++);
1610       }
1611
1612     return (ILLEGAL_TOKEN);
1613 }
1614
1615 void
1616 yyerror (msg)
1617      char *msg; /* unused */
1618 {
1619   printf ("Parsing:  %s\n", lexptr);
1620   if (yychar < 256)
1621     {
1622       error ("Invalid syntax in expression near character '%c'.", yychar);
1623     }
1624   else
1625     {
1626       error ("Invalid syntax in expression");
1627     }
1628 }
This page took 0.117429 seconds and 4 git commands to generate.