2 /* YACC parser for Fortran expressions, for GDB.
3 Copyright (C) 1986-2016 Free Software Foundation, Inc.
5 Contributed by Motorola. Adapted from the C parser by Farooq Butt
6 (fmbutt@engage.sps.mot.com).
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 /* This was blantantly ripped off the C expression parser, please
24 be aware of that as you look at its basic structure -FMB */
26 /* Parse a F77 expression from text in a string,
27 and return the result as a struct expression pointer.
28 That structure contains arithmetic operations in reverse polish,
29 with constants represented by operations that are followed by special data.
30 See expression.h for the details of the format.
31 What is important here is that it can be built up sequentially
32 during the process of parsing; the lower levels of the tree always
33 come first in the result.
35 Note that malloc's and realloc's in this file are transformed to
36 xmalloc and xrealloc respectively by the same sed command in the
37 makefile that remaps any other malloc/realloc inserted by the parser
38 generator. Doing this with #defines and trying to control the interaction
39 with include files (<malloc.h> and <stdlib.h> for example) just became
40 too messy, particularly when such includes can be inserted at random
41 times by the parser generator. */
46 #include "expression.h"
48 #include "parser-defs.h"
51 #include "bfd.h" /* Required by objfiles.h. */
52 #include "symfile.h" /* Required by objfiles.h. */
53 #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
58 #define parse_type(ps) builtin_type (parse_gdbarch (ps))
59 #define parse_f_type(ps) builtin_f_type (parse_gdbarch (ps))
61 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror,
63 #define GDB_YY_REMAP_PREFIX f_
66 /* The state of the parser, used internally when we are parsing the
69 static struct parser_state *pstate = NULL;
73 static int yylex (void);
75 void yyerror (char *);
77 static void growbuf_by_size (int);
79 static int match_string_literal (void);
83 /* Although the yacc "value" of an expression is not used,
84 since the result is stored in the structure being created,
85 other node types do have values. */
102 enum exp_opcode opcode;
103 struct internalvar *ivar;
110 /* YYSTYPE gets defined by %union */
111 static int parse_number (struct parser_state *, const char *, int,
115 %type <voidval> exp type_exp start variable
116 %type <tval> type typebase
117 %type <tvec> nonempty_typelist
118 /* %type <bval> block */
120 /* Fancy type parsing. */
121 %type <voidval> func_mod direct_abs_decl abs_decl
124 %token <typed_val> INT
127 /* Both NAME and TYPENAME tokens represent symbols in the input,
128 and both convey their data as strings.
129 But a TYPENAME is a string that happens to be defined as a typedef
130 or builtin type name (such as int or char)
131 and a NAME is any other symbol.
132 Contexts where this distinction is not important can use the
133 nonterminal "name", which matches either NAME or TYPENAME. */
135 %token <sval> STRING_LITERAL
136 %token <lval> BOOLEAN_LITERAL
138 %token <tsym> TYPENAME
140 %type <ssym> name_not_typename
142 /* A NAME_OR_INT is a symbol which is not known in the symbol table,
143 but which would parse as a valid number in the current input radix.
144 E.g. "c" when input_radix==16. Depending on the parse, it will be
145 turned into a name or into a number. */
147 %token <ssym> NAME_OR_INT
152 /* Special type cases, put in to allow the parser to distinguish different
154 %token INT_KEYWORD INT_S2_KEYWORD LOGICAL_S1_KEYWORD LOGICAL_S2_KEYWORD
155 %token LOGICAL_S8_KEYWORD
156 %token LOGICAL_KEYWORD REAL_KEYWORD REAL_S8_KEYWORD REAL_S16_KEYWORD
157 %token COMPLEX_S8_KEYWORD COMPLEX_S16_KEYWORD COMPLEX_S32_KEYWORD
158 %token BOOL_AND BOOL_OR BOOL_NOT
159 %token <lval> CHARACTER
161 %token <voidval> VARIABLE
163 %token <opcode> ASSIGN_MODIFY
167 %right '=' ASSIGN_MODIFY
176 %left LESSTHAN GREATERTHAN LEQ GEQ
194 { write_exp_elt_opcode (pstate, OP_TYPE);
195 write_exp_elt_type (pstate, $1);
196 write_exp_elt_opcode (pstate, OP_TYPE); }
203 /* Expressions, not including the comma operator. */
204 exp : '*' exp %prec UNARY
205 { write_exp_elt_opcode (pstate, UNOP_IND); }
208 exp : '&' exp %prec UNARY
209 { write_exp_elt_opcode (pstate, UNOP_ADDR); }
212 exp : '-' exp %prec UNARY
213 { write_exp_elt_opcode (pstate, UNOP_NEG); }
216 exp : BOOL_NOT exp %prec UNARY
217 { write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); }
220 exp : '~' exp %prec UNARY
221 { write_exp_elt_opcode (pstate, UNOP_COMPLEMENT); }
224 exp : SIZEOF exp %prec UNARY
225 { write_exp_elt_opcode (pstate, UNOP_SIZEOF); }
228 /* No more explicit array operators, we treat everything in F77 as
229 a function call. The disambiguation as to whether we are
230 doing a subscript operation or a function call is done
234 { start_arglist (); }
236 { write_exp_elt_opcode (pstate,
237 OP_F77_UNDETERMINED_ARGLIST);
238 write_exp_elt_longcst (pstate,
239 (LONGEST) end_arglist ());
240 write_exp_elt_opcode (pstate,
241 OP_F77_UNDETERMINED_ARGLIST); }
255 arglist : arglist ',' exp %prec ABOVE_COMMA
259 /* There are four sorts of subrange types in F90. */
261 subrange: exp ':' exp %prec ABOVE_COMMA
262 { write_exp_elt_opcode (pstate, OP_RANGE);
263 write_exp_elt_longcst (pstate, NONE_BOUND_DEFAULT);
264 write_exp_elt_opcode (pstate, OP_RANGE); }
267 subrange: exp ':' %prec ABOVE_COMMA
268 { write_exp_elt_opcode (pstate, OP_RANGE);
269 write_exp_elt_longcst (pstate, HIGH_BOUND_DEFAULT);
270 write_exp_elt_opcode (pstate, OP_RANGE); }
273 subrange: ':' exp %prec ABOVE_COMMA
274 { write_exp_elt_opcode (pstate, OP_RANGE);
275 write_exp_elt_longcst (pstate, LOW_BOUND_DEFAULT);
276 write_exp_elt_opcode (pstate, OP_RANGE); }
279 subrange: ':' %prec ABOVE_COMMA
280 { write_exp_elt_opcode (pstate, OP_RANGE);
281 write_exp_elt_longcst (pstate, BOTH_BOUND_DEFAULT);
282 write_exp_elt_opcode (pstate, OP_RANGE); }
285 complexnum: exp ',' exp
289 exp : '(' complexnum ')'
290 { write_exp_elt_opcode (pstate, OP_COMPLEX);
291 write_exp_elt_type (pstate,
292 parse_f_type (pstate)
293 ->builtin_complex_s16);
294 write_exp_elt_opcode (pstate, OP_COMPLEX); }
297 exp : '(' type ')' exp %prec UNARY
298 { write_exp_elt_opcode (pstate, UNOP_CAST);
299 write_exp_elt_type (pstate, $2);
300 write_exp_elt_opcode (pstate, UNOP_CAST); }
304 { write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
305 write_exp_string (pstate, $3);
306 write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
309 /* Binary operators in order of decreasing precedence. */
312 { write_exp_elt_opcode (pstate, BINOP_REPEAT); }
315 exp : exp STARSTAR exp
316 { write_exp_elt_opcode (pstate, BINOP_EXP); }
320 { write_exp_elt_opcode (pstate, BINOP_MUL); }
324 { write_exp_elt_opcode (pstate, BINOP_DIV); }
328 { write_exp_elt_opcode (pstate, BINOP_ADD); }
332 { write_exp_elt_opcode (pstate, BINOP_SUB); }
336 { write_exp_elt_opcode (pstate, BINOP_LSH); }
340 { write_exp_elt_opcode (pstate, BINOP_RSH); }
344 { write_exp_elt_opcode (pstate, BINOP_EQUAL); }
347 exp : exp NOTEQUAL exp
348 { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); }
352 { write_exp_elt_opcode (pstate, BINOP_LEQ); }
356 { write_exp_elt_opcode (pstate, BINOP_GEQ); }
359 exp : exp LESSTHAN exp
360 { write_exp_elt_opcode (pstate, BINOP_LESS); }
363 exp : exp GREATERTHAN exp
364 { write_exp_elt_opcode (pstate, BINOP_GTR); }
368 { write_exp_elt_opcode (pstate, BINOP_BITWISE_AND); }
372 { write_exp_elt_opcode (pstate, BINOP_BITWISE_XOR); }
376 { write_exp_elt_opcode (pstate, BINOP_BITWISE_IOR); }
379 exp : exp BOOL_AND exp
380 { write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); }
384 exp : exp BOOL_OR exp
385 { write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); }
389 { write_exp_elt_opcode (pstate, BINOP_ASSIGN); }
392 exp : exp ASSIGN_MODIFY exp
393 { write_exp_elt_opcode (pstate, BINOP_ASSIGN_MODIFY);
394 write_exp_elt_opcode (pstate, $2);
395 write_exp_elt_opcode (pstate, BINOP_ASSIGN_MODIFY); }
399 { write_exp_elt_opcode (pstate, OP_LONG);
400 write_exp_elt_type (pstate, $1.type);
401 write_exp_elt_longcst (pstate, (LONGEST) ($1.val));
402 write_exp_elt_opcode (pstate, OP_LONG); }
407 parse_number (pstate, $1.stoken.ptr,
408 $1.stoken.length, 0, &val);
409 write_exp_elt_opcode (pstate, OP_LONG);
410 write_exp_elt_type (pstate, val.typed_val.type);
411 write_exp_elt_longcst (pstate,
412 (LONGEST)val.typed_val.val);
413 write_exp_elt_opcode (pstate, OP_LONG); }
417 { write_exp_elt_opcode (pstate, OP_DOUBLE);
418 write_exp_elt_type (pstate,
419 parse_f_type (pstate)
421 write_exp_elt_dblcst (pstate, $1);
422 write_exp_elt_opcode (pstate, OP_DOUBLE); }
431 exp : SIZEOF '(' type ')' %prec UNARY
432 { write_exp_elt_opcode (pstate, OP_LONG);
433 write_exp_elt_type (pstate,
434 parse_f_type (pstate)
436 $3 = check_typedef ($3);
437 write_exp_elt_longcst (pstate,
438 (LONGEST) TYPE_LENGTH ($3));
439 write_exp_elt_opcode (pstate, OP_LONG); }
442 exp : BOOLEAN_LITERAL
443 { write_exp_elt_opcode (pstate, OP_BOOL);
444 write_exp_elt_longcst (pstate, (LONGEST) $1);
445 write_exp_elt_opcode (pstate, OP_BOOL);
451 write_exp_elt_opcode (pstate, OP_STRING);
452 write_exp_string (pstate, $1);
453 write_exp_elt_opcode (pstate, OP_STRING);
457 variable: name_not_typename
458 { struct block_symbol sym = $1.sym;
462 if (symbol_read_needs_frame (sym.symbol))
464 if (innermost_block == 0
465 || contained_in (sym.block,
467 innermost_block = sym.block;
469 write_exp_elt_opcode (pstate, OP_VAR_VALUE);
470 write_exp_elt_block (pstate, sym.block);
471 write_exp_elt_sym (pstate, sym.symbol);
472 write_exp_elt_opcode (pstate, OP_VAR_VALUE);
477 struct bound_minimal_symbol msymbol;
478 char *arg = copy_name ($1.stoken);
481 lookup_bound_minimal_symbol (arg);
482 if (msymbol.minsym != NULL)
483 write_exp_msymbol (pstate, msymbol);
484 else if (!have_full_symbols () && !have_partial_symbols ())
485 error (_("No symbol table is loaded. Use the \"file\" command."));
487 error (_("No symbol \"%s\" in current context."),
488 copy_name ($1.stoken));
500 /* This is where the interesting stuff happens. */
503 struct type *follow_type = $1;
504 struct type *range_type;
513 follow_type = lookup_pointer_type (follow_type);
516 follow_type = lookup_reference_type (follow_type);
519 array_size = pop_type_int ();
520 if (array_size != -1)
523 create_static_range_type ((struct type *) NULL,
524 parse_f_type (pstate)
528 create_array_type ((struct type *) NULL,
529 follow_type, range_type);
532 follow_type = lookup_pointer_type (follow_type);
535 follow_type = lookup_function_type (follow_type);
543 { push_type (tp_pointer); $$ = 0; }
545 { push_type (tp_pointer); $$ = $2; }
547 { push_type (tp_reference); $$ = 0; }
549 { push_type (tp_reference); $$ = $2; }
553 direct_abs_decl: '(' abs_decl ')'
555 | direct_abs_decl func_mod
556 { push_type (tp_function); }
558 { push_type (tp_function); }
563 | '(' nonempty_typelist ')'
564 { free ($2); $$ = 0; }
567 typebase /* Implements (approximately): (type-qualifier)* type-specifier */
571 { $$ = parse_f_type (pstate)->builtin_integer; }
573 { $$ = parse_f_type (pstate)->builtin_integer_s2; }
575 { $$ = parse_f_type (pstate)->builtin_character; }
577 { $$ = parse_f_type (pstate)->builtin_logical_s8; }
579 { $$ = parse_f_type (pstate)->builtin_logical; }
581 { $$ = parse_f_type (pstate)->builtin_logical_s2; }
583 { $$ = parse_f_type (pstate)->builtin_logical_s1; }
585 { $$ = parse_f_type (pstate)->builtin_real; }
587 { $$ = parse_f_type (pstate)->builtin_real_s8; }
589 { $$ = parse_f_type (pstate)->builtin_real_s16; }
591 { $$ = parse_f_type (pstate)->builtin_complex_s8; }
592 | COMPLEX_S16_KEYWORD
593 { $$ = parse_f_type (pstate)->builtin_complex_s16; }
594 | COMPLEX_S32_KEYWORD
595 { $$ = parse_f_type (pstate)->builtin_complex_s32; }
600 { $$ = (struct type **) malloc (sizeof (struct type *) * 2);
601 $<ivec>$[0] = 1; /* Number of types in vector */
604 | nonempty_typelist ',' type
605 { int len = sizeof (struct type *) * (++($<ivec>1[0]) + 1);
606 $$ = (struct type **) realloc ((char *) $1, len);
607 $$[$<ivec>$[0]] = $3;
615 name_not_typename : NAME
616 /* These would be useful if name_not_typename was useful, but it is just
617 a fake for "variable", so these cause reduce/reduce conflicts because
618 the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable,
619 =exp) or just an exp. If name_not_typename was ever used in an lvalue
620 context where only a name could occur, this might be useful.
627 /* Take care of parsing a number (anything that starts with a digit).
628 Set yylval and return the token type; update lexptr.
629 LEN is the number of characters in it. */
631 /*** Needs some error checking for the float case ***/
634 parse_number (struct parser_state *par_state,
635 const char *p, int len, int parsed_float, YYSTYPE *putithere)
640 int base = input_radix;
644 struct type *signed_type;
645 struct type *unsigned_type;
649 /* It's a float since it contains a point or an exponent. */
650 /* [dD] is not understood as an exponent by atof, change it to 'e'. */
654 for (tmp2 = tmp; *tmp2; ++tmp2)
655 if (*tmp2 == 'd' || *tmp2 == 'D')
657 putithere->dval = atof (tmp);
662 /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
698 if (len == 0 && c == 'l')
700 else if (len == 0 && c == 'u')
705 if (c >= '0' && c <= '9')
707 else if (c >= 'a' && c <= 'f')
710 return ERROR; /* Char not a digit */
712 return ERROR; /* Invalid digit in this base */
716 /* Portably test for overflow (only works for nonzero values, so make
717 a second check for zero). */
718 if ((prevn >= n) && n != 0)
719 unsigned_p=1; /* Try something unsigned */
720 /* If range checking enabled, portably test for unsigned overflow. */
721 if (RANGE_CHECK && n != 0)
723 if ((unsigned_p && (unsigned)prevn >= (unsigned)n))
724 range_error (_("Overflow on numeric constant."));
729 /* If the number is too big to be an int, or it's got an l suffix
730 then it's a long. Work out if this has to be a long by
731 shifting right and seeing if anything remains, and the
732 target int size is different to the target long size.
734 In the expression below, we could have tested
735 (n >> gdbarch_int_bit (parse_gdbarch))
736 to see if it was zero,
737 but too many compilers warn about that, when ints and longs
738 are the same size. So we shift it twice, with fewer bits
739 each time, for the same result. */
741 if ((gdbarch_int_bit (parse_gdbarch (par_state))
742 != gdbarch_long_bit (parse_gdbarch (par_state))
744 >> (gdbarch_int_bit (parse_gdbarch (par_state))-2))) /* Avoid
748 high_bit = ((ULONGEST)1)
749 << (gdbarch_long_bit (parse_gdbarch (par_state))-1);
750 unsigned_type = parse_type (par_state)->builtin_unsigned_long;
751 signed_type = parse_type (par_state)->builtin_long;
756 ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch (par_state)) - 1);
757 unsigned_type = parse_type (par_state)->builtin_unsigned_int;
758 signed_type = parse_type (par_state)->builtin_int;
761 putithere->typed_val.val = n;
763 /* If the high bit of the worked out type is set then this number
764 has to be unsigned. */
766 if (unsigned_p || (n & high_bit))
767 putithere->typed_val.type = unsigned_type;
769 putithere->typed_val.type = signed_type;
778 enum exp_opcode opcode;
781 static const struct token dot_ops[] =
783 { ".and.", BOOL_AND, BINOP_END },
784 { ".AND.", BOOL_AND, BINOP_END },
785 { ".or.", BOOL_OR, BINOP_END },
786 { ".OR.", BOOL_OR, BINOP_END },
787 { ".not.", BOOL_NOT, BINOP_END },
788 { ".NOT.", BOOL_NOT, BINOP_END },
789 { ".eq.", EQUAL, BINOP_END },
790 { ".EQ.", EQUAL, BINOP_END },
791 { ".eqv.", EQUAL, BINOP_END },
792 { ".NEQV.", NOTEQUAL, BINOP_END },
793 { ".neqv.", NOTEQUAL, BINOP_END },
794 { ".EQV.", EQUAL, BINOP_END },
795 { ".ne.", NOTEQUAL, BINOP_END },
796 { ".NE.", NOTEQUAL, BINOP_END },
797 { ".le.", LEQ, BINOP_END },
798 { ".LE.", LEQ, BINOP_END },
799 { ".ge.", GEQ, BINOP_END },
800 { ".GE.", GEQ, BINOP_END },
801 { ".gt.", GREATERTHAN, BINOP_END },
802 { ".GT.", GREATERTHAN, BINOP_END },
803 { ".lt.", LESSTHAN, BINOP_END },
804 { ".LT.", LESSTHAN, BINOP_END },
805 { NULL, 0, BINOP_END }
808 struct f77_boolean_val
814 static const struct f77_boolean_val boolean_values[] =
823 static const struct token f77_keywords[] =
825 { "complex_16", COMPLEX_S16_KEYWORD, BINOP_END },
826 { "complex_32", COMPLEX_S32_KEYWORD, BINOP_END },
827 { "character", CHARACTER, BINOP_END },
828 { "integer_2", INT_S2_KEYWORD, BINOP_END },
829 { "logical_1", LOGICAL_S1_KEYWORD, BINOP_END },
830 { "logical_2", LOGICAL_S2_KEYWORD, BINOP_END },
831 { "logical_8", LOGICAL_S8_KEYWORD, BINOP_END },
832 { "complex_8", COMPLEX_S8_KEYWORD, BINOP_END },
833 { "integer", INT_KEYWORD, BINOP_END },
834 { "logical", LOGICAL_KEYWORD, BINOP_END },
835 { "real_16", REAL_S16_KEYWORD, BINOP_END },
836 { "complex", COMPLEX_S8_KEYWORD, BINOP_END },
837 { "sizeof", SIZEOF, BINOP_END },
838 { "real_8", REAL_S8_KEYWORD, BINOP_END },
839 { "real", REAL_KEYWORD, BINOP_END },
840 { NULL, 0, BINOP_END }
843 /* Implementation of a dynamically expandable buffer for processing input
844 characters acquired through lexptr and building a value to return in
845 yylval. Ripped off from ch-exp.y */
847 static char *tempbuf; /* Current buffer contents */
848 static int tempbufsize; /* Size of allocated buffer */
849 static int tempbufindex; /* Current index into buffer */
851 #define GROWBY_MIN_SIZE 64 /* Minimum amount to grow buffer by */
853 #define CHECKBUF(size) \
855 if (tempbufindex + (size) >= tempbufsize) \
857 growbuf_by_size (size); \
862 /* Grow the static temp buffer if necessary, including allocating the
863 first one on demand. */
866 growbuf_by_size (int count)
870 growby = std::max (count, GROWBY_MIN_SIZE);
871 tempbufsize += growby;
873 tempbuf = (char *) malloc (tempbufsize);
875 tempbuf = (char *) realloc (tempbuf, tempbufsize);
878 /* Blatantly ripped off from ch-exp.y. This routine recognizes F77
881 Recognize a string literal. A string literal is a nonzero sequence
882 of characters enclosed in matching single quotes, except that
883 a single character inside single quotes is a character literal, which
884 we reject as a string literal. To embed the terminator character inside
885 a string, it is simply doubled (I.E. 'this''is''one''string') */
888 match_string_literal (void)
890 const char *tokptr = lexptr;
892 for (tempbufindex = 0, tokptr++; *tokptr != '\0'; tokptr++)
895 if (*tokptr == *lexptr)
897 if (*(tokptr + 1) == *lexptr)
902 tempbuf[tempbufindex++] = *tokptr;
904 if (*tokptr == '\0' /* no terminator */
905 || tempbufindex == 0) /* no string */
909 tempbuf[tempbufindex] = '\0';
910 yylval.sval.ptr = tempbuf;
911 yylval.sval.length = tempbufindex;
913 return STRING_LITERAL;
917 /* Read one token, getting characters through lexptr. */
924 unsigned int i,token;
925 const char *tokstart;
929 prev_lexptr = lexptr;
933 /* First of all, let us make sure we are not dealing with the
934 special tokens .true. and .false. which evaluate to 1 and 0. */
938 for (i = 0; boolean_values[i].name != NULL; i++)
940 if (strncmp (tokstart, boolean_values[i].name,
941 strlen (boolean_values[i].name)) == 0)
943 lexptr += strlen (boolean_values[i].name);
944 yylval.lval = boolean_values[i].value;
945 return BOOLEAN_LITERAL;
950 /* See if it is a special .foo. operator. */
952 for (i = 0; dot_ops[i].oper != NULL; i++)
953 if (strncmp (tokstart, dot_ops[i].oper,
954 strlen (dot_ops[i].oper)) == 0)
956 lexptr += strlen (dot_ops[i].oper);
957 yylval.opcode = dot_ops[i].opcode;
958 return dot_ops[i].token;
961 /* See if it is an exponentiation operator. */
963 if (strncmp (tokstart, "**", 2) == 0)
966 yylval.opcode = BINOP_EXP;
970 switch (c = *tokstart)
982 token = match_string_literal ();
993 if (paren_depth == 0)
1000 if (comma_terminates && paren_depth == 0)
1006 /* Might be a floating point number. */
1007 if (lexptr[1] < '0' || lexptr[1] > '9')
1008 goto symbol; /* Nope, must be a symbol. */
1009 /* FALL THRU into number case. */
1022 /* It's a number. */
1023 int got_dot = 0, got_e = 0, got_d = 0, toktype;
1024 const char *p = tokstart;
1025 int hex = input_radix > 10;
1027 if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
1032 else if (c == '0' && (p[1]=='t' || p[1]=='T'
1033 || p[1]=='d' || p[1]=='D'))
1041 if (!hex && !got_e && (*p == 'e' || *p == 'E'))
1042 got_dot = got_e = 1;
1043 else if (!hex && !got_d && (*p == 'd' || *p == 'D'))
1044 got_dot = got_d = 1;
1045 else if (!hex && !got_dot && *p == '.')
1047 else if (((got_e && (p[-1] == 'e' || p[-1] == 'E'))
1048 || (got_d && (p[-1] == 'd' || p[-1] == 'D')))
1049 && (*p == '-' || *p == '+'))
1050 /* This is the sign of the exponent, not the end of the
1053 /* We will take any letters or digits. parse_number will
1054 complain if past the radix, or if L or U are not final. */
1055 else if ((*p < '0' || *p > '9')
1056 && ((*p < 'a' || *p > 'z')
1057 && (*p < 'A' || *p > 'Z')))
1060 toktype = parse_number (pstate, tokstart, p - tokstart,
1061 got_dot|got_e|got_d,
1063 if (toktype == ERROR)
1065 char *err_copy = (char *) alloca (p - tokstart + 1);
1067 memcpy (err_copy, tokstart, p - tokstart);
1068 err_copy[p - tokstart] = 0;
1069 error (_("Invalid number \"%s\"."), err_copy);
1100 if (!(c == '_' || c == '$' || c ==':'
1101 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
1102 /* We must have come across a bad character (e.g. ';'). */
1103 error (_("Invalid character '%c' in expression."), c);
1106 for (c = tokstart[namelen];
1107 (c == '_' || c == '$' || c == ':' || (c >= '0' && c <= '9')
1108 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
1109 c = tokstart[++namelen]);
1111 /* The token "if" terminates the expression and is NOT
1112 removed from the input stream. */
1114 if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
1119 /* Catch specific keywords. */
1121 for (i = 0; f77_keywords[i].oper != NULL; i++)
1122 if (strlen (f77_keywords[i].oper) == namelen
1123 && strncmp (tokstart, f77_keywords[i].oper, namelen) == 0)
1125 /* lexptr += strlen(f77_keywords[i].operator); */
1126 yylval.opcode = f77_keywords[i].opcode;
1127 return f77_keywords[i].token;
1130 yylval.sval.ptr = tokstart;
1131 yylval.sval.length = namelen;
1133 if (*tokstart == '$')
1135 write_dollar_variable (pstate, yylval.sval);
1139 /* Use token-type TYPENAME for symbols that happen to be defined
1140 currently as names of types; NAME for other symbols.
1141 The caller is not constrained to care about the distinction. */
1143 char *tmp = copy_name (yylval.sval);
1144 struct block_symbol result;
1145 struct field_of_this_result is_a_field_of_this;
1146 enum domain_enum_tag lookup_domains[] =
1155 for (i = 0; i < ARRAY_SIZE (lookup_domains); ++i)
1157 /* Initialize this in case we *don't* use it in this call; that
1158 way we can refer to it unconditionally below. */
1159 memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this));
1161 result = lookup_symbol (tmp, expression_context_block,
1163 parse_language (pstate)->la_language
1165 ? &is_a_field_of_this : NULL);
1166 if (result.symbol && SYMBOL_CLASS (result.symbol) == LOC_TYPEDEF)
1168 yylval.tsym.type = SYMBOL_TYPE (result.symbol);
1177 = language_lookup_primitive_type (parse_language (pstate),
1178 parse_gdbarch (pstate), tmp);
1179 if (yylval.tsym.type != NULL)
1182 /* Input names that aren't symbols but ARE valid hex numbers,
1183 when the input radix permits them, can be names or numbers
1184 depending on the parse. Note we support radixes > 16 here. */
1186 && ((tokstart[0] >= 'a' && tokstart[0] < 'a' + input_radix - 10)
1187 || (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10)))
1189 YYSTYPE newlval; /* Its value is ignored. */
1190 hextype = parse_number (pstate, tokstart, namelen, 0, &newlval);
1193 yylval.ssym.sym = result;
1194 yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
1199 /* Any other kind of symbol */
1200 yylval.ssym.sym = result;
1201 yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
1207 f_parse (struct parser_state *par_state)
1210 struct cleanup *c = make_cleanup_clear_parser_state (&pstate);
1212 /* Setting up the parser state. */
1213 gdb_assert (par_state != NULL);
1216 result = yyparse ();
1225 lexptr = prev_lexptr;
1227 error (_("A %s in expression, near `%s'."), (msg ? msg : "error"), lexptr);