1 /* YACC parser for C expressions, for GDB.
2 Copyright (C) 1986, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2003, 2004, 2006, 2007, 2008, 2009
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 /* Parse a C expression from text in a string,
24 and return the result as a struct expression pointer.
25 That structure contains arithmetic operations in reverse polish,
26 with constants represented by operations that are followed by special data.
27 See expression.h for the details of the format.
28 What is important here is that it can be built up sequentially
29 during the process of parsing; the lower levels of the tree always
30 come first in the result.
32 Note that malloc's and realloc's in this file are transformed to
33 xmalloc and xrealloc respectively by the same sed command in the
34 makefile that remaps any other malloc/realloc inserted by the parser
35 generator. Doing this with #defines and trying to control the interaction
36 with include files (<malloc.h> and <stdlib.h> for example) just became
37 too messy, particularly when such includes can be inserted at random
38 times by the parser generator. */
43 #include "gdb_string.h"
45 #include "expression.h"
47 #include "parser-defs.h"
50 #include "bfd.h" /* Required by objfiles.h. */
51 #include "symfile.h" /* Required by objfiles.h. */
52 #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
55 #include "cp-support.h"
57 #include "gdb_assert.h"
58 #include "macroscope.h"
60 #define parse_type builtin_type (parse_gdbarch)
62 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
63 as well as gratuitiously global symbol names, so we can have multiple
64 yacc generated parsers in gdb. Note that these are only the variables
65 produced by yacc. If other parser generators (bison, byacc, etc) produce
66 additional global names that conflict at link time, then those parser
67 generators need to be fixed instead of adding those names to this list. */
69 #define yymaxdepth c_maxdepth
70 #define yyparse c_parse_internal
72 #define yyerror c_error
75 #define yydebug c_debug
84 #define yyerrflag c_errflag
85 #define yynerrs c_nerrs
90 #define yystate c_state
96 #define yyreds c_reds /* With YYDEBUG defined */
97 #define yytoks c_toks /* With YYDEBUG defined */
98 #define yyname c_name /* With YYDEBUG defined */
99 #define yyrule c_rule /* With YYDEBUG defined */
100 #define yylhs c_yylhs
101 #define yylen c_yylen
102 #define yydefred c_yydefred
103 #define yydgoto c_yydgoto
104 #define yysindex c_yysindex
105 #define yyrindex c_yyrindex
106 #define yygindex c_yygindex
107 #define yytable c_yytable
108 #define yycheck c_yycheck
111 #define YYDEBUG 1 /* Default to yydebug support */
114 #define YYFPRINTF parser_fprintf
118 static int yylex (void);
120 void yyerror (char *);
124 /* Although the yacc "value" of an expression is not used,
125 since the result is stored in the structure being created,
126 other node types do have values. */
142 } typed_val_decfloat;
147 struct symtoken ssym;
150 enum exp_opcode opcode;
151 struct internalvar *ivar;
158 /* YYSTYPE gets defined by %union */
159 static int parse_number (char *, int, int, YYSTYPE *);
162 %type <voidval> exp exp1 type_exp start variable qualified_name lcurly
164 %type <tval> type typebase qualified_type
165 %type <tvec> nonempty_typelist
166 /* %type <bval> block */
168 /* Fancy type parsing. */
169 %type <voidval> func_mod direct_abs_decl abs_decl
171 %type <lval> array_mod
173 %token <typed_val_int> INT
174 %token <typed_val_float> FLOAT
175 %token <typed_val_decfloat> DECFLOAT
177 /* Both NAME and TYPENAME tokens represent symbols in the input,
178 and both convey their data as strings.
179 But a TYPENAME is a string that happens to be defined as a typedef
180 or builtin type name (such as int or char)
181 and a NAME is any other symbol.
182 Contexts where this distinction is not important can use the
183 nonterminal "name", which matches either NAME or TYPENAME. */
186 %token <ssym> NAME /* BLOCKNAME defined below to give it higher precedence. */
187 %token <voidval> COMPLETE
188 %token <tsym> TYPENAME
189 %type <sval> name string_exp
190 %type <ssym> name_not_typename
191 %type <tsym> typename
193 /* A NAME_OR_INT is a symbol which is not known in the symbol table,
194 but which would parse as a valid number in the current input radix.
195 E.g. "c" when input_radix==16. Depending on the parse, it will be
196 turned into a name or into a number. */
198 %token <ssym> NAME_OR_INT
200 %token STRUCT CLASS UNION ENUM SIZEOF UNSIGNED COLONCOLON
204 /* Special type cases, put in to allow the parser to distinguish different
206 %token SIGNED_KEYWORD LONG SHORT INT_KEYWORD CONST_KEYWORD VOLATILE_KEYWORD DOUBLE_KEYWORD
208 %token <voidval> VARIABLE
210 %token <opcode> ASSIGN_MODIFY
219 %right '=' ASSIGN_MODIFY
227 %left '<' '>' LEQ GEQ
232 %right UNARY INCREMENT DECREMENT
233 %right ARROW '.' '[' '('
234 %token <ssym> BLOCKNAME
235 %token <bval> FILENAME
247 { write_exp_elt_opcode(OP_TYPE);
248 write_exp_elt_type($1);
249 write_exp_elt_opcode(OP_TYPE);}
252 /* Expressions, including the comma operator. */
255 { write_exp_elt_opcode (BINOP_COMMA); }
258 /* Expressions, not including the comma operator. */
259 exp : '*' exp %prec UNARY
260 { write_exp_elt_opcode (UNOP_IND); }
263 exp : '&' exp %prec UNARY
264 { write_exp_elt_opcode (UNOP_ADDR); }
267 exp : '-' exp %prec UNARY
268 { write_exp_elt_opcode (UNOP_NEG); }
271 exp : '+' exp %prec UNARY
272 { write_exp_elt_opcode (UNOP_PLUS); }
275 exp : '!' exp %prec UNARY
276 { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
279 exp : '~' exp %prec UNARY
280 { write_exp_elt_opcode (UNOP_COMPLEMENT); }
283 exp : INCREMENT exp %prec UNARY
284 { write_exp_elt_opcode (UNOP_PREINCREMENT); }
287 exp : DECREMENT exp %prec UNARY
288 { write_exp_elt_opcode (UNOP_PREDECREMENT); }
291 exp : exp INCREMENT %prec UNARY
292 { write_exp_elt_opcode (UNOP_POSTINCREMENT); }
295 exp : exp DECREMENT %prec UNARY
296 { write_exp_elt_opcode (UNOP_POSTDECREMENT); }
299 exp : SIZEOF exp %prec UNARY
300 { write_exp_elt_opcode (UNOP_SIZEOF); }
304 { write_exp_elt_opcode (STRUCTOP_PTR);
305 write_exp_string ($3);
306 write_exp_elt_opcode (STRUCTOP_PTR); }
309 exp : exp ARROW name COMPLETE
310 { mark_struct_expression ();
311 write_exp_elt_opcode (STRUCTOP_PTR);
312 write_exp_string ($3);
313 write_exp_elt_opcode (STRUCTOP_PTR); }
316 exp : exp ARROW COMPLETE
318 mark_struct_expression ();
319 write_exp_elt_opcode (STRUCTOP_PTR);
322 write_exp_string (s);
323 write_exp_elt_opcode (STRUCTOP_PTR); }
326 exp : exp ARROW qualified_name
327 { /* exp->type::name becomes exp->*(&type::name) */
328 /* Note: this doesn't work if name is a
329 static member! FIXME */
330 write_exp_elt_opcode (UNOP_ADDR);
331 write_exp_elt_opcode (STRUCTOP_MPTR); }
334 exp : exp ARROW '*' exp
335 { write_exp_elt_opcode (STRUCTOP_MPTR); }
339 { write_exp_elt_opcode (STRUCTOP_STRUCT);
340 write_exp_string ($3);
341 write_exp_elt_opcode (STRUCTOP_STRUCT); }
344 exp : exp '.' name COMPLETE
345 { mark_struct_expression ();
346 write_exp_elt_opcode (STRUCTOP_STRUCT);
347 write_exp_string ($3);
348 write_exp_elt_opcode (STRUCTOP_STRUCT); }
351 exp : exp '.' COMPLETE
353 mark_struct_expression ();
354 write_exp_elt_opcode (STRUCTOP_STRUCT);
357 write_exp_string (s);
358 write_exp_elt_opcode (STRUCTOP_STRUCT); }
361 exp : exp '.' qualified_name
362 { /* exp.type::name becomes exp.*(&type::name) */
363 /* Note: this doesn't work if name is a
364 static member! FIXME */
365 write_exp_elt_opcode (UNOP_ADDR);
366 write_exp_elt_opcode (STRUCTOP_MEMBER); }
369 exp : exp '.' '*' exp
370 { write_exp_elt_opcode (STRUCTOP_MEMBER); }
373 exp : exp '[' exp1 ']'
374 { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
378 /* This is to save the value of arglist_len
379 being accumulated by an outer function call. */
380 { start_arglist (); }
381 arglist ')' %prec ARROW
382 { write_exp_elt_opcode (OP_FUNCALL);
383 write_exp_elt_longcst ((LONGEST) end_arglist ());
384 write_exp_elt_opcode (OP_FUNCALL); }
388 { start_arglist (); }
398 arglist : arglist ',' exp %prec ABOVE_COMMA
403 { $$ = end_arglist () - 1; }
405 exp : lcurly arglist rcurly %prec ARROW
406 { write_exp_elt_opcode (OP_ARRAY);
407 write_exp_elt_longcst ((LONGEST) 0);
408 write_exp_elt_longcst ((LONGEST) $3);
409 write_exp_elt_opcode (OP_ARRAY); }
412 exp : lcurly type rcurly exp %prec UNARY
413 { write_exp_elt_opcode (UNOP_MEMVAL);
414 write_exp_elt_type ($2);
415 write_exp_elt_opcode (UNOP_MEMVAL); }
418 exp : '(' type ')' exp %prec UNARY
419 { write_exp_elt_opcode (UNOP_CAST);
420 write_exp_elt_type ($2);
421 write_exp_elt_opcode (UNOP_CAST); }
428 /* Binary operators in order of decreasing precedence. */
431 { write_exp_elt_opcode (BINOP_REPEAT); }
435 { write_exp_elt_opcode (BINOP_MUL); }
439 { write_exp_elt_opcode (BINOP_DIV); }
443 { write_exp_elt_opcode (BINOP_REM); }
447 { write_exp_elt_opcode (BINOP_ADD); }
451 { write_exp_elt_opcode (BINOP_SUB); }
455 { write_exp_elt_opcode (BINOP_LSH); }
459 { write_exp_elt_opcode (BINOP_RSH); }
463 { write_exp_elt_opcode (BINOP_EQUAL); }
466 exp : exp NOTEQUAL exp
467 { write_exp_elt_opcode (BINOP_NOTEQUAL); }
471 { write_exp_elt_opcode (BINOP_LEQ); }
475 { write_exp_elt_opcode (BINOP_GEQ); }
479 { write_exp_elt_opcode (BINOP_LESS); }
483 { write_exp_elt_opcode (BINOP_GTR); }
487 { write_exp_elt_opcode (BINOP_BITWISE_AND); }
491 { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
495 { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
499 { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
503 { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
506 exp : exp '?' exp ':' exp %prec '?'
507 { write_exp_elt_opcode (TERNOP_COND); }
511 { write_exp_elt_opcode (BINOP_ASSIGN); }
514 exp : exp ASSIGN_MODIFY exp
515 { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY);
516 write_exp_elt_opcode ($2);
517 write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); }
521 { write_exp_elt_opcode (OP_LONG);
522 write_exp_elt_type ($1.type);
523 write_exp_elt_longcst ((LONGEST)($1.val));
524 write_exp_elt_opcode (OP_LONG); }
529 parse_number ($1.stoken.ptr, $1.stoken.length, 0, &val);
530 write_exp_elt_opcode (OP_LONG);
531 write_exp_elt_type (val.typed_val_int.type);
532 write_exp_elt_longcst ((LONGEST)val.typed_val_int.val);
533 write_exp_elt_opcode (OP_LONG);
539 { write_exp_elt_opcode (OP_DOUBLE);
540 write_exp_elt_type ($1.type);
541 write_exp_elt_dblcst ($1.dval);
542 write_exp_elt_opcode (OP_DOUBLE); }
546 { write_exp_elt_opcode (OP_DECFLOAT);
547 write_exp_elt_type ($1.type);
548 write_exp_elt_decfloatcst ($1.val);
549 write_exp_elt_opcode (OP_DECFLOAT); }
556 /* Already written by write_dollar_variable. */
559 exp : SIZEOF '(' type ')' %prec UNARY
560 { write_exp_elt_opcode (OP_LONG);
561 write_exp_elt_type (parse_type->builtin_int);
563 write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
564 write_exp_elt_opcode (OP_LONG); }
570 /* We copy the string here, and not in the
571 lexer, to guarantee that we do not leak a
572 string. Note that we follow the
573 NUL-termination convention of the
575 $$.length = $1.length;
576 $$.ptr = malloc ($1.length + 1);
577 memcpy ($$.ptr, $1.ptr, $1.length + 1);
582 /* Note that we NUL-terminate here, but just
585 t.length = $1.length + $2.length;
586 t.ptr = malloc (t.length + 1);
587 memcpy (t.ptr, $1.ptr, $1.length);
588 memcpy (t.ptr + $1.length, $2.ptr, $2.length + 1);
595 { /* C strings are converted into array constants with
596 an explicit null byte added at the end. Thus
597 the array upper bound is the string length.
598 There is no such thing in C as a completely empty
600 char *sp = $1.ptr; int count = $1.length;
603 write_exp_elt_opcode (OP_LONG);
604 write_exp_elt_type (parse_type->builtin_char);
605 write_exp_elt_longcst ((LONGEST)(*sp++));
606 write_exp_elt_opcode (OP_LONG);
608 write_exp_elt_opcode (OP_LONG);
609 write_exp_elt_type (parse_type->builtin_char);
610 write_exp_elt_longcst ((LONGEST)'\0');
611 write_exp_elt_opcode (OP_LONG);
612 write_exp_elt_opcode (OP_ARRAY);
613 write_exp_elt_longcst ((LONGEST) 0);
614 write_exp_elt_longcst ((LONGEST) ($1.length));
615 write_exp_elt_opcode (OP_ARRAY);
622 { write_exp_elt_opcode (OP_LONG);
623 write_exp_elt_type (parse_type->builtin_bool);
624 write_exp_elt_longcst ((LONGEST) 1);
625 write_exp_elt_opcode (OP_LONG); }
629 { write_exp_elt_opcode (OP_LONG);
630 write_exp_elt_type (parse_type->builtin_bool);
631 write_exp_elt_longcst ((LONGEST) 0);
632 write_exp_elt_opcode (OP_LONG); }
640 $$ = SYMBOL_BLOCK_VALUE ($1.sym);
642 error ("No file or function \"%s\".",
643 copy_name ($1.stoken));
651 block : block COLONCOLON name
653 = lookup_symbol (copy_name ($3), $1,
654 VAR_DOMAIN, (int *) NULL);
655 if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
656 error ("No function \"%s\" in specified context.",
658 $$ = SYMBOL_BLOCK_VALUE (tem); }
661 variable: block COLONCOLON name
662 { struct symbol *sym;
663 sym = lookup_symbol (copy_name ($3), $1,
664 VAR_DOMAIN, (int *) NULL);
666 error ("No symbol \"%s\" in specified context.",
669 write_exp_elt_opcode (OP_VAR_VALUE);
670 /* block_found is set by lookup_symbol. */
671 write_exp_elt_block (block_found);
672 write_exp_elt_sym (sym);
673 write_exp_elt_opcode (OP_VAR_VALUE); }
676 qualified_name: typebase COLONCOLON name
678 struct type *type = $1;
679 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
680 && TYPE_CODE (type) != TYPE_CODE_UNION
681 && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
682 error ("`%s' is not defined as an aggregate type.",
685 write_exp_elt_opcode (OP_SCOPE);
686 write_exp_elt_type (type);
687 write_exp_string ($3);
688 write_exp_elt_opcode (OP_SCOPE);
690 | typebase COLONCOLON '~' name
692 struct type *type = $1;
693 struct stoken tmp_token;
694 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
695 && TYPE_CODE (type) != TYPE_CODE_UNION
696 && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
697 error ("`%s' is not defined as an aggregate type.",
700 tmp_token.ptr = (char*) alloca ($4.length + 2);
701 tmp_token.length = $4.length + 1;
702 tmp_token.ptr[0] = '~';
703 memcpy (tmp_token.ptr+1, $4.ptr, $4.length);
704 tmp_token.ptr[tmp_token.length] = 0;
706 /* Check for valid destructor name. */
707 destructor_name_p (tmp_token.ptr, type);
708 write_exp_elt_opcode (OP_SCOPE);
709 write_exp_elt_type (type);
710 write_exp_string (tmp_token);
711 write_exp_elt_opcode (OP_SCOPE);
715 variable: qualified_name
718 char *name = copy_name ($2);
720 struct minimal_symbol *msymbol;
723 lookup_symbol (name, (const struct block *) NULL,
724 VAR_DOMAIN, (int *) NULL);
727 write_exp_elt_opcode (OP_VAR_VALUE);
728 write_exp_elt_block (NULL);
729 write_exp_elt_sym (sym);
730 write_exp_elt_opcode (OP_VAR_VALUE);
734 msymbol = lookup_minimal_symbol (name, NULL, NULL);
736 write_exp_msymbol (msymbol);
737 else if (!have_full_symbols () && !have_partial_symbols ())
738 error ("No symbol table is loaded. Use the \"file\" command.");
740 error ("No symbol \"%s\" in current context.", name);
744 variable: name_not_typename
745 { struct symbol *sym = $1.sym;
749 if (symbol_read_needs_frame (sym))
751 if (innermost_block == 0 ||
752 contained_in (block_found,
754 innermost_block = block_found;
757 write_exp_elt_opcode (OP_VAR_VALUE);
758 /* We want to use the selected frame, not
759 another more inner frame which happens to
760 be in the same block. */
761 write_exp_elt_block (NULL);
762 write_exp_elt_sym (sym);
763 write_exp_elt_opcode (OP_VAR_VALUE);
765 else if ($1.is_a_field_of_this)
767 /* C++: it hangs off of `this'. Must
768 not inadvertently convert from a method call
770 if (innermost_block == 0 ||
771 contained_in (block_found, innermost_block))
772 innermost_block = block_found;
773 write_exp_elt_opcode (OP_THIS);
774 write_exp_elt_opcode (OP_THIS);
775 write_exp_elt_opcode (STRUCTOP_PTR);
776 write_exp_string ($1.stoken);
777 write_exp_elt_opcode (STRUCTOP_PTR);
781 struct minimal_symbol *msymbol;
782 char *arg = copy_name ($1.stoken);
785 lookup_minimal_symbol (arg, NULL, NULL);
787 write_exp_msymbol (msymbol);
788 else if (!have_full_symbols () && !have_partial_symbols ())
789 error ("No symbol table is loaded. Use the \"file\" command.");
791 error ("No symbol \"%s\" in current context.",
792 copy_name ($1.stoken));
797 space_identifier : '@' NAME
798 { push_type_address_space (copy_name ($2.stoken));
799 push_type (tp_space_identifier);
803 const_or_volatile: const_or_volatile_noopt
807 cv_with_space_id : const_or_volatile space_identifier const_or_volatile
810 const_or_volatile_or_space_identifier_noopt: cv_with_space_id
811 | const_or_volatile_noopt
814 const_or_volatile_or_space_identifier:
815 const_or_volatile_or_space_identifier_noopt
820 { push_type (tp_pointer); $$ = 0; }
822 { push_type (tp_pointer); $$ = $2; }
824 { push_type (tp_reference); $$ = 0; }
826 { push_type (tp_reference); $$ = $2; }
830 direct_abs_decl: '(' abs_decl ')'
832 | direct_abs_decl array_mod
835 push_type (tp_array);
840 push_type (tp_array);
844 | direct_abs_decl func_mod
845 { push_type (tp_function); }
847 { push_type (tp_function); }
858 | '(' nonempty_typelist ')'
859 { free ($2); $$ = 0; }
862 /* We used to try to recognize pointer to member types here, but
863 that didn't work (shift/reduce conflicts meant that these rules never
864 got executed). The problem is that
865 int (foo::bar::baz::bizzle)
866 is a function type but
867 int (foo::bar::baz::bizzle::*)
868 is a pointer to member type. Stroustrup loses again! */
873 typebase /* Implements (approximately): (type-qualifier)* type-specifier */
877 { $$ = parse_type->builtin_int; }
879 { $$ = parse_type->builtin_long; }
881 { $$ = parse_type->builtin_short; }
883 { $$ = parse_type->builtin_long; }
884 | LONG SIGNED_KEYWORD INT_KEYWORD
885 { $$ = parse_type->builtin_long; }
886 | LONG SIGNED_KEYWORD
887 { $$ = parse_type->builtin_long; }
888 | SIGNED_KEYWORD LONG INT_KEYWORD
889 { $$ = parse_type->builtin_long; }
890 | UNSIGNED LONG INT_KEYWORD
891 { $$ = parse_type->builtin_unsigned_long; }
892 | LONG UNSIGNED INT_KEYWORD
893 { $$ = parse_type->builtin_unsigned_long; }
895 { $$ = parse_type->builtin_unsigned_long; }
897 { $$ = parse_type->builtin_long_long; }
898 | LONG LONG INT_KEYWORD
899 { $$ = parse_type->builtin_long_long; }
900 | LONG LONG SIGNED_KEYWORD INT_KEYWORD
901 { $$ = parse_type->builtin_long_long; }
902 | LONG LONG SIGNED_KEYWORD
903 { $$ = parse_type->builtin_long_long; }
904 | SIGNED_KEYWORD LONG LONG
905 { $$ = parse_type->builtin_long_long; }
906 | SIGNED_KEYWORD LONG LONG INT_KEYWORD
907 { $$ = parse_type->builtin_long_long; }
909 { $$ = parse_type->builtin_unsigned_long_long; }
910 | UNSIGNED LONG LONG INT_KEYWORD
911 { $$ = parse_type->builtin_unsigned_long_long; }
913 { $$ = parse_type->builtin_unsigned_long_long; }
914 | LONG LONG UNSIGNED INT_KEYWORD
915 { $$ = parse_type->builtin_unsigned_long_long; }
917 { $$ = parse_type->builtin_short; }
918 | SHORT SIGNED_KEYWORD INT_KEYWORD
919 { $$ = parse_type->builtin_short; }
920 | SHORT SIGNED_KEYWORD
921 { $$ = parse_type->builtin_short; }
922 | UNSIGNED SHORT INT_KEYWORD
923 { $$ = parse_type->builtin_unsigned_short; }
925 { $$ = parse_type->builtin_unsigned_short; }
926 | SHORT UNSIGNED INT_KEYWORD
927 { $$ = parse_type->builtin_unsigned_short; }
929 { $$ = parse_type->builtin_double; }
930 | LONG DOUBLE_KEYWORD
931 { $$ = parse_type->builtin_long_double; }
933 { $$ = lookup_struct (copy_name ($2),
934 expression_context_block); }
936 { $$ = lookup_struct (copy_name ($2),
937 expression_context_block); }
939 { $$ = lookup_union (copy_name ($2),
940 expression_context_block); }
942 { $$ = lookup_enum (copy_name ($2),
943 expression_context_block); }
945 { $$ = lookup_unsigned_typename (TYPE_NAME($2.type)); }
947 { $$ = parse_type->builtin_unsigned_int; }
948 | SIGNED_KEYWORD typename
949 { $$ = lookup_signed_typename (TYPE_NAME($2.type)); }
951 { $$ = parse_type->builtin_int; }
952 /* It appears that this rule for templates is never
953 reduced; template recognition happens by lookahead
954 in the token processing code in yylex. */
955 | TEMPLATE name '<' type '>'
956 { $$ = lookup_template_type(copy_name($2), $4,
957 expression_context_block);
959 | const_or_volatile_or_space_identifier_noopt typebase
960 { $$ = follow_types ($2); }
961 | typebase const_or_volatile_or_space_identifier_noopt
962 { $$ = follow_types ($1); }
966 /* FIXME: carlton/2003-09-25: This next bit leads to lots of
967 reduce-reduce conflicts, because the parser doesn't know whether or
968 not to use qualified_name or qualified_type: the rules are
969 identical. If the parser is parsing 'A::B::x', then, when it sees
970 the second '::', it knows that the expression to the left of it has
971 to be a type, so it uses qualified_type. But if it is parsing just
972 'A::B', then it doesn't have any way of knowing which rule to use,
973 so there's a reduce-reduce conflict; it picks qualified_name, since
974 that occurs earlier in this file than qualified_type.
976 There's no good way to fix this with the grammar as it stands; as
977 far as I can tell, some of the problems arise from ambiguities that
978 GDB introduces ('start' can be either an expression or a type), but
979 some of it is inherent to the nature of C++ (you want to treat the
980 input "(FOO)" fairly differently depending on whether FOO is an
981 expression or a type, and if FOO is a complex expression, this can
982 be hard to determine at the right time). Fortunately, it works
983 pretty well in most cases. For example, if you do 'ptype A::B',
984 where A::B is a nested type, then the parser will mistakenly
985 misidentify it as an expression; but evaluate_subexp will get
986 called with 'noside' set to EVAL_AVOID_SIDE_EFFECTS, and everything
987 will work out anyways. But there are situations where the parser
988 will get confused: the most common one that I've run into is when
993 where the parser doesn't realize that A::B has to be a type until
994 it hits the first right paren, at which point it's too late. (The
995 workaround is to type "print *(('A::B' *) x)" instead.) (And
996 another solution is to fix our symbol-handling code so that the
997 user never wants to type something like that in the first place,
998 because we get all the types right without the user's help!)
1000 Perhaps we could fix this by making the lexer smarter. Some of
1001 this functionality used to be in the lexer, but in a way that
1002 worked even less well than the current solution: that attempt
1003 involved having the parser sometimes handle '::' and having the
1004 lexer sometimes handle it, and without a clear division of
1005 responsibility, it quickly degenerated into a big mess. Probably
1006 the eventual correct solution will give more of a role to the lexer
1007 (ideally via code that is shared between the lexer and
1008 decode_line_1), but I'm not holding my breath waiting for somebody
1009 to get around to cleaning this up... */
1011 qualified_type: typebase COLONCOLON name
1013 struct type *type = $1;
1014 struct type *new_type;
1015 char *ncopy = alloca ($3.length + 1);
1017 memcpy (ncopy, $3.ptr, $3.length);
1018 ncopy[$3.length] = '\0';
1020 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
1021 && TYPE_CODE (type) != TYPE_CODE_UNION
1022 && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
1023 error ("`%s' is not defined as an aggregate type.",
1026 new_type = cp_lookup_nested_type (type, ncopy,
1027 expression_context_block);
1028 if (new_type == NULL)
1029 error ("No type \"%s\" within class or namespace \"%s\".",
1030 ncopy, TYPE_NAME (type));
1039 $$.stoken.ptr = "int";
1040 $$.stoken.length = 3;
1041 $$.type = parse_type->builtin_int;
1045 $$.stoken.ptr = "long";
1046 $$.stoken.length = 4;
1047 $$.type = parse_type->builtin_long;
1051 $$.stoken.ptr = "short";
1052 $$.stoken.length = 5;
1053 $$.type = parse_type->builtin_short;
1059 { $$ = (struct type **) malloc (sizeof (struct type *) * 2);
1060 $<ivec>$[0] = 1; /* Number of types in vector */
1063 | nonempty_typelist ',' type
1064 { int len = sizeof (struct type *) * (++($<ivec>1[0]) + 1);
1065 $$ = (struct type **) realloc ((char *) $1, len);
1066 $$[$<ivec>$[0]] = $3;
1071 | ptype const_or_volatile_or_space_identifier abs_decl const_or_volatile_or_space_identifier
1072 { $$ = follow_types ($1); }
1075 const_and_volatile: CONST_KEYWORD VOLATILE_KEYWORD
1076 | VOLATILE_KEYWORD CONST_KEYWORD
1079 const_or_volatile_noopt: const_and_volatile
1080 { push_type (tp_const);
1081 push_type (tp_volatile);
1084 { push_type (tp_const); }
1086 { push_type (tp_volatile); }
1089 name : NAME { $$ = $1.stoken; }
1090 | BLOCKNAME { $$ = $1.stoken; }
1091 | TYPENAME { $$ = $1.stoken; }
1092 | NAME_OR_INT { $$ = $1.stoken; }
1095 name_not_typename : NAME
1097 /* These would be useful if name_not_typename was useful, but it is just
1098 a fake for "variable", so these cause reduce/reduce conflicts because
1099 the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable,
1100 =exp) or just an exp. If name_not_typename was ever used in an lvalue
1101 context where only a name could occur, this might be useful.
1108 /* Take care of parsing a number (anything that starts with a digit).
1109 Set yylval and return the token type; update lexptr.
1110 LEN is the number of characters in it. */
1112 /*** Needs some error checking for the float case ***/
1115 parse_number (p, len, parsed_float, putithere)
1121 /* FIXME: Shouldn't these be unsigned? We don't deal with negative values
1122 here, and we do kind of silly things like cast to unsigned. */
1129 int base = input_radix;
1132 /* Number of "L" suffixes encountered. */
1135 /* We have found a "L" or "U" suffix. */
1136 int found_suffix = 0;
1139 struct type *signed_type;
1140 struct type *unsigned_type;
1144 /* It's a float since it contains a point or an exponent. */
1146 int num; /* number of tokens scanned by scanf */
1149 /* If it ends at "df", "dd" or "dl", take it as type of decimal floating
1150 point. Return DECFLOAT. */
1152 if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'f')
1155 putithere->typed_val_decfloat.type
1156 = parse_type->builtin_decfloat;
1157 decimal_from_string (putithere->typed_val_decfloat.val, 4, p);
1162 if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'd')
1165 putithere->typed_val_decfloat.type
1166 = parse_type->builtin_decdouble;
1167 decimal_from_string (putithere->typed_val_decfloat.val, 8, p);
1172 if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'l')
1175 putithere->typed_val_decfloat.type
1176 = parse_type->builtin_declong;
1177 decimal_from_string (putithere->typed_val_decfloat.val, 16, p);
1183 saved_char = p[len];
1184 p[len] = 0; /* null-terminate the token */
1185 num = sscanf (p, "%" DOUBLEST_SCAN_FORMAT "%s",
1186 &putithere->typed_val_float.dval, s);
1187 p[len] = saved_char; /* restore the input stream */
1190 putithere->typed_val_float.type =
1191 parse_type->builtin_double;
1195 /* See if it has any float suffix: 'f' for float, 'l' for long
1197 if (!strcasecmp (s, "f"))
1198 putithere->typed_val_float.type =
1199 parse_type->builtin_float;
1200 else if (!strcasecmp (s, "l"))
1201 putithere->typed_val_float.type =
1202 parse_type->builtin_long_double;
1214 /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
1248 if (c >= 'A' && c <= 'Z')
1250 if (c != 'l' && c != 'u')
1252 if (c >= '0' && c <= '9')
1260 if (base > 10 && c >= 'a' && c <= 'f')
1264 n += i = c - 'a' + 10;
1277 return ERROR; /* Char not a digit */
1280 return ERROR; /* Invalid digit in this base */
1282 /* Portably test for overflow (only works for nonzero values, so make
1283 a second check for zero). FIXME: Can't we just make n and prevn
1284 unsigned and avoid this? */
1285 if (c != 'l' && c != 'u' && (prevn >= n) && n != 0)
1286 unsigned_p = 1; /* Try something unsigned */
1288 /* Portably test for unsigned overflow.
1289 FIXME: This check is wrong; for example it doesn't find overflow
1290 on 0x123456789 when LONGEST is 32 bits. */
1291 if (c != 'l' && c != 'u' && n != 0)
1293 if ((unsigned_p && (ULONGEST) prevn >= (ULONGEST) n))
1294 error ("Numeric constant too large.");
1299 /* An integer constant is an int, a long, or a long long. An L
1300 suffix forces it to be long; an LL suffix forces it to be long
1301 long. If not forced to a larger size, it gets the first type of
1302 the above that it fits in. To figure out whether it fits, we
1303 shift it right and see whether anything remains. Note that we
1304 can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one
1305 operation, because many compilers will warn about such a shift
1306 (which always produces a zero result). Sometimes gdbarch_int_bit
1307 or gdbarch_long_bit will be that big, sometimes not. To deal with
1308 the case where it is we just always shift the value more than
1309 once, with fewer bits each time. */
1311 un = (ULONGEST)n >> 2;
1313 && (un >> (gdbarch_int_bit (parse_gdbarch) - 2)) == 0)
1315 high_bit = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch) - 1);
1317 /* A large decimal (not hex or octal) constant (between INT_MAX
1318 and UINT_MAX) is a long or unsigned long, according to ANSI,
1319 never an unsigned int, but this code treats it as unsigned
1320 int. This probably should be fixed. GCC gives a warning on
1323 unsigned_type = parse_type->builtin_unsigned_int;
1324 signed_type = parse_type->builtin_int;
1326 else if (long_p <= 1
1327 && (un >> (gdbarch_long_bit (parse_gdbarch) - 2)) == 0)
1329 high_bit = ((ULONGEST)1) << (gdbarch_long_bit (parse_gdbarch) - 1);
1330 unsigned_type = parse_type->builtin_unsigned_long;
1331 signed_type = parse_type->builtin_long;
1336 if (sizeof (ULONGEST) * HOST_CHAR_BIT
1337 < gdbarch_long_long_bit (parse_gdbarch))
1338 /* A long long does not fit in a LONGEST. */
1339 shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1);
1341 shift = (gdbarch_long_long_bit (parse_gdbarch) - 1);
1342 high_bit = (ULONGEST) 1 << shift;
1343 unsigned_type = parse_type->builtin_unsigned_long_long;
1344 signed_type = parse_type->builtin_long_long;
1347 putithere->typed_val_int.val = n;
1349 /* If the high bit of the worked out type is set then this number
1350 has to be unsigned. */
1352 if (unsigned_p || (n & high_bit))
1354 putithere->typed_val_int.type = unsigned_type;
1358 putithere->typed_val_int.type = signed_type;
1368 enum exp_opcode opcode;
1372 static const struct token tokentab3[] =
1374 {">>=", ASSIGN_MODIFY, BINOP_RSH, 0},
1375 {"<<=", ASSIGN_MODIFY, BINOP_LSH, 0}
1378 static const struct token tokentab2[] =
1380 {"+=", ASSIGN_MODIFY, BINOP_ADD, 0},
1381 {"-=", ASSIGN_MODIFY, BINOP_SUB, 0},
1382 {"*=", ASSIGN_MODIFY, BINOP_MUL, 0},
1383 {"/=", ASSIGN_MODIFY, BINOP_DIV, 0},
1384 {"%=", ASSIGN_MODIFY, BINOP_REM, 0},
1385 {"|=", ASSIGN_MODIFY, BINOP_BITWISE_IOR, 0},
1386 {"&=", ASSIGN_MODIFY, BINOP_BITWISE_AND, 0},
1387 {"^=", ASSIGN_MODIFY, BINOP_BITWISE_XOR, 0},
1388 {"++", INCREMENT, BINOP_END, 0},
1389 {"--", DECREMENT, BINOP_END, 0},
1390 {"->", ARROW, BINOP_END, 0},
1391 {"&&", ANDAND, BINOP_END, 0},
1392 {"||", OROR, BINOP_END, 0},
1393 {"::", COLONCOLON, BINOP_END, 0},
1394 {"<<", LSH, BINOP_END, 0},
1395 {">>", RSH, BINOP_END, 0},
1396 {"==", EQUAL, BINOP_END, 0},
1397 {"!=", NOTEQUAL, BINOP_END, 0},
1398 {"<=", LEQ, BINOP_END, 0},
1399 {">=", GEQ, BINOP_END, 0}
1402 /* Identifier-like tokens. */
1403 static const struct token ident_tokens[] =
1405 {"unsigned", UNSIGNED, OP_NULL, 0},
1406 {"template", TEMPLATE, OP_NULL, 1},
1407 {"volatile", VOLATILE_KEYWORD, OP_NULL, 0},
1408 {"struct", STRUCT, OP_NULL, 0},
1409 {"signed", SIGNED_KEYWORD, OP_NULL, 0},
1410 {"sizeof", SIZEOF, OP_NULL, 0},
1411 {"double", DOUBLE_KEYWORD, OP_NULL, 0},
1412 {"false", FALSEKEYWORD, OP_NULL, 1},
1413 {"class", CLASS, OP_NULL, 1},
1414 {"union", UNION, OP_NULL, 0},
1415 {"short", SHORT, OP_NULL, 0},
1416 {"const", CONST_KEYWORD, OP_NULL, 0},
1417 {"enum", ENUM, OP_NULL, 0},
1418 {"long", LONG, OP_NULL, 0},
1419 {"true", TRUEKEYWORD, OP_NULL, 1},
1420 {"int", INT_KEYWORD, OP_NULL, 0},
1422 {"and", ANDAND, BINOP_END, 1},
1423 {"and_eq", ASSIGN_MODIFY, BINOP_BITWISE_AND, 1},
1424 {"bitand", '&', OP_NULL, 1},
1425 {"bitor", '|', OP_NULL, 1},
1426 {"compl", '~', OP_NULL, 1},
1427 {"not", '!', OP_NULL, 1},
1428 {"not_eq", NOTEQUAL, BINOP_END, 1},
1429 {"or", OROR, BINOP_END, 1},
1430 {"or_eq", ASSIGN_MODIFY, BINOP_BITWISE_IOR, 1},
1431 {"xor", '^', OP_NULL, 1},
1432 {"xor_eq", ASSIGN_MODIFY, BINOP_BITWISE_XOR, 1}
1435 /* When we find that lexptr (the global var defined in parse.c) is
1436 pointing at a macro invocation, we expand the invocation, and call
1437 scan_macro_expansion to save the old lexptr here and point lexptr
1438 into the expanded text. When we reach the end of that, we call
1439 end_macro_expansion to pop back to the value we saved here. The
1440 macro expansion code promises to return only fully-expanded text,
1441 so we don't need to "push" more than one level.
1443 This is disgusting, of course. It would be cleaner to do all macro
1444 expansion beforehand, and then hand that to lexptr. But we don't
1445 really know where the expression ends. Remember, in a command like
1447 (gdb) break *ADDRESS if CONDITION
1449 we evaluate ADDRESS in the scope of the current frame, but we
1450 evaluate CONDITION in the scope of the breakpoint's location. So
1451 it's simply wrong to try to macro-expand the whole thing at once. */
1452 static char *macro_original_text;
1454 /* We save all intermediate macro expansions on this obstack for the
1455 duration of a single parse. The expansion text may sometimes have
1456 to live past the end of the expansion, due to yacc lookahead.
1457 Rather than try to be clever about saving the data for a single
1458 token, we simply keep it all and delete it after parsing has
1460 static struct obstack expansion_obstack;
1463 scan_macro_expansion (char *expansion)
1467 /* We'd better not be trying to push the stack twice. */
1468 gdb_assert (! macro_original_text);
1470 /* Copy to the obstack, and then free the intermediate
1472 copy = obstack_copy0 (&expansion_obstack, expansion, strlen (expansion));
1475 /* Save the old lexptr value, so we can return to it when we're done
1476 parsing the expanded text. */
1477 macro_original_text = lexptr;
1483 scanning_macro_expansion (void)
1485 return macro_original_text != 0;
1490 finished_macro_expansion (void)
1492 /* There'd better be something to pop back to. */
1493 gdb_assert (macro_original_text);
1495 /* Pop back to the original text. */
1496 lexptr = macro_original_text;
1497 macro_original_text = 0;
1502 scan_macro_cleanup (void *dummy)
1504 if (macro_original_text)
1505 finished_macro_expansion ();
1507 obstack_free (&expansion_obstack, NULL);
1511 /* The scope used for macro expansion. */
1512 static struct macro_scope *expression_macro_scope;
1514 /* This is set if a NAME token appeared at the very end of the input
1515 string, with no whitespace separating the name from the EOF. This
1516 is used only when parsing to do field name completion. */
1517 static int saw_name_at_eof;
1519 /* This is set if the previously-returned token was a structure
1520 operator -- either '.' or ARROW. This is used only when parsing to
1521 do field name completion. */
1522 static int last_was_structop;
1524 /* Read one token, getting characters through lexptr. */
1535 static char *tempbuf;
1536 static int tempbufsize;
1537 char * token_string = NULL;
1538 int class_prefix = 0;
1539 int saw_structop = last_was_structop;
1542 last_was_structop = 0;
1546 /* Check if this is a macro invocation that we need to expand. */
1547 if (! scanning_macro_expansion ())
1549 char *expanded = macro_expand_next (&lexptr,
1550 standard_macro_lookup,
1551 expression_macro_scope);
1554 scan_macro_expansion (expanded);
1557 prev_lexptr = lexptr;
1560 /* See if it is a special token of length 3. */
1561 for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++)
1562 if (strncmp (tokstart, tokentab3[i].operator, 3) == 0)
1565 yylval.opcode = tokentab3[i].opcode;
1566 return tokentab3[i].token;
1569 /* See if it is a special token of length 2. */
1570 for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++)
1571 if (strncmp (tokstart, tokentab2[i].operator, 2) == 0)
1574 yylval.opcode = tokentab2[i].opcode;
1575 if (in_parse_field && tokentab2[i].token == ARROW)
1576 last_was_structop = 1;
1577 return tokentab2[i].token;
1580 switch (c = *tokstart)
1583 /* If we were just scanning the result of a macro expansion,
1584 then we need to resume scanning the original text.
1585 If we're parsing for field name completion, and the previous
1586 token allows such completion, return a COMPLETE token.
1587 Otherwise, we were already scanning the original text, and
1588 we're really done. */
1589 if (scanning_macro_expansion ())
1591 finished_macro_expansion ();
1594 else if (saw_name_at_eof)
1596 saw_name_at_eof = 0;
1599 else if (saw_structop)
1611 /* We either have a character constant ('0' or '\177' for example)
1612 or we have a quoted symbol reference ('foo(int,int)' in C++
1617 c = parse_escape (&lexptr);
1619 error ("Empty character constant.");
1620 else if (! host_char_to_target (c, &c))
1622 int toklen = lexptr - tokstart + 1;
1623 char *tok = alloca (toklen + 1);
1624 memcpy (tok, tokstart, toklen);
1626 error ("There is no character corresponding to %s in the target "
1627 "character set `%s'.", tok, target_charset ());
1630 yylval.typed_val_int.val = c;
1631 yylval.typed_val_int.type = parse_type->builtin_char;
1636 namelen = skip_quoted (tokstart) - tokstart;
1639 lexptr = tokstart + namelen;
1640 if (lexptr[-1] != '\'')
1641 error ("Unmatched single quote.");
1646 error ("Invalid character constant.");
1656 if (paren_depth == 0)
1663 if (comma_terminates
1665 && ! scanning_macro_expansion ())
1671 /* Might be a floating point number. */
1672 if (lexptr[1] < '0' || lexptr[1] > '9')
1675 last_was_structop = 1;
1676 goto symbol; /* Nope, must be a symbol. */
1678 /* FALL THRU into number case. */
1691 /* It's a number. */
1692 int got_dot = 0, got_e = 0, toktype;
1694 int hex = input_radix > 10;
1696 if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
1701 else if (c == '0' && (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))
1709 /* This test includes !hex because 'e' is a valid hex digit
1710 and thus does not indicate a floating point number when
1711 the radix is hex. */
1712 if (!hex && !got_e && (*p == 'e' || *p == 'E'))
1713 got_dot = got_e = 1;
1714 /* This test does not include !hex, because a '.' always indicates
1715 a decimal floating point number regardless of the radix. */
1716 else if (!got_dot && *p == '.')
1718 else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
1719 && (*p == '-' || *p == '+'))
1720 /* This is the sign of the exponent, not the end of the
1723 /* We will take any letters or digits. parse_number will
1724 complain if past the radix, or if L or U are not final. */
1725 else if ((*p < '0' || *p > '9')
1726 && ((*p < 'a' || *p > 'z')
1727 && (*p < 'A' || *p > 'Z')))
1730 toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval);
1731 if (toktype == ERROR)
1733 char *err_copy = (char *) alloca (p - tokstart + 1);
1735 memcpy (err_copy, tokstart, p - tokstart);
1736 err_copy[p - tokstart] = 0;
1737 error ("Invalid number \"%s\".", err_copy);
1769 /* Build the gdb internal form of the input string in tempbuf,
1770 translating any standard C escape forms seen. Note that the
1771 buffer is null byte terminated *only* for the convenience of
1772 debugging gdb itself and printing the buffer contents when
1773 the buffer contains no embedded nulls. Gdb does not depend
1774 upon the buffer being null byte terminated, it uses the length
1775 string instead. This allows gdb to handle C strings (as well
1776 as strings in other languages) with embedded null bytes */
1778 tokptr = ++tokstart;
1782 char *char_start_pos = tokptr;
1784 /* Grow the static temp buffer if necessary, including allocating
1785 the first one on demand. */
1786 if (tempbufindex + 1 >= tempbufsize)
1788 tempbuf = (char *) realloc (tempbuf, tempbufsize += 64);
1794 /* Do nothing, loop will terminate. */
1798 c = parse_escape (&tokptr);
1803 tempbuf[tempbufindex++] = c;
1807 if (! host_char_to_target (c, &c))
1809 int len = tokptr - char_start_pos;
1810 char *copy = alloca (len + 1);
1811 memcpy (copy, char_start_pos, len);
1814 error ("There is no character corresponding to `%s' "
1815 "in the target character set `%s'.",
1816 copy, target_charset ());
1818 tempbuf[tempbufindex++] = c;
1821 } while ((*tokptr != '"') && (*tokptr != '\0'));
1822 if (*tokptr++ != '"')
1824 error ("Unterminated string in expression.");
1826 tempbuf[tempbufindex] = '\0'; /* See note above */
1827 yylval.sval.ptr = tempbuf;
1828 yylval.sval.length = tempbufindex;
1833 if (!(c == '_' || c == '$'
1834 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
1835 /* We must have come across a bad character (e.g. ';'). */
1836 error ("Invalid character '%c' in expression.", c);
1838 /* It's a name. See how long it is. */
1840 for (c = tokstart[namelen];
1841 (c == '_' || c == '$' || (c >= '0' && c <= '9')
1842 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '<');)
1844 /* Template parameter lists are part of the name.
1845 FIXME: This mishandles `print $a<4&&$a>3'. */
1849 /* Scan ahead to get rest of the template specification. Note
1850 that we look ahead only when the '<' adjoins non-whitespace
1851 characters; for comparison expressions, e.g. "a < b > c",
1852 there must be spaces before the '<', etc. */
1854 char * p = find_template_name_end (tokstart + namelen);
1856 namelen = p - tokstart;
1859 c = tokstart[++namelen];
1862 /* The token "if" terminates the expression and is NOT removed from
1863 the input stream. It doesn't count if it appears in the
1864 expansion of a macro. */
1866 && tokstart[0] == 'i'
1867 && tokstart[1] == 'f'
1868 && ! scanning_macro_expansion ())
1877 yylval.sval.ptr = tokstart;
1878 yylval.sval.length = namelen;
1880 /* Catch specific keywords. */
1881 copy = copy_name (yylval.sval);
1882 for (i = 0; i < sizeof ident_tokens / sizeof ident_tokens[0]; i++)
1883 if (strcmp (copy, ident_tokens[i].operator) == 0)
1885 if (ident_tokens[i].cxx_only
1886 && parse_language->la_language != language_cplus)
1889 /* It is ok to always set this, even though we don't always
1890 strictly need to. */
1891 yylval.opcode = ident_tokens[i].opcode;
1892 return ident_tokens[i].token;
1895 if (*tokstart == '$')
1897 write_dollar_variable (yylval.sval);
1901 /* Use token-type BLOCKNAME for symbols that happen to be defined as
1902 functions or symtabs. If this is not so, then ...
1903 Use token-type TYPENAME for symbols that happen to be defined
1904 currently as names of types; NAME for other symbols.
1905 The caller is not constrained to care about the distinction. */
1908 int is_a_field_of_this = 0;
1911 sym = lookup_symbol (copy, expression_context_block,
1913 parse_language->la_language == language_cplus
1914 ? &is_a_field_of_this : (int *) NULL);
1915 /* Call lookup_symtab, not lookup_partial_symtab, in case there are
1916 no psymtabs (coff, xcoff, or some future change to blow away the
1917 psymtabs once once symbols are read). */
1918 if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
1920 yylval.ssym.sym = sym;
1921 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
1925 { /* See if it's a file name. */
1926 struct symtab *symtab;
1928 symtab = lookup_symtab (copy);
1932 yylval.bval = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), STATIC_BLOCK);
1937 if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
1939 /* NOTE: carlton/2003-09-25: There used to be code here to
1940 handle nested types. It didn't work very well. See the
1941 comment before qualified_type for more info. */
1942 yylval.tsym.type = SYMBOL_TYPE (sym);
1946 = language_lookup_primitive_type_by_name (parse_language,
1947 parse_gdbarch, copy);
1948 if (yylval.tsym.type != NULL)
1951 /* Input names that aren't symbols but ARE valid hex numbers,
1952 when the input radix permits them, can be names or numbers
1953 depending on the parse. Note we support radixes > 16 here. */
1955 ((tokstart[0] >= 'a' && tokstart[0] < 'a' + input_radix - 10) ||
1956 (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10)))
1958 YYSTYPE newlval; /* Its value is ignored. */
1959 hextype = parse_number (tokstart, namelen, 0, &newlval);
1962 yylval.ssym.sym = sym;
1963 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
1968 /* Any other kind of symbol */
1969 yylval.ssym.sym = sym;
1970 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
1971 if (in_parse_field && *lexptr == '\0')
1972 saw_name_at_eof = 1;
1981 struct cleanup *back_to = make_cleanup (free_current_contents,
1982 &expression_macro_scope);
1984 /* Set up the scope for macro expansion. */
1985 expression_macro_scope = NULL;
1987 if (expression_context_block)
1988 expression_macro_scope
1989 = sal_macro_scope (find_pc_line (expression_context_pc, 0));
1991 expression_macro_scope = default_macro_scope ();
1992 if (! expression_macro_scope)
1993 expression_macro_scope = user_macro_scope ();
1995 /* Initialize macro expansion code. */
1996 obstack_init (&expansion_obstack);
1997 gdb_assert (! macro_original_text);
1998 make_cleanup (scan_macro_cleanup, 0);
2000 /* Initialize some state used by the lexer. */
2001 last_was_structop = 0;
2002 saw_name_at_eof = 0;
2004 result = yyparse ();
2005 do_cleanups (back_to);
2015 lexptr = prev_lexptr;
2017 error ("A %s in expression, near `%s'.", (msg ? msg : "error"), lexptr);