1 /* YACC parser for Fortran expressions, for GDB.
2 Copyright (C) 1986-2014 Free Software Foundation, Inc.
4 Contributed by Motorola. Adapted from the C parser by Farooq Butt
5 (fmbutt@engage.sps.mot.com).
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 /* This was blantantly ripped off the C expression parser, please
23 be aware of that as you look at its basic structure -FMB */
25 /* Parse a F77 expression from text in a string,
26 and return the result as a struct expression pointer.
27 That structure contains arithmetic operations in reverse polish,
28 with constants represented by operations that are followed by special data.
29 See expression.h for the details of the format.
30 What is important here is that it can be built up sequentially
31 during the process of parsing; the lower levels of the tree always
32 come first in the result.
34 Note that malloc's and realloc's in this file are transformed to
35 xmalloc and xrealloc respectively by the same sed command in the
36 makefile that remaps any other malloc/realloc inserted by the parser
37 generator. Doing this with #defines and trying to control the interaction
38 with include files (<malloc.h> and <stdlib.h> for example) just became
39 too messy, particularly when such includes can be inserted at random
40 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 */
57 #define parse_type builtin_type (parse_gdbarch)
58 #define parse_f_type builtin_f_type (parse_gdbarch)
60 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
61 as well as gratuitiously global symbol names, so we can have multiple
62 yacc generated parsers in gdb. Note that these are only the variables
63 produced by yacc. If other parser generators (bison, byacc, etc) produce
64 additional global names that conflict at link time, then those parser
65 generators need to be fixed instead of adding those names to this list. */
67 #define yymaxdepth f_maxdepth
68 #define yyparse f_parse
70 #define yyerror f_error
73 #define yydebug f_debug
82 #define yyerrflag f_errflag
83 #define yynerrs f_nerrs
88 #define yystate f_state
94 #define yyreds f_reds /* With YYDEBUG defined */
95 #define yytoks f_toks /* With YYDEBUG defined */
96 #define yyname f_name /* With YYDEBUG defined */
97 #define yyrule f_rule /* With YYDEBUG defined */
100 #define yydefred f_yydefred
101 #define yydgoto f_yydgoto
102 #define yysindex f_yysindex
103 #define yyrindex f_yyrindex
104 #define yygindex f_yygindex
105 #define yytable f_yytable
106 #define yycheck f_yycheck
108 #define yysslim f_yysslim
109 #define yyssp f_yyssp
110 #define yystacksize f_yystacksize
112 #define yyvsp f_yyvsp
115 #define YYDEBUG 1 /* Default to yydebug support */
118 #define YYFPRINTF parser_fprintf
122 static int yylex (void);
124 void yyerror (char *);
126 static void growbuf_by_size (int);
128 static int match_string_literal (void);
132 /* Although the yacc "value" of an expression is not used,
133 since the result is stored in the structure being created,
134 other node types do have values. */
148 struct symtoken ssym;
151 enum exp_opcode opcode;
152 struct internalvar *ivar;
159 /* YYSTYPE gets defined by %union */
160 static int parse_number (const char *, int, int, YYSTYPE *);
163 %type <voidval> exp type_exp start variable
164 %type <tval> type typebase
165 %type <tvec> nonempty_typelist
166 /* %type <bval> block */
168 /* Fancy type parsing. */
169 %type <voidval> func_mod direct_abs_decl abs_decl
172 %token <typed_val> INT
175 /* Both NAME and TYPENAME tokens represent symbols in the input,
176 and both convey their data as strings.
177 But a TYPENAME is a string that happens to be defined as a typedef
178 or builtin type name (such as int or char)
179 and a NAME is any other symbol.
180 Contexts where this distinction is not important can use the
181 nonterminal "name", which matches either NAME or TYPENAME. */
183 %token <sval> STRING_LITERAL
184 %token <lval> BOOLEAN_LITERAL
186 %token <tsym> TYPENAME
188 %type <ssym> name_not_typename
190 /* A NAME_OR_INT is a symbol which is not known in the symbol table,
191 but which would parse as a valid number in the current input radix.
192 E.g. "c" when input_radix==16. Depending on the parse, it will be
193 turned into a name or into a number. */
195 %token <ssym> NAME_OR_INT
200 /* Special type cases, put in to allow the parser to distinguish different
202 %token INT_KEYWORD INT_S2_KEYWORD LOGICAL_S1_KEYWORD LOGICAL_S2_KEYWORD
203 %token LOGICAL_S8_KEYWORD
204 %token LOGICAL_KEYWORD REAL_KEYWORD REAL_S8_KEYWORD REAL_S16_KEYWORD
205 %token COMPLEX_S8_KEYWORD COMPLEX_S16_KEYWORD COMPLEX_S32_KEYWORD
206 %token BOOL_AND BOOL_OR BOOL_NOT
207 %token <lval> CHARACTER
209 %token <voidval> VARIABLE
211 %token <opcode> ASSIGN_MODIFY
215 %right '=' ASSIGN_MODIFY
224 %left LESSTHAN GREATERTHAN LEQ GEQ
242 { write_exp_elt_opcode(OP_TYPE);
243 write_exp_elt_type($1);
244 write_exp_elt_opcode(OP_TYPE); }
251 /* Expressions, not including the comma operator. */
252 exp : '*' exp %prec UNARY
253 { write_exp_elt_opcode (UNOP_IND); }
256 exp : '&' exp %prec UNARY
257 { write_exp_elt_opcode (UNOP_ADDR); }
260 exp : '-' exp %prec UNARY
261 { write_exp_elt_opcode (UNOP_NEG); }
264 exp : BOOL_NOT exp %prec UNARY
265 { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
268 exp : '~' exp %prec UNARY
269 { write_exp_elt_opcode (UNOP_COMPLEMENT); }
272 exp : SIZEOF exp %prec UNARY
273 { write_exp_elt_opcode (UNOP_SIZEOF); }
276 /* No more explicit array operators, we treat everything in F77 as
277 a function call. The disambiguation as to whether we are
278 doing a subscript operation or a function call is done
282 { start_arglist (); }
284 { write_exp_elt_opcode (OP_F77_UNDETERMINED_ARGLIST);
285 write_exp_elt_longcst ((LONGEST) end_arglist ());
286 write_exp_elt_opcode (OP_F77_UNDETERMINED_ARGLIST); }
300 arglist : arglist ',' exp %prec ABOVE_COMMA
304 /* There are four sorts of subrange types in F90. */
306 subrange: exp ':' exp %prec ABOVE_COMMA
307 { write_exp_elt_opcode (OP_F90_RANGE);
308 write_exp_elt_longcst (NONE_BOUND_DEFAULT);
309 write_exp_elt_opcode (OP_F90_RANGE); }
312 subrange: exp ':' %prec ABOVE_COMMA
313 { write_exp_elt_opcode (OP_F90_RANGE);
314 write_exp_elt_longcst (HIGH_BOUND_DEFAULT);
315 write_exp_elt_opcode (OP_F90_RANGE); }
318 subrange: ':' exp %prec ABOVE_COMMA
319 { write_exp_elt_opcode (OP_F90_RANGE);
320 write_exp_elt_longcst (LOW_BOUND_DEFAULT);
321 write_exp_elt_opcode (OP_F90_RANGE); }
324 subrange: ':' %prec ABOVE_COMMA
325 { write_exp_elt_opcode (OP_F90_RANGE);
326 write_exp_elt_longcst (BOTH_BOUND_DEFAULT);
327 write_exp_elt_opcode (OP_F90_RANGE); }
330 complexnum: exp ',' exp
334 exp : '(' complexnum ')'
335 { write_exp_elt_opcode(OP_COMPLEX);
336 write_exp_elt_type (parse_f_type->builtin_complex_s16);
337 write_exp_elt_opcode(OP_COMPLEX); }
340 exp : '(' type ')' exp %prec UNARY
341 { write_exp_elt_opcode (UNOP_CAST);
342 write_exp_elt_type ($2);
343 write_exp_elt_opcode (UNOP_CAST); }
347 { write_exp_elt_opcode (STRUCTOP_STRUCT);
348 write_exp_string ($3);
349 write_exp_elt_opcode (STRUCTOP_STRUCT); }
352 /* Binary operators in order of decreasing precedence. */
355 { write_exp_elt_opcode (BINOP_REPEAT); }
358 exp : exp STARSTAR exp
359 { write_exp_elt_opcode (BINOP_EXP); }
363 { write_exp_elt_opcode (BINOP_MUL); }
367 { write_exp_elt_opcode (BINOP_DIV); }
371 { write_exp_elt_opcode (BINOP_ADD); }
375 { write_exp_elt_opcode (BINOP_SUB); }
379 { write_exp_elt_opcode (BINOP_LSH); }
383 { write_exp_elt_opcode (BINOP_RSH); }
387 { write_exp_elt_opcode (BINOP_EQUAL); }
390 exp : exp NOTEQUAL exp
391 { write_exp_elt_opcode (BINOP_NOTEQUAL); }
395 { write_exp_elt_opcode (BINOP_LEQ); }
399 { write_exp_elt_opcode (BINOP_GEQ); }
402 exp : exp LESSTHAN exp
403 { write_exp_elt_opcode (BINOP_LESS); }
406 exp : exp GREATERTHAN exp
407 { write_exp_elt_opcode (BINOP_GTR); }
411 { write_exp_elt_opcode (BINOP_BITWISE_AND); }
415 { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
419 { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
422 exp : exp BOOL_AND exp
423 { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
427 exp : exp BOOL_OR exp
428 { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
432 { write_exp_elt_opcode (BINOP_ASSIGN); }
435 exp : exp ASSIGN_MODIFY exp
436 { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY);
437 write_exp_elt_opcode ($2);
438 write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); }
442 { write_exp_elt_opcode (OP_LONG);
443 write_exp_elt_type ($1.type);
444 write_exp_elt_longcst ((LONGEST)($1.val));
445 write_exp_elt_opcode (OP_LONG); }
450 parse_number ($1.stoken.ptr, $1.stoken.length, 0, &val);
451 write_exp_elt_opcode (OP_LONG);
452 write_exp_elt_type (val.typed_val.type);
453 write_exp_elt_longcst ((LONGEST)val.typed_val.val);
454 write_exp_elt_opcode (OP_LONG); }
458 { write_exp_elt_opcode (OP_DOUBLE);
459 write_exp_elt_type (parse_f_type->builtin_real_s8);
460 write_exp_elt_dblcst ($1);
461 write_exp_elt_opcode (OP_DOUBLE); }
470 exp : SIZEOF '(' type ')' %prec UNARY
471 { write_exp_elt_opcode (OP_LONG);
472 write_exp_elt_type (parse_f_type->builtin_integer);
474 write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
475 write_exp_elt_opcode (OP_LONG); }
478 exp : BOOLEAN_LITERAL
479 { write_exp_elt_opcode (OP_BOOL);
480 write_exp_elt_longcst ((LONGEST) $1);
481 write_exp_elt_opcode (OP_BOOL);
487 write_exp_elt_opcode (OP_STRING);
488 write_exp_string ($1);
489 write_exp_elt_opcode (OP_STRING);
493 variable: name_not_typename
494 { struct symbol *sym = $1.sym;
498 if (symbol_read_needs_frame (sym))
500 if (innermost_block == 0
501 || contained_in (block_found,
503 innermost_block = block_found;
505 write_exp_elt_opcode (OP_VAR_VALUE);
506 /* We want to use the selected frame, not
507 another more inner frame which happens to
508 be in the same block. */
509 write_exp_elt_block (NULL);
510 write_exp_elt_sym (sym);
511 write_exp_elt_opcode (OP_VAR_VALUE);
516 struct bound_minimal_symbol msymbol;
517 char *arg = copy_name ($1.stoken);
520 lookup_bound_minimal_symbol (arg);
521 if (msymbol.minsym != NULL)
522 write_exp_msymbol (msymbol);
523 else if (!have_full_symbols () && !have_partial_symbols ())
524 error (_("No symbol table is loaded. Use the \"file\" command."));
526 error (_("No symbol \"%s\" in current context."),
527 copy_name ($1.stoken));
539 /* This is where the interesting stuff happens. */
542 struct type *follow_type = $1;
543 struct type *range_type;
552 follow_type = lookup_pointer_type (follow_type);
555 follow_type = lookup_reference_type (follow_type);
558 array_size = pop_type_int ();
559 if (array_size != -1)
562 create_range_type ((struct type *) NULL,
563 parse_f_type->builtin_integer,
566 create_array_type ((struct type *) NULL,
567 follow_type, range_type);
570 follow_type = lookup_pointer_type (follow_type);
573 follow_type = lookup_function_type (follow_type);
581 { push_type (tp_pointer); $$ = 0; }
583 { push_type (tp_pointer); $$ = $2; }
585 { push_type (tp_reference); $$ = 0; }
587 { push_type (tp_reference); $$ = $2; }
591 direct_abs_decl: '(' abs_decl ')'
593 | direct_abs_decl func_mod
594 { push_type (tp_function); }
596 { push_type (tp_function); }
601 | '(' nonempty_typelist ')'
602 { free ($2); $$ = 0; }
605 typebase /* Implements (approximately): (type-qualifier)* type-specifier */
609 { $$ = parse_f_type->builtin_integer; }
611 { $$ = parse_f_type->builtin_integer_s2; }
613 { $$ = parse_f_type->builtin_character; }
615 { $$ = parse_f_type->builtin_logical_s8; }
617 { $$ = parse_f_type->builtin_logical; }
619 { $$ = parse_f_type->builtin_logical_s2; }
621 { $$ = parse_f_type->builtin_logical_s1; }
623 { $$ = parse_f_type->builtin_real; }
625 { $$ = parse_f_type->builtin_real_s8; }
627 { $$ = parse_f_type->builtin_real_s16; }
629 { $$ = parse_f_type->builtin_complex_s8; }
630 | COMPLEX_S16_KEYWORD
631 { $$ = parse_f_type->builtin_complex_s16; }
632 | COMPLEX_S32_KEYWORD
633 { $$ = parse_f_type->builtin_complex_s32; }
638 { $$ = (struct type **) malloc (sizeof (struct type *) * 2);
639 $<ivec>$[0] = 1; /* Number of types in vector */
642 | nonempty_typelist ',' type
643 { int len = sizeof (struct type *) * (++($<ivec>1[0]) + 1);
644 $$ = (struct type **) realloc ((char *) $1, len);
645 $$[$<ivec>$[0]] = $3;
653 name_not_typename : NAME
654 /* These would be useful if name_not_typename was useful, but it is just
655 a fake for "variable", so these cause reduce/reduce conflicts because
656 the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable,
657 =exp) or just an exp. If name_not_typename was ever used in an lvalue
658 context where only a name could occur, this might be useful.
665 /* Take care of parsing a number (anything that starts with a digit).
666 Set yylval and return the token type; update lexptr.
667 LEN is the number of characters in it. */
669 /*** Needs some error checking for the float case ***/
672 parse_number (const char *p, int len, int parsed_float, YYSTYPE *putithere)
677 int base = input_radix;
681 struct type *signed_type;
682 struct type *unsigned_type;
686 /* It's a float since it contains a point or an exponent. */
687 /* [dD] is not understood as an exponent by atof, change it to 'e'. */
691 for (tmp2 = tmp; *tmp2; ++tmp2)
692 if (*tmp2 == 'd' || *tmp2 == 'D')
694 putithere->dval = atof (tmp);
699 /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
735 if (len == 0 && c == 'l')
737 else if (len == 0 && c == 'u')
742 if (c >= '0' && c <= '9')
744 else if (c >= 'a' && c <= 'f')
747 return ERROR; /* Char not a digit */
749 return ERROR; /* Invalid digit in this base */
753 /* Portably test for overflow (only works for nonzero values, so make
754 a second check for zero). */
755 if ((prevn >= n) && n != 0)
756 unsigned_p=1; /* Try something unsigned */
757 /* If range checking enabled, portably test for unsigned overflow. */
758 if (RANGE_CHECK && n != 0)
760 if ((unsigned_p && (unsigned)prevn >= (unsigned)n))
761 range_error (_("Overflow on numeric constant."));
766 /* If the number is too big to be an int, or it's got an l suffix
767 then it's a long. Work out if this has to be a long by
768 shifting right and seeing if anything remains, and the
769 target int size is different to the target long size.
771 In the expression below, we could have tested
772 (n >> gdbarch_int_bit (parse_gdbarch))
773 to see if it was zero,
774 but too many compilers warn about that, when ints and longs
775 are the same size. So we shift it twice, with fewer bits
776 each time, for the same result. */
778 if ((gdbarch_int_bit (parse_gdbarch) != gdbarch_long_bit (parse_gdbarch)
780 >> (gdbarch_int_bit (parse_gdbarch)-2))) /* Avoid shift warning */
783 high_bit = ((ULONGEST)1) << (gdbarch_long_bit (parse_gdbarch)-1);
784 unsigned_type = parse_type->builtin_unsigned_long;
785 signed_type = parse_type->builtin_long;
789 high_bit = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch)-1);
790 unsigned_type = parse_type->builtin_unsigned_int;
791 signed_type = parse_type->builtin_int;
794 putithere->typed_val.val = n;
796 /* If the high bit of the worked out type is set then this number
797 has to be unsigned. */
799 if (unsigned_p || (n & high_bit))
800 putithere->typed_val.type = unsigned_type;
802 putithere->typed_val.type = signed_type;
811 enum exp_opcode opcode;
814 static const struct token dot_ops[] =
816 { ".and.", BOOL_AND, BINOP_END },
817 { ".AND.", BOOL_AND, BINOP_END },
818 { ".or.", BOOL_OR, BINOP_END },
819 { ".OR.", BOOL_OR, BINOP_END },
820 { ".not.", BOOL_NOT, BINOP_END },
821 { ".NOT.", BOOL_NOT, BINOP_END },
822 { ".eq.", EQUAL, BINOP_END },
823 { ".EQ.", EQUAL, BINOP_END },
824 { ".eqv.", EQUAL, BINOP_END },
825 { ".NEQV.", NOTEQUAL, BINOP_END },
826 { ".neqv.", NOTEQUAL, BINOP_END },
827 { ".EQV.", EQUAL, BINOP_END },
828 { ".ne.", NOTEQUAL, BINOP_END },
829 { ".NE.", NOTEQUAL, BINOP_END },
830 { ".le.", LEQ, BINOP_END },
831 { ".LE.", LEQ, BINOP_END },
832 { ".ge.", GEQ, BINOP_END },
833 { ".GE.", GEQ, BINOP_END },
834 { ".gt.", GREATERTHAN, BINOP_END },
835 { ".GT.", GREATERTHAN, BINOP_END },
836 { ".lt.", LESSTHAN, BINOP_END },
837 { ".LT.", LESSTHAN, BINOP_END },
841 struct f77_boolean_val
847 static const struct f77_boolean_val boolean_values[] =
856 static const struct token f77_keywords[] =
858 { "complex_16", COMPLEX_S16_KEYWORD, BINOP_END },
859 { "complex_32", COMPLEX_S32_KEYWORD, BINOP_END },
860 { "character", CHARACTER, BINOP_END },
861 { "integer_2", INT_S2_KEYWORD, BINOP_END },
862 { "logical_1", LOGICAL_S1_KEYWORD, BINOP_END },
863 { "logical_2", LOGICAL_S2_KEYWORD, BINOP_END },
864 { "logical_8", LOGICAL_S8_KEYWORD, BINOP_END },
865 { "complex_8", COMPLEX_S8_KEYWORD, BINOP_END },
866 { "integer", INT_KEYWORD, BINOP_END },
867 { "logical", LOGICAL_KEYWORD, BINOP_END },
868 { "real_16", REAL_S16_KEYWORD, BINOP_END },
869 { "complex", COMPLEX_S8_KEYWORD, BINOP_END },
870 { "sizeof", SIZEOF, BINOP_END },
871 { "real_8", REAL_S8_KEYWORD, BINOP_END },
872 { "real", REAL_KEYWORD, BINOP_END },
876 /* Implementation of a dynamically expandable buffer for processing input
877 characters acquired through lexptr and building a value to return in
878 yylval. Ripped off from ch-exp.y */
880 static char *tempbuf; /* Current buffer contents */
881 static int tempbufsize; /* Size of allocated buffer */
882 static int tempbufindex; /* Current index into buffer */
884 #define GROWBY_MIN_SIZE 64 /* Minimum amount to grow buffer by */
886 #define CHECKBUF(size) \
888 if (tempbufindex + (size) >= tempbufsize) \
890 growbuf_by_size (size); \
895 /* Grow the static temp buffer if necessary, including allocating the
896 first one on demand. */
899 growbuf_by_size (int count)
903 growby = max (count, GROWBY_MIN_SIZE);
904 tempbufsize += growby;
906 tempbuf = (char *) malloc (tempbufsize);
908 tempbuf = (char *) realloc (tempbuf, tempbufsize);
911 /* Blatantly ripped off from ch-exp.y. This routine recognizes F77
914 Recognize a string literal. A string literal is a nonzero sequence
915 of characters enclosed in matching single quotes, except that
916 a single character inside single quotes is a character literal, which
917 we reject as a string literal. To embed the terminator character inside
918 a string, it is simply doubled (I.E. 'this''is''one''string') */
921 match_string_literal (void)
923 const char *tokptr = lexptr;
925 for (tempbufindex = 0, tokptr++; *tokptr != '\0'; tokptr++)
928 if (*tokptr == *lexptr)
930 if (*(tokptr + 1) == *lexptr)
935 tempbuf[tempbufindex++] = *tokptr;
937 if (*tokptr == '\0' /* no terminator */
938 || tempbufindex == 0) /* no string */
942 tempbuf[tempbufindex] = '\0';
943 yylval.sval.ptr = tempbuf;
944 yylval.sval.length = tempbufindex;
946 return STRING_LITERAL;
950 /* Read one token, getting characters through lexptr. */
957 unsigned int i,token;
958 const char *tokstart;
962 prev_lexptr = lexptr;
966 /* First of all, let us make sure we are not dealing with the
967 special tokens .true. and .false. which evaluate to 1 and 0. */
971 for (i = 0; boolean_values[i].name != NULL; i++)
973 if (strncmp (tokstart, boolean_values[i].name,
974 strlen (boolean_values[i].name)) == 0)
976 lexptr += strlen (boolean_values[i].name);
977 yylval.lval = boolean_values[i].value;
978 return BOOLEAN_LITERAL;
983 /* See if it is a special .foo. operator. */
985 for (i = 0; dot_ops[i].operator != NULL; i++)
986 if (strncmp (tokstart, dot_ops[i].operator,
987 strlen (dot_ops[i].operator)) == 0)
989 lexptr += strlen (dot_ops[i].operator);
990 yylval.opcode = dot_ops[i].opcode;
991 return dot_ops[i].token;
994 /* See if it is an exponentiation operator. */
996 if (strncmp (tokstart, "**", 2) == 0)
999 yylval.opcode = BINOP_EXP;
1003 switch (c = *tokstart)
1015 token = match_string_literal ();
1026 if (paren_depth == 0)
1033 if (comma_terminates && paren_depth == 0)
1039 /* Might be a floating point number. */
1040 if (lexptr[1] < '0' || lexptr[1] > '9')
1041 goto symbol; /* Nope, must be a symbol. */
1042 /* FALL THRU into number case. */
1055 /* It's a number. */
1056 int got_dot = 0, got_e = 0, got_d = 0, toktype;
1057 const char *p = tokstart;
1058 int hex = input_radix > 10;
1060 if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
1065 else if (c == '0' && (p[1]=='t' || p[1]=='T'
1066 || p[1]=='d' || p[1]=='D'))
1074 if (!hex && !got_e && (*p == 'e' || *p == 'E'))
1075 got_dot = got_e = 1;
1076 else if (!hex && !got_d && (*p == 'd' || *p == 'D'))
1077 got_dot = got_d = 1;
1078 else if (!hex && !got_dot && *p == '.')
1080 else if (((got_e && (p[-1] == 'e' || p[-1] == 'E'))
1081 || (got_d && (p[-1] == 'd' || p[-1] == 'D')))
1082 && (*p == '-' || *p == '+'))
1083 /* This is the sign of the exponent, not the end of the
1086 /* We will take any letters or digits. parse_number will
1087 complain if past the radix, or if L or U are not final. */
1088 else if ((*p < '0' || *p > '9')
1089 && ((*p < 'a' || *p > 'z')
1090 && (*p < 'A' || *p > 'Z')))
1093 toktype = parse_number (tokstart, p - tokstart, got_dot|got_e|got_d,
1095 if (toktype == ERROR)
1097 char *err_copy = (char *) alloca (p - tokstart + 1);
1099 memcpy (err_copy, tokstart, p - tokstart);
1100 err_copy[p - tokstart] = 0;
1101 error (_("Invalid number \"%s\"."), err_copy);
1132 if (!(c == '_' || c == '$' || c ==':'
1133 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
1134 /* We must have come across a bad character (e.g. ';'). */
1135 error (_("Invalid character '%c' in expression."), c);
1138 for (c = tokstart[namelen];
1139 (c == '_' || c == '$' || c == ':' || (c >= '0' && c <= '9')
1140 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
1141 c = tokstart[++namelen]);
1143 /* The token "if" terminates the expression and is NOT
1144 removed from the input stream. */
1146 if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
1151 /* Catch specific keywords. */
1153 for (i = 0; f77_keywords[i].operator != NULL; i++)
1154 if (strlen (f77_keywords[i].operator) == namelen
1155 && strncmp (tokstart, f77_keywords[i].operator, namelen) == 0)
1157 /* lexptr += strlen(f77_keywords[i].operator); */
1158 yylval.opcode = f77_keywords[i].opcode;
1159 return f77_keywords[i].token;
1162 yylval.sval.ptr = tokstart;
1163 yylval.sval.length = namelen;
1165 if (*tokstart == '$')
1167 write_dollar_variable (yylval.sval);
1171 /* Use token-type TYPENAME for symbols that happen to be defined
1172 currently as names of types; NAME for other symbols.
1173 The caller is not constrained to care about the distinction. */
1175 char *tmp = copy_name (yylval.sval);
1177 struct field_of_this_result is_a_field_of_this;
1178 enum domain_enum_tag lookup_domains[] =
1187 for (i = 0; i < ARRAY_SIZE (lookup_domains); ++i)
1189 /* Initialize this in case we *don't* use it in this call; that
1190 way we can refer to it unconditionally below. */
1191 memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this));
1193 sym = lookup_symbol (tmp, expression_context_block,
1195 parse_language->la_language == language_cplus
1196 ? &is_a_field_of_this : NULL);
1197 if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
1199 yylval.tsym.type = SYMBOL_TYPE (sym);
1208 = language_lookup_primitive_type_by_name (parse_language,
1209 parse_gdbarch, tmp);
1210 if (yylval.tsym.type != NULL)
1213 /* Input names that aren't symbols but ARE valid hex numbers,
1214 when the input radix permits them, can be names or numbers
1215 depending on the parse. Note we support radixes > 16 here. */
1217 && ((tokstart[0] >= 'a' && tokstart[0] < 'a' + input_radix - 10)
1218 || (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10)))
1220 YYSTYPE newlval; /* Its value is ignored. */
1221 hextype = parse_number (tokstart, namelen, 0, &newlval);
1224 yylval.ssym.sym = sym;
1225 yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
1230 /* Any other kind of symbol */
1231 yylval.ssym.sym = sym;
1232 yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
1241 lexptr = prev_lexptr;
1243 error (_("A %s in expression, near `%s'."), (msg ? msg : "error"), lexptr);