1 /* YACC parser for C expressions, for GDB.
2 Copyright (C) 1986, 1989-2000, 2003-2004, 2006-2012 Free Software
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* Parse a C expression from text in a string,
21 and return the result as a struct expression pointer.
22 That structure contains arithmetic operations in reverse polish,
23 with constants represented by operations that are followed by special data.
24 See expression.h for the details of the format.
25 What is important here is that it can be built up sequentially
26 during the process of parsing; the lower levels of the tree always
27 come first in the result.
29 Note that malloc's and realloc's in this file are transformed to
30 xmalloc and xrealloc respectively by the same sed command in the
31 makefile that remaps any other malloc/realloc inserted by the parser
32 generator. Doing this with #defines and trying to control the interaction
33 with include files (<malloc.h> and <stdlib.h> for example) just became
34 too messy, particularly when such includes can be inserted at random
35 times by the parser generator. */
40 #include "gdb_string.h"
42 #include "expression.h"
44 #include "parser-defs.h"
47 #include "bfd.h" /* Required by objfiles.h. */
48 #include "symfile.h" /* Required by objfiles.h. */
49 #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
52 #include "cp-support.h"
54 #include "gdb_assert.h"
55 #include "macroscope.h"
56 #include "objc-lang.h"
58 #define parse_type builtin_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 c_maxdepth
68 #define yyparse c_parse_internal
70 #define yyerror c_error
73 #define yydebug c_debug
82 #define yyerrflag c_errflag
83 #define yynerrs c_nerrs
88 #define yystate c_state
94 #define yyreds c_reds /* With YYDEBUG defined */
95 #define yytoks c_toks /* With YYDEBUG defined */
96 #define yyname c_name /* With YYDEBUG defined */
97 #define yyrule c_rule /* With YYDEBUG defined */
100 #define yydefred c_yydefred
101 #define yydgoto c_yydgoto
102 #define yysindex c_yysindex
103 #define yyrindex c_yyrindex
104 #define yygindex c_yygindex
105 #define yytable c_yytable
106 #define yycheck c_yycheck
108 #define yysslim c_yysslim
109 #define yyssp c_yyssp
110 #define yystacksize c_yystacksize
112 #define yyvsp c_yyvsp
115 #define YYDEBUG 1 /* Default to yydebug support */
118 #define YYFPRINTF parser_fprintf
122 static int yylex (void);
124 void yyerror (char *);
128 /* Although the yacc "value" of an expression is not used,
129 since the result is stored in the structure being created,
130 other node types do have values. */
146 } typed_val_decfloat;
150 struct typed_stoken tsval;
152 struct symtoken ssym;
155 enum exp_opcode opcode;
156 struct internalvar *ivar;
158 struct stoken_vector svec;
159 VEC (type_ptr) *tvec;
162 struct type_stack *type_stack;
164 struct objc_class_str class;
168 /* YYSTYPE gets defined by %union */
169 static int parse_number (char *, int, int, YYSTYPE *);
170 static struct stoken operator_stoken (const char *);
171 static void check_parameter_typelist (VEC (type_ptr) *);
174 %type <voidval> exp exp1 type_exp start variable qualified_name lcurly
176 %type <tval> type typebase
177 %type <tvec> nonempty_typelist func_mod parameter_typelist
178 /* %type <bval> block */
180 /* Fancy type parsing. */
182 %type <lval> array_mod
183 %type <tval> conversion_type_id
185 %type <type_stack> ptr_operator_ts abs_decl direct_abs_decl
187 %token <typed_val_int> INT
188 %token <typed_val_float> FLOAT
189 %token <typed_val_decfloat> DECFLOAT
191 /* Both NAME and TYPENAME tokens represent symbols in the input,
192 and both convey their data as strings.
193 But a TYPENAME is a string that happens to be defined as a typedef
194 or builtin type name (such as int or char)
195 and a NAME is any other symbol.
196 Contexts where this distinction is not important can use the
197 nonterminal "name", which matches either NAME or TYPENAME. */
199 %token <tsval> STRING
200 %token <sval> NSSTRING /* ObjC Foundation "NSString" literal */
201 %token SELECTOR /* ObjC "@selector" pseudo-operator */
203 %token <ssym> NAME /* BLOCKNAME defined below to give it higher precedence. */
204 %token <ssym> UNKNOWN_CPP_NAME
205 %token <voidval> COMPLETE
206 %token <tsym> TYPENAME
207 %token <class> CLASSNAME /* ObjC Class name */
209 %type <svec> string_exp
210 %type <ssym> name_not_typename
211 %type <tsym> typename
213 /* This is like a '[' token, but is only generated when parsing
214 Objective C. This lets us reuse the same parser without
215 erroneously parsing ObjC-specific expressions in C. */
218 /* A NAME_OR_INT is a symbol which is not known in the symbol table,
219 but which would parse as a valid number in the current input radix.
220 E.g. "c" when input_radix==16. Depending on the parse, it will be
221 turned into a name or into a number. */
223 %token <ssym> NAME_OR_INT
226 %token STRUCT CLASS UNION ENUM SIZEOF UNSIGNED COLONCOLON
230 %type <sval> operator
231 %token REINTERPRET_CAST DYNAMIC_CAST STATIC_CAST CONST_CAST
236 /* Special type cases, put in to allow the parser to distinguish different
238 %token SIGNED_KEYWORD LONG SHORT INT_KEYWORD CONST_KEYWORD VOLATILE_KEYWORD DOUBLE_KEYWORD
240 %token <sval> VARIABLE
242 %token <opcode> ASSIGN_MODIFY
251 %right '=' ASSIGN_MODIFY
259 %left '<' '>' LEQ GEQ
264 %right UNARY INCREMENT DECREMENT
265 %right ARROW ARROW_STAR '.' DOT_STAR '[' OBJC_LBRAC '('
266 %token <ssym> BLOCKNAME
267 %token <bval> FILENAME
281 { write_exp_elt_opcode(OP_TYPE);
282 write_exp_elt_type($1);
283 write_exp_elt_opcode(OP_TYPE);}
286 write_exp_elt_opcode (OP_TYPEOF);
288 | TYPEOF '(' type ')'
290 write_exp_elt_opcode (OP_TYPE);
291 write_exp_elt_type ($3);
292 write_exp_elt_opcode (OP_TYPE);
294 | DECLTYPE '(' exp ')'
296 write_exp_elt_opcode (OP_DECLTYPE);
300 /* Expressions, including the comma operator. */
303 { write_exp_elt_opcode (BINOP_COMMA); }
306 /* Expressions, not including the comma operator. */
307 exp : '*' exp %prec UNARY
308 { write_exp_elt_opcode (UNOP_IND); }
311 exp : '&' exp %prec UNARY
312 { write_exp_elt_opcode (UNOP_ADDR); }
315 exp : '-' exp %prec UNARY
316 { write_exp_elt_opcode (UNOP_NEG); }
319 exp : '+' exp %prec UNARY
320 { write_exp_elt_opcode (UNOP_PLUS); }
323 exp : '!' exp %prec UNARY
324 { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
327 exp : '~' exp %prec UNARY
328 { write_exp_elt_opcode (UNOP_COMPLEMENT); }
331 exp : INCREMENT exp %prec UNARY
332 { write_exp_elt_opcode (UNOP_PREINCREMENT); }
335 exp : DECREMENT exp %prec UNARY
336 { write_exp_elt_opcode (UNOP_PREDECREMENT); }
339 exp : exp INCREMENT %prec UNARY
340 { write_exp_elt_opcode (UNOP_POSTINCREMENT); }
343 exp : exp DECREMENT %prec UNARY
344 { write_exp_elt_opcode (UNOP_POSTDECREMENT); }
347 exp : SIZEOF exp %prec UNARY
348 { write_exp_elt_opcode (UNOP_SIZEOF); }
352 { write_exp_elt_opcode (STRUCTOP_PTR);
353 write_exp_string ($3);
354 write_exp_elt_opcode (STRUCTOP_PTR); }
357 exp : exp ARROW name COMPLETE
358 { mark_struct_expression ();
359 write_exp_elt_opcode (STRUCTOP_PTR);
360 write_exp_string ($3);
361 write_exp_elt_opcode (STRUCTOP_PTR); }
364 exp : exp ARROW COMPLETE
366 mark_struct_expression ();
367 write_exp_elt_opcode (STRUCTOP_PTR);
370 write_exp_string (s);
371 write_exp_elt_opcode (STRUCTOP_PTR); }
374 exp : exp ARROW qualified_name
375 { /* exp->type::name becomes exp->*(&type::name) */
376 /* Note: this doesn't work if name is a
377 static member! FIXME */
378 write_exp_elt_opcode (UNOP_ADDR);
379 write_exp_elt_opcode (STRUCTOP_MPTR); }
382 exp : exp ARROW_STAR exp
383 { write_exp_elt_opcode (STRUCTOP_MPTR); }
387 { write_exp_elt_opcode (STRUCTOP_STRUCT);
388 write_exp_string ($3);
389 write_exp_elt_opcode (STRUCTOP_STRUCT); }
392 exp : exp '.' name COMPLETE
393 { mark_struct_expression ();
394 write_exp_elt_opcode (STRUCTOP_STRUCT);
395 write_exp_string ($3);
396 write_exp_elt_opcode (STRUCTOP_STRUCT); }
399 exp : exp '.' COMPLETE
401 mark_struct_expression ();
402 write_exp_elt_opcode (STRUCTOP_STRUCT);
405 write_exp_string (s);
406 write_exp_elt_opcode (STRUCTOP_STRUCT); }
409 exp : exp '.' qualified_name
410 { /* exp.type::name becomes exp.*(&type::name) */
411 /* Note: this doesn't work if name is a
412 static member! FIXME */
413 write_exp_elt_opcode (UNOP_ADDR);
414 write_exp_elt_opcode (STRUCTOP_MEMBER); }
417 exp : exp DOT_STAR exp
418 { write_exp_elt_opcode (STRUCTOP_MEMBER); }
421 exp : exp '[' exp1 ']'
422 { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
425 exp : exp OBJC_LBRAC exp1 ']'
426 { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
430 * The rules below parse ObjC message calls of the form:
431 * '[' target selector {':' argument}* ']'
434 exp : OBJC_LBRAC TYPENAME
438 class = lookup_objc_class (parse_gdbarch,
439 copy_name ($2.stoken));
441 error (_("%s is not an ObjC Class"),
442 copy_name ($2.stoken));
443 write_exp_elt_opcode (OP_LONG);
444 write_exp_elt_type (parse_type->builtin_int);
445 write_exp_elt_longcst ((LONGEST) class);
446 write_exp_elt_opcode (OP_LONG);
450 { write_exp_elt_opcode (OP_OBJC_MSGCALL);
452 write_exp_elt_opcode (OP_OBJC_MSGCALL);
456 exp : OBJC_LBRAC CLASSNAME
458 write_exp_elt_opcode (OP_LONG);
459 write_exp_elt_type (parse_type->builtin_int);
460 write_exp_elt_longcst ((LONGEST) $2.class);
461 write_exp_elt_opcode (OP_LONG);
465 { write_exp_elt_opcode (OP_OBJC_MSGCALL);
467 write_exp_elt_opcode (OP_OBJC_MSGCALL);
474 { write_exp_elt_opcode (OP_OBJC_MSGCALL);
476 write_exp_elt_opcode (OP_OBJC_MSGCALL);
481 { add_msglist(&$1, 0); }
489 msgarg : name ':' exp
490 { add_msglist(&$1, 1); }
491 | ':' exp /* Unnamed arg. */
492 { add_msglist(0, 1); }
493 | ',' exp /* Variable number of args. */
494 { add_msglist(0, 0); }
498 /* This is to save the value of arglist_len
499 being accumulated by an outer function call. */
500 { start_arglist (); }
501 arglist ')' %prec ARROW
502 { write_exp_elt_opcode (OP_FUNCALL);
503 write_exp_elt_longcst ((LONGEST) end_arglist ());
504 write_exp_elt_opcode (OP_FUNCALL); }
507 exp : UNKNOWN_CPP_NAME '('
509 /* This could potentially be a an argument defined
510 lookup function (Koenig). */
511 write_exp_elt_opcode (OP_ADL_FUNC);
512 write_exp_elt_block (expression_context_block);
513 write_exp_elt_sym (NULL); /* Placeholder. */
514 write_exp_string ($1.stoken);
515 write_exp_elt_opcode (OP_ADL_FUNC);
517 /* This is to save the value of arglist_len
518 being accumulated by an outer function call. */
522 arglist ')' %prec ARROW
524 write_exp_elt_opcode (OP_FUNCALL);
525 write_exp_elt_longcst ((LONGEST) end_arglist ());
526 write_exp_elt_opcode (OP_FUNCALL);
531 { start_arglist (); }
541 arglist : arglist ',' exp %prec ABOVE_COMMA
545 exp : exp '(' parameter_typelist ')' const_or_volatile
547 VEC (type_ptr) *type_list = $3;
548 struct type *type_elt;
549 LONGEST len = VEC_length (type_ptr, type_list);
551 write_exp_elt_opcode (TYPE_INSTANCE);
552 write_exp_elt_longcst (len);
554 VEC_iterate (type_ptr, type_list, i, type_elt);
556 write_exp_elt_type (type_elt);
557 write_exp_elt_longcst(len);
558 write_exp_elt_opcode (TYPE_INSTANCE);
559 VEC_free (type_ptr, type_list);
564 { $$ = end_arglist () - 1; }
566 exp : lcurly arglist rcurly %prec ARROW
567 { write_exp_elt_opcode (OP_ARRAY);
568 write_exp_elt_longcst ((LONGEST) 0);
569 write_exp_elt_longcst ((LONGEST) $3);
570 write_exp_elt_opcode (OP_ARRAY); }
573 exp : lcurly type_exp rcurly exp %prec UNARY
574 { write_exp_elt_opcode (UNOP_MEMVAL_TYPE); }
577 exp : '(' type_exp ')' exp %prec UNARY
578 { write_exp_elt_opcode (UNOP_CAST_TYPE); }
585 /* Binary operators in order of decreasing precedence. */
588 { write_exp_elt_opcode (BINOP_REPEAT); }
592 { write_exp_elt_opcode (BINOP_MUL); }
596 { write_exp_elt_opcode (BINOP_DIV); }
600 { write_exp_elt_opcode (BINOP_REM); }
604 { write_exp_elt_opcode (BINOP_ADD); }
608 { write_exp_elt_opcode (BINOP_SUB); }
612 { write_exp_elt_opcode (BINOP_LSH); }
616 { write_exp_elt_opcode (BINOP_RSH); }
620 { write_exp_elt_opcode (BINOP_EQUAL); }
623 exp : exp NOTEQUAL exp
624 { write_exp_elt_opcode (BINOP_NOTEQUAL); }
628 { write_exp_elt_opcode (BINOP_LEQ); }
632 { write_exp_elt_opcode (BINOP_GEQ); }
636 { write_exp_elt_opcode (BINOP_LESS); }
640 { write_exp_elt_opcode (BINOP_GTR); }
644 { write_exp_elt_opcode (BINOP_BITWISE_AND); }
648 { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
652 { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
656 { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
660 { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
663 exp : exp '?' exp ':' exp %prec '?'
664 { write_exp_elt_opcode (TERNOP_COND); }
668 { write_exp_elt_opcode (BINOP_ASSIGN); }
671 exp : exp ASSIGN_MODIFY exp
672 { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY);
673 write_exp_elt_opcode ($2);
674 write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); }
678 { write_exp_elt_opcode (OP_LONG);
679 write_exp_elt_type ($1.type);
680 write_exp_elt_longcst ((LONGEST)($1.val));
681 write_exp_elt_opcode (OP_LONG); }
686 struct stoken_vector vec;
689 write_exp_string_vector ($1.type, &vec);
695 parse_number ($1.stoken.ptr, $1.stoken.length, 0, &val);
696 write_exp_elt_opcode (OP_LONG);
697 write_exp_elt_type (val.typed_val_int.type);
698 write_exp_elt_longcst ((LONGEST)val.typed_val_int.val);
699 write_exp_elt_opcode (OP_LONG);
705 { write_exp_elt_opcode (OP_DOUBLE);
706 write_exp_elt_type ($1.type);
707 write_exp_elt_dblcst ($1.dval);
708 write_exp_elt_opcode (OP_DOUBLE); }
712 { write_exp_elt_opcode (OP_DECFLOAT);
713 write_exp_elt_type ($1.type);
714 write_exp_elt_decfloatcst ($1.val);
715 write_exp_elt_opcode (OP_DECFLOAT); }
723 write_dollar_variable ($1);
727 exp : SELECTOR '(' name ')'
729 write_exp_elt_opcode (OP_OBJC_SELECTOR);
730 write_exp_string ($3);
731 write_exp_elt_opcode (OP_OBJC_SELECTOR); }
734 exp : SIZEOF '(' type ')' %prec UNARY
735 { write_exp_elt_opcode (OP_LONG);
736 write_exp_elt_type (lookup_signed_typename
737 (parse_language, parse_gdbarch,
740 write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
741 write_exp_elt_opcode (OP_LONG); }
744 exp : REINTERPRET_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
745 { write_exp_elt_opcode (UNOP_REINTERPRET_CAST); }
748 exp : STATIC_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
749 { write_exp_elt_opcode (UNOP_CAST_TYPE); }
752 exp : DYNAMIC_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
753 { write_exp_elt_opcode (UNOP_DYNAMIC_CAST); }
756 exp : CONST_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
757 { /* We could do more error checking here, but
758 it doesn't seem worthwhile. */
759 write_exp_elt_opcode (UNOP_CAST_TYPE); }
765 /* We copy the string here, and not in the
766 lexer, to guarantee that we do not leak a
767 string. Note that we follow the
768 NUL-termination convention of the
770 struct typed_stoken *vec = XNEW (struct typed_stoken);
775 vec->length = $1.length;
776 vec->ptr = malloc ($1.length + 1);
777 memcpy (vec->ptr, $1.ptr, $1.length + 1);
782 /* Note that we NUL-terminate here, but just
786 $$.tokens = realloc ($$.tokens,
787 $$.len * sizeof (struct typed_stoken));
789 p = malloc ($2.length + 1);
790 memcpy (p, $2.ptr, $2.length + 1);
792 $$.tokens[$$.len - 1].type = $2.type;
793 $$.tokens[$$.len - 1].length = $2.length;
794 $$.tokens[$$.len - 1].ptr = p;
801 enum c_string_type type = C_STRING;
803 for (i = 0; i < $1.len; ++i)
805 switch ($1.tokens[i].type)
813 && type != $1.tokens[i].type)
814 error (_("Undefined string concatenation."));
815 type = $1.tokens[i].type;
819 internal_error (__FILE__, __LINE__,
820 "unrecognized type in string concatenation");
824 write_exp_string_vector (type, &$1);
825 for (i = 0; i < $1.len; ++i)
826 free ($1.tokens[i].ptr);
831 exp : NSSTRING /* ObjC NextStep NSString constant
832 * of the form '@' '"' string '"'.
834 { write_exp_elt_opcode (OP_OBJC_NSSTRING);
835 write_exp_string ($1);
836 write_exp_elt_opcode (OP_OBJC_NSSTRING); }
841 { write_exp_elt_opcode (OP_LONG);
842 write_exp_elt_type (parse_type->builtin_bool);
843 write_exp_elt_longcst ((LONGEST) 1);
844 write_exp_elt_opcode (OP_LONG); }
848 { write_exp_elt_opcode (OP_LONG);
849 write_exp_elt_type (parse_type->builtin_bool);
850 write_exp_elt_longcst ((LONGEST) 0);
851 write_exp_elt_opcode (OP_LONG); }
859 $$ = SYMBOL_BLOCK_VALUE ($1.sym);
861 error (_("No file or function \"%s\"."),
862 copy_name ($1.stoken));
870 block : block COLONCOLON name
872 = lookup_symbol (copy_name ($3), $1,
873 VAR_DOMAIN, (int *) NULL);
874 if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
875 error (_("No function \"%s\" in specified context."),
877 $$ = SYMBOL_BLOCK_VALUE (tem); }
880 variable: name_not_typename ENTRY
881 { struct symbol *sym = $1.sym;
883 if (sym == NULL || !SYMBOL_IS_ARGUMENT (sym)
884 || !symbol_read_needs_frame (sym))
885 error (_("@entry can be used only for function "
886 "parameters, not for \"%s\""),
887 copy_name ($1.stoken));
889 write_exp_elt_opcode (OP_VAR_ENTRY_VALUE);
890 write_exp_elt_sym (sym);
891 write_exp_elt_opcode (OP_VAR_ENTRY_VALUE);
895 variable: block COLONCOLON name
896 { struct symbol *sym;
897 sym = lookup_symbol (copy_name ($3), $1,
898 VAR_DOMAIN, (int *) NULL);
900 error (_("No symbol \"%s\" in specified context."),
902 if (symbol_read_needs_frame (sym))
904 if (innermost_block == 0
905 || contained_in (block_found,
907 innermost_block = block_found;
910 write_exp_elt_opcode (OP_VAR_VALUE);
911 /* block_found is set by lookup_symbol. */
912 write_exp_elt_block (block_found);
913 write_exp_elt_sym (sym);
914 write_exp_elt_opcode (OP_VAR_VALUE); }
917 qualified_name: TYPENAME COLONCOLON name
919 struct type *type = $1.type;
920 CHECK_TYPEDEF (type);
921 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
922 && TYPE_CODE (type) != TYPE_CODE_UNION
923 && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
924 error (_("`%s' is not defined as an aggregate type."),
927 write_exp_elt_opcode (OP_SCOPE);
928 write_exp_elt_type (type);
929 write_exp_string ($3);
930 write_exp_elt_opcode (OP_SCOPE);
932 | TYPENAME COLONCOLON '~' name
934 struct type *type = $1.type;
935 struct stoken tmp_token;
936 CHECK_TYPEDEF (type);
937 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
938 && TYPE_CODE (type) != TYPE_CODE_UNION
939 && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
940 error (_("`%s' is not defined as an aggregate type."),
943 tmp_token.ptr = (char*) alloca ($4.length + 2);
944 tmp_token.length = $4.length + 1;
945 tmp_token.ptr[0] = '~';
946 memcpy (tmp_token.ptr+1, $4.ptr, $4.length);
947 tmp_token.ptr[tmp_token.length] = 0;
949 /* Check for valid destructor name. */
950 destructor_name_p (tmp_token.ptr, $1.type);
951 write_exp_elt_opcode (OP_SCOPE);
952 write_exp_elt_type (type);
953 write_exp_string (tmp_token);
954 write_exp_elt_opcode (OP_SCOPE);
956 | TYPENAME COLONCOLON name COLONCOLON name
958 char *copy = copy_name ($3);
959 error (_("No type \"%s\" within class "
960 "or namespace \"%s\"."),
961 copy, TYPE_NAME ($1.type));
965 variable: qualified_name
966 | COLONCOLON name_not_typename
968 char *name = copy_name ($2.stoken);
970 struct minimal_symbol *msymbol;
973 lookup_symbol (name, (const struct block *) NULL,
974 VAR_DOMAIN, (int *) NULL);
977 write_exp_elt_opcode (OP_VAR_VALUE);
978 write_exp_elt_block (NULL);
979 write_exp_elt_sym (sym);
980 write_exp_elt_opcode (OP_VAR_VALUE);
984 msymbol = lookup_minimal_symbol (name, NULL, NULL);
986 write_exp_msymbol (msymbol);
987 else if (!have_full_symbols () && !have_partial_symbols ())
988 error (_("No symbol table is loaded. Use the \"file\" command."));
990 error (_("No symbol \"%s\" in current context."), name);
994 variable: name_not_typename
995 { struct symbol *sym = $1.sym;
999 if (symbol_read_needs_frame (sym))
1001 if (innermost_block == 0
1002 || contained_in (block_found,
1004 innermost_block = block_found;
1007 write_exp_elt_opcode (OP_VAR_VALUE);
1008 /* We want to use the selected frame, not
1009 another more inner frame which happens to
1010 be in the same block. */
1011 write_exp_elt_block (NULL);
1012 write_exp_elt_sym (sym);
1013 write_exp_elt_opcode (OP_VAR_VALUE);
1015 else if ($1.is_a_field_of_this)
1017 /* C++: it hangs off of `this'. Must
1018 not inadvertently convert from a method call
1020 if (innermost_block == 0
1021 || contained_in (block_found,
1023 innermost_block = block_found;
1024 write_exp_elt_opcode (OP_THIS);
1025 write_exp_elt_opcode (OP_THIS);
1026 write_exp_elt_opcode (STRUCTOP_PTR);
1027 write_exp_string ($1.stoken);
1028 write_exp_elt_opcode (STRUCTOP_PTR);
1032 struct minimal_symbol *msymbol;
1033 char *arg = copy_name ($1.stoken);
1036 lookup_minimal_symbol (arg, NULL, NULL);
1037 if (msymbol != NULL)
1038 write_exp_msymbol (msymbol);
1039 else if (!have_full_symbols () && !have_partial_symbols ())
1040 error (_("No symbol table is loaded. Use the \"file\" command."));
1042 error (_("No symbol \"%s\" in current context."),
1043 copy_name ($1.stoken));
1048 space_identifier : '@' NAME
1049 { insert_type_address_space (copy_name ($2.stoken)); }
1052 const_or_volatile: const_or_volatile_noopt
1056 cv_with_space_id : const_or_volatile space_identifier const_or_volatile
1059 const_or_volatile_or_space_identifier_noopt: cv_with_space_id
1060 | const_or_volatile_noopt
1063 const_or_volatile_or_space_identifier:
1064 const_or_volatile_or_space_identifier_noopt
1070 { insert_type (tp_pointer); }
1071 const_or_volatile_or_space_identifier
1073 { insert_type (tp_pointer); }
1074 const_or_volatile_or_space_identifier
1076 { insert_type (tp_reference); }
1078 { insert_type (tp_reference); }
1081 ptr_operator_ts: ptr_operator
1083 $$ = get_type_stack ();
1084 /* This cleanup is eventually run by
1086 make_cleanup (type_stack_cleanup, $$);
1090 abs_decl: ptr_operator_ts direct_abs_decl
1091 { $$ = append_type_stack ($2, $1); }
1096 direct_abs_decl: '(' abs_decl ')'
1098 | direct_abs_decl array_mod
1100 push_type_stack ($1);
1102 push_type (tp_array);
1103 $$ = get_type_stack ();
1108 push_type (tp_array);
1109 $$ = get_type_stack ();
1112 | direct_abs_decl func_mod
1114 push_type_stack ($1);
1116 $$ = get_type_stack ();
1121 $$ = get_type_stack ();
1131 | OBJC_LBRAC INT ']'
1137 | '(' parameter_typelist ')'
1141 /* We used to try to recognize pointer to member types here, but
1142 that didn't work (shift/reduce conflicts meant that these rules never
1143 got executed). The problem is that
1144 int (foo::bar::baz::bizzle)
1145 is a function type but
1146 int (foo::bar::baz::bizzle::*)
1147 is a pointer to member type. Stroustrup loses again! */
1152 typebase /* Implements (approximately): (type-qualifier)* type-specifier */
1156 { $$ = lookup_signed_typename (parse_language,
1160 { $$ = lookup_signed_typename (parse_language,
1164 { $$ = lookup_signed_typename (parse_language,
1168 { $$ = lookup_signed_typename (parse_language,
1171 | LONG SIGNED_KEYWORD INT_KEYWORD
1172 { $$ = lookup_signed_typename (parse_language,
1175 | LONG SIGNED_KEYWORD
1176 { $$ = lookup_signed_typename (parse_language,
1179 | SIGNED_KEYWORD LONG INT_KEYWORD
1180 { $$ = lookup_signed_typename (parse_language,
1183 | UNSIGNED LONG INT_KEYWORD
1184 { $$ = lookup_unsigned_typename (parse_language,
1187 | LONG UNSIGNED INT_KEYWORD
1188 { $$ = lookup_unsigned_typename (parse_language,
1192 { $$ = lookup_unsigned_typename (parse_language,
1196 { $$ = lookup_signed_typename (parse_language,
1199 | LONG LONG INT_KEYWORD
1200 { $$ = lookup_signed_typename (parse_language,
1203 | LONG LONG SIGNED_KEYWORD INT_KEYWORD
1204 { $$ = lookup_signed_typename (parse_language,
1207 | LONG LONG SIGNED_KEYWORD
1208 { $$ = lookup_signed_typename (parse_language,
1211 | SIGNED_KEYWORD LONG LONG
1212 { $$ = lookup_signed_typename (parse_language,
1215 | SIGNED_KEYWORD LONG LONG INT_KEYWORD
1216 { $$ = lookup_signed_typename (parse_language,
1219 | UNSIGNED LONG LONG
1220 { $$ = lookup_unsigned_typename (parse_language,
1223 | UNSIGNED LONG LONG INT_KEYWORD
1224 { $$ = lookup_unsigned_typename (parse_language,
1227 | LONG LONG UNSIGNED
1228 { $$ = lookup_unsigned_typename (parse_language,
1231 | LONG LONG UNSIGNED INT_KEYWORD
1232 { $$ = lookup_unsigned_typename (parse_language,
1236 { $$ = lookup_signed_typename (parse_language,
1239 | SHORT SIGNED_KEYWORD INT_KEYWORD
1240 { $$ = lookup_signed_typename (parse_language,
1243 | SHORT SIGNED_KEYWORD
1244 { $$ = lookup_signed_typename (parse_language,
1247 | UNSIGNED SHORT INT_KEYWORD
1248 { $$ = lookup_unsigned_typename (parse_language,
1252 { $$ = lookup_unsigned_typename (parse_language,
1255 | SHORT UNSIGNED INT_KEYWORD
1256 { $$ = lookup_unsigned_typename (parse_language,
1260 { $$ = lookup_typename (parse_language, parse_gdbarch,
1261 "double", (struct block *) NULL,
1263 | LONG DOUBLE_KEYWORD
1264 { $$ = lookup_typename (parse_language, parse_gdbarch,
1266 (struct block *) NULL, 0); }
1268 { $$ = lookup_struct (copy_name ($2),
1269 expression_context_block); }
1271 { $$ = lookup_struct (copy_name ($2),
1272 expression_context_block); }
1274 { $$ = lookup_union (copy_name ($2),
1275 expression_context_block); }
1277 { $$ = lookup_enum (copy_name ($2),
1278 expression_context_block); }
1280 { $$ = lookup_unsigned_typename (parse_language,
1282 TYPE_NAME($2.type)); }
1284 { $$ = lookup_unsigned_typename (parse_language,
1287 | SIGNED_KEYWORD typename
1288 { $$ = lookup_signed_typename (parse_language,
1290 TYPE_NAME($2.type)); }
1292 { $$ = lookup_signed_typename (parse_language,
1295 /* It appears that this rule for templates is never
1296 reduced; template recognition happens by lookahead
1297 in the token processing code in yylex. */
1298 | TEMPLATE name '<' type '>'
1299 { $$ = lookup_template_type(copy_name($2), $4,
1300 expression_context_block);
1302 | const_or_volatile_or_space_identifier_noopt typebase
1303 { $$ = follow_types ($2); }
1304 | typebase const_or_volatile_or_space_identifier_noopt
1305 { $$ = follow_types ($1); }
1311 $$.stoken.ptr = "int";
1312 $$.stoken.length = 3;
1313 $$.type = lookup_signed_typename (parse_language,
1319 $$.stoken.ptr = "long";
1320 $$.stoken.length = 4;
1321 $$.type = lookup_signed_typename (parse_language,
1327 $$.stoken.ptr = "short";
1328 $$.stoken.length = 5;
1329 $$.type = lookup_signed_typename (parse_language,
1337 { check_parameter_typelist ($1); }
1338 | nonempty_typelist ',' DOTDOTDOT
1340 VEC_safe_push (type_ptr, $1, NULL);
1341 check_parameter_typelist ($1);
1349 VEC (type_ptr) *typelist = NULL;
1350 VEC_safe_push (type_ptr, typelist, $1);
1353 | nonempty_typelist ',' type
1355 VEC_safe_push (type_ptr, $1, $3);
1363 push_type_stack ($2);
1364 $$ = follow_types ($1);
1368 conversion_type_id: typebase conversion_declarator
1369 { $$ = follow_types ($1); }
1372 conversion_declarator: /* Nothing. */
1373 | ptr_operator conversion_declarator
1376 const_and_volatile: CONST_KEYWORD VOLATILE_KEYWORD
1377 | VOLATILE_KEYWORD CONST_KEYWORD
1380 const_or_volatile_noopt: const_and_volatile
1381 { insert_type (tp_const);
1382 insert_type (tp_volatile);
1385 { insert_type (tp_const); }
1387 { insert_type (tp_volatile); }
1390 operator: OPERATOR NEW
1391 { $$ = operator_stoken (" new"); }
1393 { $$ = operator_stoken (" delete"); }
1394 | OPERATOR NEW '[' ']'
1395 { $$ = operator_stoken (" new[]"); }
1396 | OPERATOR DELETE '[' ']'
1397 { $$ = operator_stoken (" delete[]"); }
1398 | OPERATOR NEW OBJC_LBRAC ']'
1399 { $$ = operator_stoken (" new[]"); }
1400 | OPERATOR DELETE OBJC_LBRAC ']'
1401 { $$ = operator_stoken (" delete[]"); }
1403 { $$ = operator_stoken ("+"); }
1405 { $$ = operator_stoken ("-"); }
1407 { $$ = operator_stoken ("*"); }
1409 { $$ = operator_stoken ("/"); }
1411 { $$ = operator_stoken ("%"); }
1413 { $$ = operator_stoken ("^"); }
1415 { $$ = operator_stoken ("&"); }
1417 { $$ = operator_stoken ("|"); }
1419 { $$ = operator_stoken ("~"); }
1421 { $$ = operator_stoken ("!"); }
1423 { $$ = operator_stoken ("="); }
1425 { $$ = operator_stoken ("<"); }
1427 { $$ = operator_stoken (">"); }
1428 | OPERATOR ASSIGN_MODIFY
1429 { const char *op = "unknown";
1453 case BINOP_BITWISE_IOR:
1456 case BINOP_BITWISE_AND:
1459 case BINOP_BITWISE_XOR:
1466 $$ = operator_stoken (op);
1469 { $$ = operator_stoken ("<<"); }
1471 { $$ = operator_stoken (">>"); }
1473 { $$ = operator_stoken ("=="); }
1475 { $$ = operator_stoken ("!="); }
1477 { $$ = operator_stoken ("<="); }
1479 { $$ = operator_stoken (">="); }
1481 { $$ = operator_stoken ("&&"); }
1483 { $$ = operator_stoken ("||"); }
1484 | OPERATOR INCREMENT
1485 { $$ = operator_stoken ("++"); }
1486 | OPERATOR DECREMENT
1487 { $$ = operator_stoken ("--"); }
1489 { $$ = operator_stoken (","); }
1490 | OPERATOR ARROW_STAR
1491 { $$ = operator_stoken ("->*"); }
1493 { $$ = operator_stoken ("->"); }
1495 { $$ = operator_stoken ("()"); }
1497 { $$ = operator_stoken ("[]"); }
1498 | OPERATOR OBJC_LBRAC ']'
1499 { $$ = operator_stoken ("[]"); }
1500 | OPERATOR conversion_type_id
1503 struct ui_file *buf = mem_fileopen ();
1505 c_print_type ($2, NULL, buf, -1, 0);
1506 name = ui_file_xstrdup (buf, &length);
1507 ui_file_delete (buf);
1508 $$ = operator_stoken (name);
1515 name : NAME { $$ = $1.stoken; }
1516 | BLOCKNAME { $$ = $1.stoken; }
1517 | TYPENAME { $$ = $1.stoken; }
1518 | NAME_OR_INT { $$ = $1.stoken; }
1519 | UNKNOWN_CPP_NAME { $$ = $1.stoken; }
1520 | operator { $$ = $1; }
1523 name_not_typename : NAME
1525 /* These would be useful if name_not_typename was useful, but it is just
1526 a fake for "variable", so these cause reduce/reduce conflicts because
1527 the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable,
1528 =exp) or just an exp. If name_not_typename was ever used in an lvalue
1529 context where only a name could occur, this might be useful.
1535 $$.sym = lookup_symbol ($1.ptr,
1536 expression_context_block,
1538 &$$.is_a_field_of_this);
1545 /* Returns a stoken of the operator name given by OP (which does not
1546 include the string "operator"). */
1547 static struct stoken
1548 operator_stoken (const char *op)
1550 static const char *operator_string = "operator";
1551 struct stoken st = { NULL, 0 };
1552 st.length = strlen (operator_string) + strlen (op);
1553 st.ptr = malloc (st.length + 1);
1554 strcpy (st.ptr, operator_string);
1555 strcat (st.ptr, op);
1557 /* The toplevel (c_parse) will free the memory allocated here. */
1558 make_cleanup (free, st.ptr);
1562 /* Validate a parameter typelist. */
1565 check_parameter_typelist (VEC (type_ptr) *params)
1570 for (ix = 0; VEC_iterate (type_ptr, params, ix, type); ++ix)
1572 if (type != NULL && TYPE_CODE (check_typedef (type)) == TYPE_CODE_VOID)
1576 if (VEC_length (type_ptr, params) == 1)
1581 VEC_free (type_ptr, params);
1582 error (_("parameter types following 'void'"));
1586 VEC_free (type_ptr, params);
1587 error (_("'void' invalid as parameter type"));
1593 /* Take care of parsing a number (anything that starts with a digit).
1594 Set yylval and return the token type; update lexptr.
1595 LEN is the number of characters in it. */
1597 /*** Needs some error checking for the float case ***/
1600 parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
1602 /* FIXME: Shouldn't these be unsigned? We don't deal with negative values
1603 here, and we do kind of silly things like cast to unsigned. */
1610 int base = input_radix;
1613 /* Number of "L" suffixes encountered. */
1616 /* We have found a "L" or "U" suffix. */
1617 int found_suffix = 0;
1620 struct type *signed_type;
1621 struct type *unsigned_type;
1625 /* If it ends at "df", "dd" or "dl", take it as type of decimal floating
1626 point. Return DECFLOAT. */
1628 if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'f')
1631 putithere->typed_val_decfloat.type
1632 = parse_type->builtin_decfloat;
1633 decimal_from_string (putithere->typed_val_decfloat.val, 4,
1634 gdbarch_byte_order (parse_gdbarch), p);
1639 if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'd')
1642 putithere->typed_val_decfloat.type
1643 = parse_type->builtin_decdouble;
1644 decimal_from_string (putithere->typed_val_decfloat.val, 8,
1645 gdbarch_byte_order (parse_gdbarch), p);
1650 if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'l')
1653 putithere->typed_val_decfloat.type
1654 = parse_type->builtin_declong;
1655 decimal_from_string (putithere->typed_val_decfloat.val, 16,
1656 gdbarch_byte_order (parse_gdbarch), p);
1661 if (! parse_c_float (parse_gdbarch, p, len,
1662 &putithere->typed_val_float.dval,
1663 &putithere->typed_val_float.type))
1668 /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
1712 if (c >= 'A' && c <= 'Z')
1714 if (c != 'l' && c != 'u')
1716 if (c >= '0' && c <= '9')
1724 if (base > 10 && c >= 'a' && c <= 'f')
1728 n += i = c - 'a' + 10;
1741 return ERROR; /* Char not a digit */
1744 return ERROR; /* Invalid digit in this base */
1746 /* Portably test for overflow (only works for nonzero values, so make
1747 a second check for zero). FIXME: Can't we just make n and prevn
1748 unsigned and avoid this? */
1749 if (c != 'l' && c != 'u' && (prevn >= n) && n != 0)
1750 unsigned_p = 1; /* Try something unsigned */
1752 /* Portably test for unsigned overflow.
1753 FIXME: This check is wrong; for example it doesn't find overflow
1754 on 0x123456789 when LONGEST is 32 bits. */
1755 if (c != 'l' && c != 'u' && n != 0)
1757 if ((unsigned_p && (ULONGEST) prevn >= (ULONGEST) n))
1758 error (_("Numeric constant too large."));
1763 /* An integer constant is an int, a long, or a long long. An L
1764 suffix forces it to be long; an LL suffix forces it to be long
1765 long. If not forced to a larger size, it gets the first type of
1766 the above that it fits in. To figure out whether it fits, we
1767 shift it right and see whether anything remains. Note that we
1768 can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one
1769 operation, because many compilers will warn about such a shift
1770 (which always produces a zero result). Sometimes gdbarch_int_bit
1771 or gdbarch_long_bit will be that big, sometimes not. To deal with
1772 the case where it is we just always shift the value more than
1773 once, with fewer bits each time. */
1775 un = (ULONGEST)n >> 2;
1777 && (un >> (gdbarch_int_bit (parse_gdbarch) - 2)) == 0)
1779 high_bit = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch) - 1);
1781 /* A large decimal (not hex or octal) constant (between INT_MAX
1782 and UINT_MAX) is a long or unsigned long, according to ANSI,
1783 never an unsigned int, but this code treats it as unsigned
1784 int. This probably should be fixed. GCC gives a warning on
1787 unsigned_type = parse_type->builtin_unsigned_int;
1788 signed_type = parse_type->builtin_int;
1790 else if (long_p <= 1
1791 && (un >> (gdbarch_long_bit (parse_gdbarch) - 2)) == 0)
1793 high_bit = ((ULONGEST)1) << (gdbarch_long_bit (parse_gdbarch) - 1);
1794 unsigned_type = parse_type->builtin_unsigned_long;
1795 signed_type = parse_type->builtin_long;
1800 if (sizeof (ULONGEST) * HOST_CHAR_BIT
1801 < gdbarch_long_long_bit (parse_gdbarch))
1802 /* A long long does not fit in a LONGEST. */
1803 shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1);
1805 shift = (gdbarch_long_long_bit (parse_gdbarch) - 1);
1806 high_bit = (ULONGEST) 1 << shift;
1807 unsigned_type = parse_type->builtin_unsigned_long_long;
1808 signed_type = parse_type->builtin_long_long;
1811 putithere->typed_val_int.val = n;
1813 /* If the high bit of the worked out type is set then this number
1814 has to be unsigned. */
1816 if (unsigned_p || (n & high_bit))
1818 putithere->typed_val_int.type = unsigned_type;
1822 putithere->typed_val_int.type = signed_type;
1828 /* Temporary obstack used for holding strings. */
1829 static struct obstack tempbuf;
1830 static int tempbuf_init;
1832 /* Parse a C escape sequence. The initial backslash of the sequence
1833 is at (*PTR)[-1]. *PTR will be updated to point to just after the
1834 last character of the sequence. If OUTPUT is not NULL, the
1835 translated form of the escape sequence will be written there. If
1836 OUTPUT is NULL, no output is written and the call will only affect
1837 *PTR. If an escape sequence is expressed in target bytes, then the
1838 entire sequence will simply be copied to OUTPUT. Return 1 if any
1839 character was emitted, 0 otherwise. */
1842 c_parse_escape (char **ptr, struct obstack *output)
1844 char *tokptr = *ptr;
1847 /* Some escape sequences undergo character set conversion. Those we
1851 /* Hex escapes do not undergo character set conversion, so keep
1852 the escape sequence for later. */
1855 obstack_grow_str (output, "\\x");
1857 if (!isxdigit (*tokptr))
1858 error (_("\\x escape without a following hex digit"));
1859 while (isxdigit (*tokptr))
1862 obstack_1grow (output, *tokptr);
1867 /* Octal escapes do not undergo character set conversion, so
1868 keep the escape sequence for later. */
1880 obstack_grow_str (output, "\\");
1882 i < 3 && isdigit (*tokptr) && *tokptr != '8' && *tokptr != '9';
1886 obstack_1grow (output, *tokptr);
1892 /* We handle UCNs later. We could handle them here, but that
1893 would mean a spurious error in the case where the UCN could
1894 be converted to the target charset but not the host
1900 int i, len = c == 'U' ? 8 : 4;
1903 obstack_1grow (output, '\\');
1904 obstack_1grow (output, *tokptr);
1907 if (!isxdigit (*tokptr))
1908 error (_("\\%c escape without a following hex digit"), c);
1909 for (i = 0; i < len && isxdigit (*tokptr); ++i)
1912 obstack_1grow (output, *tokptr);
1918 /* We must pass backslash through so that it does not
1919 cause quoting during the second expansion. */
1922 obstack_grow_str (output, "\\\\");
1926 /* Escapes which undergo conversion. */
1929 obstack_1grow (output, '\a');
1934 obstack_1grow (output, '\b');
1939 obstack_1grow (output, '\f');
1944 obstack_1grow (output, '\n');
1949 obstack_1grow (output, '\r');
1954 obstack_1grow (output, '\t');
1959 obstack_1grow (output, '\v');
1963 /* GCC extension. */
1966 obstack_1grow (output, HOST_ESCAPE_CHAR);
1970 /* Backslash-newline expands to nothing at all. */
1976 /* A few escapes just expand to the character itself. */
1980 /* GCC extensions. */
1985 /* Unrecognized escapes turn into the character itself. */
1988 obstack_1grow (output, *tokptr);
1996 /* Parse a string or character literal from TOKPTR. The string or
1997 character may be wide or unicode. *OUTPTR is set to just after the
1998 end of the literal in the input string. The resulting token is
1999 stored in VALUE. This returns a token value, either STRING or
2000 CHAR, depending on what was parsed. *HOST_CHARS is set to the
2001 number of host characters in the literal. */
2003 parse_string_or_char (char *tokptr, char **outptr, struct typed_stoken *value,
2007 enum c_string_type type;
2010 /* Build the gdb internal form of the input string in tempbuf. Note
2011 that the buffer is null byte terminated *only* for the
2012 convenience of debugging gdb itself and printing the buffer
2013 contents when the buffer contains no embedded nulls. Gdb does
2014 not depend upon the buffer being null byte terminated, it uses
2015 the length string instead. This allows gdb to handle C strings
2016 (as well as strings in other languages) with embedded null
2022 obstack_free (&tempbuf, NULL);
2023 obstack_init (&tempbuf);
2025 /* Record the string type. */
2028 type = C_WIDE_STRING;
2031 else if (*tokptr == 'u')
2036 else if (*tokptr == 'U')
2041 else if (*tokptr == '@')
2043 /* An Objective C string. */
2051 /* Skip the quote. */
2065 *host_chars += c_parse_escape (&tokptr, &tempbuf);
2067 else if (c == quote)
2071 obstack_1grow (&tempbuf, c);
2073 /* FIXME: this does the wrong thing with multi-byte host
2074 characters. We could use mbrlen here, but that would
2075 make "set host-charset" a bit less useful. */
2080 if (*tokptr != quote)
2083 error (_("Unterminated string in expression."));
2085 error (_("Unmatched single quote."));
2090 value->ptr = obstack_base (&tempbuf);
2091 value->length = obstack_object_size (&tempbuf);
2095 return quote == '"' ? (is_objc ? NSSTRING : STRING) : CHAR;
2098 /* This is used to associate some attributes with a token. */
2102 /* If this bit is set, the token is C++-only. */
2106 /* If this bit is set, the token is conditional: if there is a
2107 symbol of the same name, then the token is a symbol; otherwise,
2108 the token is a keyword. */
2117 enum exp_opcode opcode;
2118 enum token_flags flags;
2121 static const struct token tokentab3[] =
2123 {">>=", ASSIGN_MODIFY, BINOP_RSH, 0},
2124 {"<<=", ASSIGN_MODIFY, BINOP_LSH, 0},
2125 {"->*", ARROW_STAR, BINOP_END, FLAG_CXX},
2126 {"...", DOTDOTDOT, BINOP_END, 0}
2129 static const struct token tokentab2[] =
2131 {"+=", ASSIGN_MODIFY, BINOP_ADD, 0},
2132 {"-=", ASSIGN_MODIFY, BINOP_SUB, 0},
2133 {"*=", ASSIGN_MODIFY, BINOP_MUL, 0},
2134 {"/=", ASSIGN_MODIFY, BINOP_DIV, 0},
2135 {"%=", ASSIGN_MODIFY, BINOP_REM, 0},
2136 {"|=", ASSIGN_MODIFY, BINOP_BITWISE_IOR, 0},
2137 {"&=", ASSIGN_MODIFY, BINOP_BITWISE_AND, 0},
2138 {"^=", ASSIGN_MODIFY, BINOP_BITWISE_XOR, 0},
2139 {"++", INCREMENT, BINOP_END, 0},
2140 {"--", DECREMENT, BINOP_END, 0},
2141 {"->", ARROW, BINOP_END, 0},
2142 {"&&", ANDAND, BINOP_END, 0},
2143 {"||", OROR, BINOP_END, 0},
2144 /* "::" is *not* only C++: gdb overrides its meaning in several
2145 different ways, e.g., 'filename'::func, function::variable. */
2146 {"::", COLONCOLON, BINOP_END, 0},
2147 {"<<", LSH, BINOP_END, 0},
2148 {">>", RSH, BINOP_END, 0},
2149 {"==", EQUAL, BINOP_END, 0},
2150 {"!=", NOTEQUAL, BINOP_END, 0},
2151 {"<=", LEQ, BINOP_END, 0},
2152 {">=", GEQ, BINOP_END, 0},
2153 {".*", DOT_STAR, BINOP_END, FLAG_CXX}
2156 /* Identifier-like tokens. */
2157 static const struct token ident_tokens[] =
2159 {"unsigned", UNSIGNED, OP_NULL, 0},
2160 {"template", TEMPLATE, OP_NULL, FLAG_CXX},
2161 {"volatile", VOLATILE_KEYWORD, OP_NULL, 0},
2162 {"struct", STRUCT, OP_NULL, 0},
2163 {"signed", SIGNED_KEYWORD, OP_NULL, 0},
2164 {"sizeof", SIZEOF, OP_NULL, 0},
2165 {"double", DOUBLE_KEYWORD, OP_NULL, 0},
2166 {"false", FALSEKEYWORD, OP_NULL, FLAG_CXX},
2167 {"class", CLASS, OP_NULL, FLAG_CXX},
2168 {"union", UNION, OP_NULL, 0},
2169 {"short", SHORT, OP_NULL, 0},
2170 {"const", CONST_KEYWORD, OP_NULL, 0},
2171 {"enum", ENUM, OP_NULL, 0},
2172 {"long", LONG, OP_NULL, 0},
2173 {"true", TRUEKEYWORD, OP_NULL, FLAG_CXX},
2174 {"int", INT_KEYWORD, OP_NULL, 0},
2175 {"new", NEW, OP_NULL, FLAG_CXX},
2176 {"delete", DELETE, OP_NULL, FLAG_CXX},
2177 {"operator", OPERATOR, OP_NULL, FLAG_CXX},
2179 {"and", ANDAND, BINOP_END, FLAG_CXX},
2180 {"and_eq", ASSIGN_MODIFY, BINOP_BITWISE_AND, FLAG_CXX},
2181 {"bitand", '&', OP_NULL, FLAG_CXX},
2182 {"bitor", '|', OP_NULL, FLAG_CXX},
2183 {"compl", '~', OP_NULL, FLAG_CXX},
2184 {"not", '!', OP_NULL, FLAG_CXX},
2185 {"not_eq", NOTEQUAL, BINOP_END, FLAG_CXX},
2186 {"or", OROR, BINOP_END, FLAG_CXX},
2187 {"or_eq", ASSIGN_MODIFY, BINOP_BITWISE_IOR, FLAG_CXX},
2188 {"xor", '^', OP_NULL, FLAG_CXX},
2189 {"xor_eq", ASSIGN_MODIFY, BINOP_BITWISE_XOR, FLAG_CXX},
2191 {"const_cast", CONST_CAST, OP_NULL, FLAG_CXX },
2192 {"dynamic_cast", DYNAMIC_CAST, OP_NULL, FLAG_CXX },
2193 {"static_cast", STATIC_CAST, OP_NULL, FLAG_CXX },
2194 {"reinterpret_cast", REINTERPRET_CAST, OP_NULL, FLAG_CXX },
2196 {"__typeof__", TYPEOF, OP_TYPEOF, 0 },
2197 {"__typeof", TYPEOF, OP_TYPEOF, 0 },
2198 {"typeof", TYPEOF, OP_TYPEOF, FLAG_SHADOW },
2199 {"__decltype", DECLTYPE, OP_DECLTYPE, FLAG_CXX },
2200 {"decltype", DECLTYPE, OP_DECLTYPE, FLAG_CXX | FLAG_SHADOW }
2203 /* When we find that lexptr (the global var defined in parse.c) is
2204 pointing at a macro invocation, we expand the invocation, and call
2205 scan_macro_expansion to save the old lexptr here and point lexptr
2206 into the expanded text. When we reach the end of that, we call
2207 end_macro_expansion to pop back to the value we saved here. The
2208 macro expansion code promises to return only fully-expanded text,
2209 so we don't need to "push" more than one level.
2211 This is disgusting, of course. It would be cleaner to do all macro
2212 expansion beforehand, and then hand that to lexptr. But we don't
2213 really know where the expression ends. Remember, in a command like
2215 (gdb) break *ADDRESS if CONDITION
2217 we evaluate ADDRESS in the scope of the current frame, but we
2218 evaluate CONDITION in the scope of the breakpoint's location. So
2219 it's simply wrong to try to macro-expand the whole thing at once. */
2220 static char *macro_original_text;
2222 /* We save all intermediate macro expansions on this obstack for the
2223 duration of a single parse. The expansion text may sometimes have
2224 to live past the end of the expansion, due to yacc lookahead.
2225 Rather than try to be clever about saving the data for a single
2226 token, we simply keep it all and delete it after parsing has
2228 static struct obstack expansion_obstack;
2231 scan_macro_expansion (char *expansion)
2235 /* We'd better not be trying to push the stack twice. */
2236 gdb_assert (! macro_original_text);
2238 /* Copy to the obstack, and then free the intermediate
2240 copy = obstack_copy0 (&expansion_obstack, expansion, strlen (expansion));
2243 /* Save the old lexptr value, so we can return to it when we're done
2244 parsing the expanded text. */
2245 macro_original_text = lexptr;
2251 scanning_macro_expansion (void)
2253 return macro_original_text != 0;
2258 finished_macro_expansion (void)
2260 /* There'd better be something to pop back to. */
2261 gdb_assert (macro_original_text);
2263 /* Pop back to the original text. */
2264 lexptr = macro_original_text;
2265 macro_original_text = 0;
2270 scan_macro_cleanup (void *dummy)
2272 if (macro_original_text)
2273 finished_macro_expansion ();
2275 obstack_free (&expansion_obstack, NULL);
2278 /* Return true iff the token represents a C++ cast operator. */
2281 is_cast_operator (const char *token, int len)
2283 return (! strncmp (token, "dynamic_cast", len)
2284 || ! strncmp (token, "static_cast", len)
2285 || ! strncmp (token, "reinterpret_cast", len)
2286 || ! strncmp (token, "const_cast", len));
2289 /* The scope used for macro expansion. */
2290 static struct macro_scope *expression_macro_scope;
2292 /* This is set if a NAME token appeared at the very end of the input
2293 string, with no whitespace separating the name from the EOF. This
2294 is used only when parsing to do field name completion. */
2295 static int saw_name_at_eof;
2297 /* This is set if the previously-returned token was a structure
2298 operator -- either '.' or ARROW. This is used only when parsing to
2299 do field name completion. */
2300 static int last_was_structop;
2302 /* Read one token, getting characters through lexptr. */
2305 lex_one_token (void)
2311 int saw_structop = last_was_structop;
2314 last_was_structop = 0;
2318 /* Check if this is a macro invocation that we need to expand. */
2319 if (! scanning_macro_expansion ())
2321 char *expanded = macro_expand_next (&lexptr,
2322 standard_macro_lookup,
2323 expression_macro_scope);
2326 scan_macro_expansion (expanded);
2329 prev_lexptr = lexptr;
2332 /* See if it is a special token of length 3. */
2333 for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++)
2334 if (strncmp (tokstart, tokentab3[i].operator, 3) == 0)
2336 if ((tokentab3[i].flags & FLAG_CXX) != 0
2337 && parse_language->la_language != language_cplus)
2341 yylval.opcode = tokentab3[i].opcode;
2342 return tokentab3[i].token;
2345 /* See if it is a special token of length 2. */
2346 for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++)
2347 if (strncmp (tokstart, tokentab2[i].operator, 2) == 0)
2349 if ((tokentab2[i].flags & FLAG_CXX) != 0
2350 && parse_language->la_language != language_cplus)
2354 yylval.opcode = tokentab2[i].opcode;
2355 if (in_parse_field && tokentab2[i].token == ARROW)
2356 last_was_structop = 1;
2357 return tokentab2[i].token;
2360 switch (c = *tokstart)
2363 /* If we were just scanning the result of a macro expansion,
2364 then we need to resume scanning the original text.
2365 If we're parsing for field name completion, and the previous
2366 token allows such completion, return a COMPLETE token.
2367 Otherwise, we were already scanning the original text, and
2368 we're really done. */
2369 if (scanning_macro_expansion ())
2371 finished_macro_expansion ();
2374 else if (saw_name_at_eof)
2376 saw_name_at_eof = 0;
2379 else if (saw_structop)
2394 if (parse_language->la_language == language_objc && c == '[')
2400 if (paren_depth == 0)
2407 if (comma_terminates
2409 && ! scanning_macro_expansion ())
2415 /* Might be a floating point number. */
2416 if (lexptr[1] < '0' || lexptr[1] > '9')
2419 last_was_structop = 1;
2420 goto symbol; /* Nope, must be a symbol. */
2422 /* FALL THRU into number case. */
2435 /* It's a number. */
2436 int got_dot = 0, got_e = 0, toktype;
2438 int hex = input_radix > 10;
2440 if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
2445 else if (c == '0' && (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))
2453 /* This test includes !hex because 'e' is a valid hex digit
2454 and thus does not indicate a floating point number when
2455 the radix is hex. */
2456 if (!hex && !got_e && (*p == 'e' || *p == 'E'))
2457 got_dot = got_e = 1;
2458 /* This test does not include !hex, because a '.' always indicates
2459 a decimal floating point number regardless of the radix. */
2460 else if (!got_dot && *p == '.')
2462 else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
2463 && (*p == '-' || *p == '+'))
2464 /* This is the sign of the exponent, not the end of the
2467 /* We will take any letters or digits. parse_number will
2468 complain if past the radix, or if L or U are not final. */
2469 else if ((*p < '0' || *p > '9')
2470 && ((*p < 'a' || *p > 'z')
2471 && (*p < 'A' || *p > 'Z')))
2474 toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval);
2475 if (toktype == ERROR)
2477 char *err_copy = (char *) alloca (p - tokstart + 1);
2479 memcpy (err_copy, tokstart, p - tokstart);
2480 err_copy[p - tokstart] = 0;
2481 error (_("Invalid number \"%s\"."), err_copy);
2489 char *p = &tokstart[1];
2490 size_t len = strlen ("entry");
2492 if (parse_language->la_language == language_objc)
2494 size_t len = strlen ("selector");
2496 if (strncmp (p, "selector", len) == 0
2497 && (p[len] == '\0' || isspace (p[len])))
2506 while (isspace (*p))
2508 if (strncmp (p, "entry", len) == 0 && !isalnum (p[len])
2540 if (tokstart[1] != '"' && tokstart[1] != '\'')
2549 int result = parse_string_or_char (tokstart, &lexptr, &yylval.tsval,
2554 error (_("Empty character constant."));
2555 else if (host_len > 2 && c == '\'')
2558 namelen = lexptr - tokstart - 1;
2561 else if (host_len > 1)
2562 error (_("Invalid character constant."));
2568 if (!(c == '_' || c == '$'
2569 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
2570 /* We must have come across a bad character (e.g. ';'). */
2571 error (_("Invalid character '%c' in expression."), c);
2573 /* It's a name. See how long it is. */
2575 for (c = tokstart[namelen];
2576 (c == '_' || c == '$' || (c >= '0' && c <= '9')
2577 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '<');)
2579 /* Template parameter lists are part of the name.
2580 FIXME: This mishandles `print $a<4&&$a>3'. */
2584 if (! is_cast_operator (tokstart, namelen))
2586 /* Scan ahead to get rest of the template specification. Note
2587 that we look ahead only when the '<' adjoins non-whitespace
2588 characters; for comparison expressions, e.g. "a < b > c",
2589 there must be spaces before the '<', etc. */
2591 char * p = find_template_name_end (tokstart + namelen);
2593 namelen = p - tokstart;
2597 c = tokstart[++namelen];
2600 /* The token "if" terminates the expression and is NOT removed from
2601 the input stream. It doesn't count if it appears in the
2602 expansion of a macro. */
2604 && tokstart[0] == 'i'
2605 && tokstart[1] == 'f'
2606 && ! scanning_macro_expansion ())
2611 /* For the same reason (breakpoint conditions), "thread N"
2612 terminates the expression. "thread" could be an identifier, but
2613 an identifier is never followed by a number without intervening
2614 punctuation. "task" is similar. Handle abbreviations of these,
2615 similarly to breakpoint.c:find_condition_and_thread. */
2617 && (strncmp (tokstart, "thread", namelen) == 0
2618 || strncmp (tokstart, "task", namelen) == 0)
2619 && (tokstart[namelen] == ' ' || tokstart[namelen] == '\t')
2620 && ! scanning_macro_expansion ())
2622 char *p = tokstart + namelen + 1;
2623 while (*p == ' ' || *p == '\t')
2625 if (*p >= '0' && *p <= '9')
2633 yylval.sval.ptr = tokstart;
2634 yylval.sval.length = namelen;
2636 /* Catch specific keywords. */
2637 copy = copy_name (yylval.sval);
2638 for (i = 0; i < sizeof ident_tokens / sizeof ident_tokens[0]; i++)
2639 if (strcmp (copy, ident_tokens[i].operator) == 0)
2641 if ((ident_tokens[i].flags & FLAG_CXX) != 0
2642 && parse_language->la_language != language_cplus)
2645 if ((ident_tokens[i].flags & FLAG_SHADOW) != 0)
2647 int is_a_field_of_this = 0;
2649 if (lookup_symbol (copy, expression_context_block,
2651 (parse_language->la_language == language_cplus
2652 ? &is_a_field_of_this
2656 /* The keyword is shadowed. */
2661 /* It is ok to always set this, even though we don't always
2662 strictly need to. */
2663 yylval.opcode = ident_tokens[i].opcode;
2664 return ident_tokens[i].token;
2667 if (*tokstart == '$')
2670 if (in_parse_field && *lexptr == '\0')
2671 saw_name_at_eof = 1;
2675 /* An object of this type is pushed on a FIFO by the "outer" lexer. */
2682 DEF_VEC_O (token_and_value);
2684 /* A FIFO of tokens that have been read but not yet returned to the
2686 static VEC (token_and_value) *token_fifo;
2688 /* Non-zero if the lexer should return tokens from the FIFO. */
2691 /* Temporary storage for c_lex; this holds symbol names as they are
2693 static struct obstack name_obstack;
2695 /* Classify a NAME token. The contents of the token are in `yylval'.
2696 Updates yylval and returns the new token type. BLOCK is the block
2697 in which lookups start; this can be NULL to mean the global
2700 classify_name (struct block *block)
2704 int is_a_field_of_this = 0;
2706 copy = copy_name (yylval.sval);
2708 sym = lookup_symbol (copy, block, VAR_DOMAIN,
2709 parse_language->la_name_of_this
2710 ? &is_a_field_of_this : (int *) NULL);
2712 if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
2714 yylval.ssym.sym = sym;
2715 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
2720 /* See if it's a file name. */
2721 struct symtab *symtab;
2723 symtab = lookup_symtab (copy);
2726 yylval.bval = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), STATIC_BLOCK);
2731 if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
2733 yylval.tsym.type = SYMBOL_TYPE (sym);
2738 = language_lookup_primitive_type_by_name (parse_language,
2739 parse_gdbarch, copy);
2740 if (yylval.tsym.type != NULL)
2743 /* See if it's an ObjC classname. */
2744 if (parse_language->la_language == language_objc && !sym)
2746 CORE_ADDR Class = lookup_objc_class (parse_gdbarch, copy);
2749 yylval.class.class = Class;
2750 if ((sym = lookup_struct_typedef (copy, expression_context_block,
2752 yylval.class.type = SYMBOL_TYPE (sym);
2757 /* Input names that aren't symbols but ARE valid hex numbers, when
2758 the input radix permits them, can be names or numbers depending
2759 on the parse. Note we support radixes > 16 here. */
2761 && ((copy[0] >= 'a' && copy[0] < 'a' + input_radix - 10)
2762 || (copy[0] >= 'A' && copy[0] < 'A' + input_radix - 10)))
2764 YYSTYPE newlval; /* Its value is ignored. */
2765 int hextype = parse_number (copy, yylval.sval.length, 0, &newlval);
2768 yylval.ssym.sym = sym;
2769 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
2774 /* Any other kind of symbol */
2775 yylval.ssym.sym = sym;
2776 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
2779 && parse_language->la_language == language_cplus
2780 && !is_a_field_of_this
2781 && !lookup_minimal_symbol (copy, NULL, NULL))
2782 return UNKNOWN_CPP_NAME;
2787 /* Like classify_name, but used by the inner loop of the lexer, when a
2788 name might have already been seen. FIRST_NAME is true if the token
2789 in `yylval' is the first component of a name, false otherwise. */
2792 classify_inner_name (struct block *block, int first_name)
2794 struct type *type, *new_type;
2798 return classify_name (block);
2800 type = check_typedef (yylval.tsym.type);
2801 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
2802 && TYPE_CODE (type) != TYPE_CODE_UNION
2803 && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
2806 copy = copy_name (yylval.tsym.stoken);
2807 yylval.ssym.sym = cp_lookup_nested_symbol (yylval.tsym.type, copy, block);
2808 if (yylval.ssym.sym == NULL)
2811 switch (SYMBOL_CLASS (yylval.ssym.sym))
2818 yylval.tsym.type = SYMBOL_TYPE (yylval.ssym.sym);;
2822 yylval.ssym.is_a_field_of_this = 0;
2825 internal_error (__FILE__, __LINE__, _("not reached"));
2828 /* The outer level of a two-level lexer. This calls the inner lexer
2829 to return tokens. It then either returns these tokens, or
2830 aggregates them into a larger token. This lets us work around a
2831 problem in our parsing approach, where the parser could not
2832 distinguish between qualified names and qualified types at the
2835 This approach is still not ideal, because it mishandles template
2836 types. See the comment in lex_one_token for an example. However,
2837 this is still an improvement over the earlier approach, and will
2838 suffice until we move to better parsing technology. */
2842 token_and_value current;
2843 int first_was_coloncolon, last_was_coloncolon, first_iter;
2845 if (popping && !VEC_empty (token_and_value, token_fifo))
2847 token_and_value tv = *VEC_index (token_and_value, token_fifo, 0);
2848 VEC_ordered_remove (token_and_value, token_fifo, 0);
2854 current.token = lex_one_token ();
2855 if (current.token == NAME)
2856 current.token = classify_name (expression_context_block);
2857 if (parse_language->la_language != language_cplus
2858 || (current.token != TYPENAME && current.token != COLONCOLON))
2859 return current.token;
2861 first_was_coloncolon = current.token == COLONCOLON;
2862 last_was_coloncolon = first_was_coloncolon;
2863 obstack_free (&name_obstack, obstack_base (&name_obstack));
2864 if (!last_was_coloncolon)
2865 obstack_grow (&name_obstack, yylval.sval.ptr, yylval.sval.length);
2866 current.value = yylval;
2870 token_and_value next;
2872 next.token = lex_one_token ();
2873 next.value = yylval;
2875 if (next.token == NAME && last_was_coloncolon)
2879 classification = classify_inner_name (first_was_coloncolon
2881 : expression_context_block,
2883 /* We keep going until we either run out of names, or until
2884 we have a qualified name which is not a type. */
2885 if (classification != TYPENAME && classification != NAME)
2887 /* Push the final component and leave the loop. */
2888 VEC_safe_push (token_and_value, token_fifo, &next);
2892 /* Update the partial name we are constructing. */
2895 /* We don't want to put a leading "::" into the name. */
2896 obstack_grow_str (&name_obstack, "::");
2898 obstack_grow (&name_obstack, next.value.sval.ptr,
2899 next.value.sval.length);
2901 yylval.sval.ptr = obstack_base (&name_obstack);
2902 yylval.sval.length = obstack_object_size (&name_obstack);
2903 current.value = yylval;
2904 current.token = classification;
2906 last_was_coloncolon = 0;
2908 else if (next.token == COLONCOLON && !last_was_coloncolon)
2909 last_was_coloncolon = 1;
2912 /* We've reached the end of the name. */
2913 VEC_safe_push (token_and_value, token_fifo, &next);
2922 /* If we ended with a "::", insert it too. */
2923 if (last_was_coloncolon)
2926 memset (&cc, 0, sizeof (token_and_value));
2927 if (first_was_coloncolon && first_iter)
2932 cc.token = COLONCOLON;
2933 VEC_safe_insert (token_and_value, token_fifo, 0, &cc);
2936 yylval = current.value;
2937 yylval.sval.ptr = obstack_copy0 (&expansion_obstack,
2939 yylval.sval.length);
2940 return current.token;
2947 struct cleanup *back_to = make_cleanup (free_current_contents,
2948 &expression_macro_scope);
2950 /* Set up the scope for macro expansion. */
2951 expression_macro_scope = NULL;
2953 if (expression_context_block)
2954 expression_macro_scope
2955 = sal_macro_scope (find_pc_line (expression_context_pc, 0));
2957 expression_macro_scope = default_macro_scope ();
2958 if (! expression_macro_scope)
2959 expression_macro_scope = user_macro_scope ();
2961 /* Initialize macro expansion code. */
2962 obstack_init (&expansion_obstack);
2963 gdb_assert (! macro_original_text);
2964 make_cleanup (scan_macro_cleanup, 0);
2966 make_cleanup_restore_integer (&yydebug);
2967 yydebug = parser_debug;
2969 /* Initialize some state used by the lexer. */
2970 last_was_structop = 0;
2971 saw_name_at_eof = 0;
2973 VEC_free (token_and_value, token_fifo);
2975 obstack_init (&name_obstack);
2976 make_cleanup_obstack_free (&name_obstack);
2978 result = yyparse ();
2979 do_cleanups (back_to);
2988 lexptr = prev_lexptr;
2990 error (_("A %s in expression, near `%s'."), (msg ? msg : "error"), lexptr);