1 /* YACC parser for Fortran expressions, for GDB.
2 Copyright 1986, 1989, 1990, 1991, 1993, 1994, 1995, 1996, 2000, 2001,
3 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
5 Contributed by Motorola. Adapted from the C parser by Farooq Butt
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 2 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, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24 /* This was blantantly ripped off the C expression parser, please
25 be aware of that as you look at its basic structure -FMB */
27 /* Parse a F77 expression from text in a string,
28 and return the result as a struct expression pointer.
29 That structure contains arithmetic operations in reverse polish,
30 with constants represented by operations that are followed by special data.
31 See expression.h for the details of the format.
32 What is important here is that it can be built up sequentially
33 during the process of parsing; the lower levels of the tree always
34 come first in the result.
36 Note that malloc's and realloc's in this file are transformed to
37 xmalloc and xrealloc respectively by the same sed command in the
38 makefile that remaps any other malloc/realloc inserted by the parser
39 generator. Doing this with #defines and trying to control the interaction
40 with include files (<malloc.h> and <stdlib.h> for example) just became
41 too messy, particularly when such includes can be inserted at random
42 times by the parser generator. */
47 #include "gdb_string.h"
48 #include "expression.h"
50 #include "parser-defs.h"
53 #include "bfd.h" /* Required by objfiles.h. */
54 #include "symfile.h" /* Required by objfiles.h. */
55 #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
59 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
60 as well as gratuitiously global symbol names, so we can have multiple
61 yacc generated parsers in gdb. Note that these are only the variables
62 produced by yacc. If other parser generators (bison, byacc, etc) produce
63 additional global names that conflict at link time, then those parser
64 generators need to be fixed instead of adding those names to this list. */
66 #define yymaxdepth f_maxdepth
67 #define yyparse f_parse
69 #define yyerror f_error
72 #define yydebug f_debug
81 #define yyerrflag f_errflag
82 #define yynerrs f_nerrs
87 #define yystate f_state
93 #define yyreds f_reds /* With YYDEBUG defined */
94 #define yytoks f_toks /* With YYDEBUG defined */
95 #define yyname f_name /* With YYDEBUG defined */
96 #define yyrule f_rule /* With YYDEBUG defined */
99 #define yydefred f_yydefred
100 #define yydgoto f_yydgoto
101 #define yysindex f_yysindex
102 #define yyrindex f_yyrindex
103 #define yygindex f_yygindex
104 #define yytable f_yytable
105 #define yycheck f_yycheck
108 #define YYDEBUG 1 /* Default to yydebug support */
111 #define YYFPRINTF parser_fprintf
115 static int yylex (void);
117 void yyerror (char *);
119 static void growbuf_by_size (int);
121 static int match_string_literal (void);
125 /* Although the yacc "value" of an expression is not used,
126 since the result is stored in the structure being created,
127 other node types do have values. */
141 struct symtoken ssym;
144 enum exp_opcode opcode;
145 struct internalvar *ivar;
152 /* YYSTYPE gets defined by %union */
153 static int parse_number (char *, int, int, YYSTYPE *);
156 %type <voidval> exp type_exp start variable
157 %type <tval> type typebase
158 %type <tvec> nonempty_typelist
159 /* %type <bval> block */
161 /* Fancy type parsing. */
162 %type <voidval> func_mod direct_abs_decl abs_decl
165 %token <typed_val> INT
168 /* Both NAME and TYPENAME tokens represent symbols in the input,
169 and both convey their data as strings.
170 But a TYPENAME is a string that happens to be defined as a typedef
171 or builtin type name (such as int or char)
172 and a NAME is any other symbol.
173 Contexts where this distinction is not important can use the
174 nonterminal "name", which matches either NAME or TYPENAME. */
176 %token <sval> STRING_LITERAL
177 %token <lval> BOOLEAN_LITERAL
179 %token <tsym> TYPENAME
180 %type <ssym> name_not_typename
182 /* A NAME_OR_INT is a symbol which is not known in the symbol table,
183 but which would parse as a valid number in the current input radix.
184 E.g. "c" when input_radix==16. Depending on the parse, it will be
185 turned into a name or into a number. */
187 %token <ssym> NAME_OR_INT
192 /* Special type cases, put in to allow the parser to distinguish different
194 %token INT_KEYWORD INT_S2_KEYWORD LOGICAL_S1_KEYWORD LOGICAL_S2_KEYWORD
195 %token LOGICAL_KEYWORD REAL_KEYWORD REAL_S8_KEYWORD REAL_S16_KEYWORD
196 %token COMPLEX_S8_KEYWORD COMPLEX_S16_KEYWORD COMPLEX_S32_KEYWORD
197 %token BOOL_AND BOOL_OR BOOL_NOT
198 %token <lval> CHARACTER
200 %token <voidval> VARIABLE
202 %token <opcode> ASSIGN_MODIFY
206 %right '=' ASSIGN_MODIFY
215 %left LESSTHAN GREATERTHAN LEQ GEQ
232 { write_exp_elt_opcode(OP_TYPE);
233 write_exp_elt_type($1);
234 write_exp_elt_opcode(OP_TYPE); }
241 /* Expressions, not including the comma operator. */
242 exp : '*' exp %prec UNARY
243 { write_exp_elt_opcode (UNOP_IND); }
246 exp : '&' exp %prec UNARY
247 { write_exp_elt_opcode (UNOP_ADDR); }
250 exp : '-' exp %prec UNARY
251 { write_exp_elt_opcode (UNOP_NEG); }
254 exp : BOOL_NOT exp %prec UNARY
255 { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
258 exp : '~' exp %prec UNARY
259 { write_exp_elt_opcode (UNOP_COMPLEMENT); }
262 exp : SIZEOF exp %prec UNARY
263 { write_exp_elt_opcode (UNOP_SIZEOF); }
266 /* No more explicit array operators, we treat everything in F77 as
267 a function call. The disambiguation as to whether we are
268 doing a subscript operation or a function call is done
272 { start_arglist (); }
274 { write_exp_elt_opcode (OP_F77_UNDETERMINED_ARGLIST);
275 write_exp_elt_longcst ((LONGEST) end_arglist ());
276 write_exp_elt_opcode (OP_F77_UNDETERMINED_ARGLIST); }
290 arglist : arglist ',' exp %prec ABOVE_COMMA
294 /* There are four sorts of subrange types in F90. */
296 subrange: exp ':' exp %prec ABOVE_COMMA
297 { write_exp_elt_opcode (OP_F90_RANGE);
298 write_exp_elt_longcst (NONE_BOUND_DEFAULT);
299 write_exp_elt_opcode (OP_F90_RANGE); }
302 subrange: exp ':' %prec ABOVE_COMMA
303 { write_exp_elt_opcode (OP_F90_RANGE);
304 write_exp_elt_longcst (HIGH_BOUND_DEFAULT);
305 write_exp_elt_opcode (OP_F90_RANGE); }
308 subrange: ':' exp %prec ABOVE_COMMA
309 { write_exp_elt_opcode (OP_F90_RANGE);
310 write_exp_elt_longcst (LOW_BOUND_DEFAULT);
311 write_exp_elt_opcode (OP_F90_RANGE); }
314 subrange: ':' %prec ABOVE_COMMA
315 { write_exp_elt_opcode (OP_F90_RANGE);
316 write_exp_elt_longcst (BOTH_BOUND_DEFAULT);
317 write_exp_elt_opcode (OP_F90_RANGE); }
320 complexnum: exp ',' exp
324 exp : '(' complexnum ')'
325 { write_exp_elt_opcode(OP_COMPLEX); }
328 exp : '(' type ')' exp %prec UNARY
329 { write_exp_elt_opcode (UNOP_CAST);
330 write_exp_elt_type ($2);
331 write_exp_elt_opcode (UNOP_CAST); }
334 /* Binary operators in order of decreasing precedence. */
337 { write_exp_elt_opcode (BINOP_REPEAT); }
340 exp : exp STARSTAR exp
341 { write_exp_elt_opcode (BINOP_EXP); }
345 { write_exp_elt_opcode (BINOP_MUL); }
349 { write_exp_elt_opcode (BINOP_DIV); }
353 { write_exp_elt_opcode (BINOP_REM); }
357 { write_exp_elt_opcode (BINOP_ADD); }
361 { write_exp_elt_opcode (BINOP_SUB); }
365 { write_exp_elt_opcode (BINOP_LSH); }
369 { write_exp_elt_opcode (BINOP_RSH); }
373 { write_exp_elt_opcode (BINOP_EQUAL); }
376 exp : exp NOTEQUAL exp
377 { write_exp_elt_opcode (BINOP_NOTEQUAL); }
381 { write_exp_elt_opcode (BINOP_LEQ); }
385 { write_exp_elt_opcode (BINOP_GEQ); }
388 exp : exp LESSTHAN exp
389 { write_exp_elt_opcode (BINOP_LESS); }
392 exp : exp GREATERTHAN exp
393 { write_exp_elt_opcode (BINOP_GTR); }
397 { write_exp_elt_opcode (BINOP_BITWISE_AND); }
401 { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
405 { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
408 exp : exp BOOL_AND exp
409 { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
413 exp : exp BOOL_OR exp
414 { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
418 { write_exp_elt_opcode (BINOP_ASSIGN); }
421 exp : exp ASSIGN_MODIFY exp
422 { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY);
423 write_exp_elt_opcode ($2);
424 write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); }
428 { write_exp_elt_opcode (OP_LONG);
429 write_exp_elt_type ($1.type);
430 write_exp_elt_longcst ((LONGEST)($1.val));
431 write_exp_elt_opcode (OP_LONG); }
436 parse_number ($1.stoken.ptr, $1.stoken.length, 0, &val);
437 write_exp_elt_opcode (OP_LONG);
438 write_exp_elt_type (val.typed_val.type);
439 write_exp_elt_longcst ((LONGEST)val.typed_val.val);
440 write_exp_elt_opcode (OP_LONG); }
444 { write_exp_elt_opcode (OP_DOUBLE);
445 write_exp_elt_type (builtin_type_f_real_s8);
446 write_exp_elt_dblcst ($1);
447 write_exp_elt_opcode (OP_DOUBLE); }
456 exp : SIZEOF '(' type ')' %prec UNARY
457 { write_exp_elt_opcode (OP_LONG);
458 write_exp_elt_type (builtin_type_f_integer);
460 write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
461 write_exp_elt_opcode (OP_LONG); }
464 exp : BOOLEAN_LITERAL
465 { write_exp_elt_opcode (OP_BOOL);
466 write_exp_elt_longcst ((LONGEST) $1);
467 write_exp_elt_opcode (OP_BOOL);
473 write_exp_elt_opcode (OP_STRING);
474 write_exp_string ($1);
475 write_exp_elt_opcode (OP_STRING);
479 variable: name_not_typename
480 { struct symbol *sym = $1.sym;
484 if (symbol_read_needs_frame (sym))
486 if (innermost_block == 0 ||
487 contained_in (block_found,
489 innermost_block = block_found;
491 write_exp_elt_opcode (OP_VAR_VALUE);
492 /* We want to use the selected frame, not
493 another more inner frame which happens to
494 be in the same block. */
495 write_exp_elt_block (NULL);
496 write_exp_elt_sym (sym);
497 write_exp_elt_opcode (OP_VAR_VALUE);
502 struct minimal_symbol *msymbol;
503 char *arg = copy_name ($1.stoken);
506 lookup_minimal_symbol (arg, NULL, NULL);
509 write_exp_msymbol (msymbol,
510 lookup_function_type (builtin_type_int),
513 else if (!have_full_symbols () && !have_partial_symbols ())
514 error ("No symbol table is loaded. Use the \"file\" command.");
516 error ("No symbol \"%s\" in current context.",
517 copy_name ($1.stoken));
529 /* This is where the interesting stuff happens. */
532 struct type *follow_type = $1;
533 struct type *range_type;
542 follow_type = lookup_pointer_type (follow_type);
545 follow_type = lookup_reference_type (follow_type);
548 array_size = pop_type_int ();
549 if (array_size != -1)
552 create_range_type ((struct type *) NULL,
553 builtin_type_f_integer, 0,
556 create_array_type ((struct type *) NULL,
557 follow_type, range_type);
560 follow_type = lookup_pointer_type (follow_type);
563 follow_type = lookup_function_type (follow_type);
571 { push_type (tp_pointer); $$ = 0; }
573 { push_type (tp_pointer); $$ = $2; }
575 { push_type (tp_reference); $$ = 0; }
577 { push_type (tp_reference); $$ = $2; }
581 direct_abs_decl: '(' abs_decl ')'
583 | direct_abs_decl func_mod
584 { push_type (tp_function); }
586 { push_type (tp_function); }
591 | '(' nonempty_typelist ')'
592 { free ($2); $$ = 0; }
595 typebase /* Implements (approximately): (type-qualifier)* type-specifier */
599 { $$ = builtin_type_f_integer; }
601 { $$ = builtin_type_f_integer_s2; }
603 { $$ = builtin_type_f_character; }
605 { $$ = builtin_type_f_logical;}
607 { $$ = builtin_type_f_logical_s2;}
609 { $$ = builtin_type_f_logical_s1;}
611 { $$ = builtin_type_f_real;}
613 { $$ = builtin_type_f_real_s8;}
615 { $$ = builtin_type_f_real_s16;}
617 { $$ = builtin_type_f_complex_s8;}
618 | COMPLEX_S16_KEYWORD
619 { $$ = builtin_type_f_complex_s16;}
620 | COMPLEX_S32_KEYWORD
621 { $$ = builtin_type_f_complex_s32;}
626 { $$ = (struct type **) malloc (sizeof (struct type *) * 2);
627 $<ivec>$[0] = 1; /* Number of types in vector */
630 | nonempty_typelist ',' type
631 { int len = sizeof (struct type *) * (++($<ivec>1[0]) + 1);
632 $$ = (struct type **) realloc ((char *) $1, len);
633 $$[$<ivec>$[0]] = $3;
637 name_not_typename : NAME
638 /* These would be useful if name_not_typename was useful, but it is just
639 a fake for "variable", so these cause reduce/reduce conflicts because
640 the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable,
641 =exp) or just an exp. If name_not_typename was ever used in an lvalue
642 context where only a name could occur, this might be useful.
649 /* Take care of parsing a number (anything that starts with a digit).
650 Set yylval and return the token type; update lexptr.
651 LEN is the number of characters in it. */
653 /*** Needs some error checking for the float case ***/
656 parse_number (p, len, parsed_float, putithere)
665 int base = input_radix;
669 struct type *signed_type;
670 struct type *unsigned_type;
674 /* It's a float since it contains a point or an exponent. */
675 /* [dD] is not understood as an exponent by atof, change it to 'e'. */
679 for (tmp2 = tmp; *tmp2; ++tmp2)
680 if (*tmp2 == 'd' || *tmp2 == 'D')
682 putithere->dval = atof (tmp);
687 /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
723 if (len == 0 && c == 'l')
725 else if (len == 0 && c == 'u')
730 if (c >= '0' && c <= '9')
732 else if (c >= 'a' && c <= 'f')
735 return ERROR; /* Char not a digit */
737 return ERROR; /* Invalid digit in this base */
741 /* Portably test for overflow (only works for nonzero values, so make
742 a second check for zero). */
743 if ((prevn >= n) && n != 0)
744 unsigned_p=1; /* Try something unsigned */
745 /* If range checking enabled, portably test for unsigned overflow. */
746 if (RANGE_CHECK && n != 0)
748 if ((unsigned_p && (unsigned)prevn >= (unsigned)n))
749 range_error("Overflow on numeric constant.");
754 /* If the number is too big to be an int, or it's got an l suffix
755 then it's a long. Work out if this has to be a long by
756 shifting right and and seeing if anything remains, and the
757 target int size is different to the target long size.
759 In the expression below, we could have tested
760 (n >> TARGET_INT_BIT)
761 to see if it was zero,
762 but too many compilers warn about that, when ints and longs
763 are the same size. So we shift it twice, with fewer bits
764 each time, for the same result. */
766 if ((TARGET_INT_BIT != TARGET_LONG_BIT
767 && ((n >> 2) >> (TARGET_INT_BIT-2))) /* Avoid shift warning */
770 high_bit = ((ULONGEST)1) << (TARGET_LONG_BIT-1);
771 unsigned_type = builtin_type_unsigned_long;
772 signed_type = builtin_type_long;
776 high_bit = ((ULONGEST)1) << (TARGET_INT_BIT-1);
777 unsigned_type = builtin_type_unsigned_int;
778 signed_type = builtin_type_int;
781 putithere->typed_val.val = n;
783 /* If the high bit of the worked out type is set then this number
784 has to be unsigned. */
786 if (unsigned_p || (n & high_bit))
787 putithere->typed_val.type = unsigned_type;
789 putithere->typed_val.type = signed_type;
798 enum exp_opcode opcode;
801 static const struct token dot_ops[] =
803 { ".and.", BOOL_AND, BINOP_END },
804 { ".AND.", BOOL_AND, BINOP_END },
805 { ".or.", BOOL_OR, BINOP_END },
806 { ".OR.", BOOL_OR, BINOP_END },
807 { ".not.", BOOL_NOT, BINOP_END },
808 { ".NOT.", BOOL_NOT, BINOP_END },
809 { ".eq.", EQUAL, BINOP_END },
810 { ".EQ.", EQUAL, BINOP_END },
811 { ".eqv.", EQUAL, BINOP_END },
812 { ".NEQV.", NOTEQUAL, BINOP_END },
813 { ".neqv.", NOTEQUAL, BINOP_END },
814 { ".EQV.", EQUAL, BINOP_END },
815 { ".ne.", NOTEQUAL, BINOP_END },
816 { ".NE.", NOTEQUAL, BINOP_END },
817 { ".le.", LEQ, BINOP_END },
818 { ".LE.", LEQ, BINOP_END },
819 { ".ge.", GEQ, BINOP_END },
820 { ".GE.", GEQ, BINOP_END },
821 { ".gt.", GREATERTHAN, BINOP_END },
822 { ".GT.", GREATERTHAN, BINOP_END },
823 { ".lt.", LESSTHAN, BINOP_END },
824 { ".LT.", LESSTHAN, BINOP_END },
828 struct f77_boolean_val
834 static const struct f77_boolean_val boolean_values[] =
843 static const struct token f77_keywords[] =
845 { "complex_16", COMPLEX_S16_KEYWORD, BINOP_END },
846 { "complex_32", COMPLEX_S32_KEYWORD, BINOP_END },
847 { "character", CHARACTER, BINOP_END },
848 { "integer_2", INT_S2_KEYWORD, BINOP_END },
849 { "logical_1", LOGICAL_S1_KEYWORD, BINOP_END },
850 { "logical_2", LOGICAL_S2_KEYWORD, BINOP_END },
851 { "complex_8", COMPLEX_S8_KEYWORD, BINOP_END },
852 { "integer", INT_KEYWORD, BINOP_END },
853 { "logical", LOGICAL_KEYWORD, BINOP_END },
854 { "real_16", REAL_S16_KEYWORD, BINOP_END },
855 { "complex", COMPLEX_S8_KEYWORD, BINOP_END },
856 { "sizeof", SIZEOF, BINOP_END },
857 { "real_8", REAL_S8_KEYWORD, BINOP_END },
858 { "real", REAL_KEYWORD, BINOP_END },
862 /* Implementation of a dynamically expandable buffer for processing input
863 characters acquired through lexptr and building a value to return in
864 yylval. Ripped off from ch-exp.y */
866 static char *tempbuf; /* Current buffer contents */
867 static int tempbufsize; /* Size of allocated buffer */
868 static int tempbufindex; /* Current index into buffer */
870 #define GROWBY_MIN_SIZE 64 /* Minimum amount to grow buffer by */
872 #define CHECKBUF(size) \
874 if (tempbufindex + (size) >= tempbufsize) \
876 growbuf_by_size (size); \
881 /* Grow the static temp buffer if necessary, including allocating the first one
885 growbuf_by_size (count)
890 growby = max (count, GROWBY_MIN_SIZE);
891 tempbufsize += growby;
893 tempbuf = (char *) malloc (tempbufsize);
895 tempbuf = (char *) realloc (tempbuf, tempbufsize);
898 /* Blatantly ripped off from ch-exp.y. This routine recognizes F77
901 Recognize a string literal. A string literal is a nonzero sequence
902 of characters enclosed in matching single quotes, except that
903 a single character inside single quotes is a character literal, which
904 we reject as a string literal. To embed the terminator character inside
905 a string, it is simply doubled (I.E. 'this''is''one''string') */
908 match_string_literal ()
910 char *tokptr = lexptr;
912 for (tempbufindex = 0, tokptr++; *tokptr != '\0'; tokptr++)
915 if (*tokptr == *lexptr)
917 if (*(tokptr + 1) == *lexptr)
922 tempbuf[tempbufindex++] = *tokptr;
924 if (*tokptr == '\0' /* no terminator */
925 || tempbufindex == 0) /* no string */
929 tempbuf[tempbufindex] = '\0';
930 yylval.sval.ptr = tempbuf;
931 yylval.sval.length = tempbufindex;
933 return STRING_LITERAL;
937 /* Read one token, getting characters through lexptr. */
944 unsigned int i,token;
949 prev_lexptr = lexptr;
953 /* First of all, let us make sure we are not dealing with the
954 special tokens .true. and .false. which evaluate to 1 and 0. */
958 for (i = 0; boolean_values[i].name != NULL; i++)
960 if (strncmp (tokstart, boolean_values[i].name,
961 strlen (boolean_values[i].name)) == 0)
963 lexptr += strlen (boolean_values[i].name);
964 yylval.lval = boolean_values[i].value;
965 return BOOLEAN_LITERAL;
970 /* See if it is a special .foo. operator. */
972 for (i = 0; dot_ops[i].operator != NULL; i++)
973 if (strncmp (tokstart, dot_ops[i].operator, strlen (dot_ops[i].operator)) == 0)
975 lexptr += strlen (dot_ops[i].operator);
976 yylval.opcode = dot_ops[i].opcode;
977 return dot_ops[i].token;
980 /* See if it is an exponentiation operator. */
982 if (strncmp (tokstart, "**", 2) == 0)
985 yylval.opcode = BINOP_EXP;
989 switch (c = *tokstart)
1001 token = match_string_literal ();
1012 if (paren_depth == 0)
1019 if (comma_terminates && paren_depth == 0)
1025 /* Might be a floating point number. */
1026 if (lexptr[1] < '0' || lexptr[1] > '9')
1027 goto symbol; /* Nope, must be a symbol. */
1028 /* FALL THRU into number case. */
1041 /* It's a number. */
1042 int got_dot = 0, got_e = 0, got_d = 0, toktype;
1044 int hex = input_radix > 10;
1046 if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
1051 else if (c == '0' && (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))
1059 if (!hex && !got_e && (*p == 'e' || *p == 'E'))
1060 got_dot = got_e = 1;
1061 else if (!hex && !got_d && (*p == 'd' || *p == 'D'))
1062 got_dot = got_d = 1;
1063 else if (!hex && !got_dot && *p == '.')
1065 else if (((got_e && (p[-1] == 'e' || p[-1] == 'E'))
1066 || (got_d && (p[-1] == 'd' || p[-1] == 'D')))
1067 && (*p == '-' || *p == '+'))
1068 /* This is the sign of the exponent, not the end of the
1071 /* We will take any letters or digits. parse_number will
1072 complain if past the radix, or if L or U are not final. */
1073 else if ((*p < '0' || *p > '9')
1074 && ((*p < 'a' || *p > 'z')
1075 && (*p < 'A' || *p > 'Z')))
1078 toktype = parse_number (tokstart, p - tokstart, got_dot|got_e|got_d,
1080 if (toktype == ERROR)
1082 char *err_copy = (char *) alloca (p - tokstart + 1);
1084 memcpy (err_copy, tokstart, p - tokstart);
1085 err_copy[p - tokstart] = 0;
1086 error ("Invalid number \"%s\".", err_copy);
1117 if (!(c == '_' || c == '$'
1118 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
1119 /* We must have come across a bad character (e.g. ';'). */
1120 error ("Invalid character '%c' in expression.", c);
1123 for (c = tokstart[namelen];
1124 (c == '_' || c == '$' || (c >= '0' && c <= '9')
1125 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
1126 c = tokstart[++namelen]);
1128 /* The token "if" terminates the expression and is NOT
1129 removed from the input stream. */
1131 if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
1136 /* Catch specific keywords. */
1138 for (i = 0; f77_keywords[i].operator != NULL; i++)
1139 if (strncmp (tokstart, f77_keywords[i].operator,
1140 strlen(f77_keywords[i].operator)) == 0)
1142 /* lexptr += strlen(f77_keywords[i].operator); */
1143 yylval.opcode = f77_keywords[i].opcode;
1144 return f77_keywords[i].token;
1147 yylval.sval.ptr = tokstart;
1148 yylval.sval.length = namelen;
1150 if (*tokstart == '$')
1152 write_dollar_variable (yylval.sval);
1156 /* Use token-type TYPENAME for symbols that happen to be defined
1157 currently as names of types; NAME for other symbols.
1158 The caller is not constrained to care about the distinction. */
1160 char *tmp = copy_name (yylval.sval);
1162 int is_a_field_of_this = 0;
1165 sym = lookup_symbol (tmp, expression_context_block,
1167 current_language->la_language == language_cplus
1168 ? &is_a_field_of_this : NULL,
1170 if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
1172 yylval.tsym.type = SYMBOL_TYPE (sym);
1176 = language_lookup_primitive_type_by_name (current_language,
1177 current_gdbarch, tmp);
1178 if (yylval.tsym.type != NULL)
1181 /* Input names that aren't symbols but ARE valid hex numbers,
1182 when the input radix permits them, can be names or numbers
1183 depending on the parse. Note we support radixes > 16 here. */
1185 && ((tokstart[0] >= 'a' && tokstart[0] < 'a' + input_radix - 10)
1186 || (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10)))
1188 YYSTYPE newlval; /* Its value is ignored. */
1189 hextype = parse_number (tokstart, namelen, 0, &newlval);
1192 yylval.ssym.sym = sym;
1193 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
1198 /* Any other kind of symbol */
1199 yylval.ssym.sym = sym;
1200 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
1210 lexptr = prev_lexptr;
1212 error ("A %s in expression, near `%s'.", (msg ? msg : "error"), lexptr);