* c-exp.y (enum token_flags): New.
[platform/upstream/binutils.git] / gdb / c-exp.y
1 /* YACC parser for C expressions, for GDB.
2    Copyright (C) 1986, 1989-2000, 2003-2004, 2006-2012 Free Software
3    Foundation, Inc.
4
5    This file is part of GDB.
6
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.
11
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.
16
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/>.  */
19
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.
28
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.  */
36    
37 %{
38
39 #include "defs.h"
40 #include "gdb_string.h"
41 #include <ctype.h>
42 #include "expression.h"
43 #include "value.h"
44 #include "parser-defs.h"
45 #include "language.h"
46 #include "c-lang.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 */
50 #include "charset.h"
51 #include "block.h"
52 #include "cp-support.h"
53 #include "dfp.h"
54 #include "gdb_assert.h"
55 #include "macroscope.h"
56
57 #define parse_type builtin_type (parse_gdbarch)
58
59 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
60    as well as gratuitiously global symbol names, so we can have multiple
61    yacc generated parsers in gdb.  Note that these are only the variables
62    produced by yacc.  If other parser generators (bison, byacc, etc) produce
63    additional global names that conflict at link time, then those parser
64    generators need to be fixed instead of adding those names to this list. */
65
66 #define yymaxdepth c_maxdepth
67 #define yyparse c_parse_internal
68 #define yylex   c_lex
69 #define yyerror c_error
70 #define yylval  c_lval
71 #define yychar  c_char
72 #define yydebug c_debug
73 #define yypact  c_pact  
74 #define yyr1    c_r1                    
75 #define yyr2    c_r2                    
76 #define yydef   c_def           
77 #define yychk   c_chk           
78 #define yypgo   c_pgo           
79 #define yyact   c_act           
80 #define yyexca  c_exca
81 #define yyerrflag c_errflag
82 #define yynerrs c_nerrs
83 #define yyps    c_ps
84 #define yypv    c_pv
85 #define yys     c_s
86 #define yy_yys  c_yys
87 #define yystate c_state
88 #define yytmp   c_tmp
89 #define yyv     c_v
90 #define yy_yyv  c_yyv
91 #define yyval   c_val
92 #define yylloc  c_lloc
93 #define yyreds  c_reds          /* With YYDEBUG defined */
94 #define yytoks  c_toks          /* With YYDEBUG defined */
95 #define yyname  c_name          /* With YYDEBUG defined */
96 #define yyrule  c_rule          /* With YYDEBUG defined */
97 #define yylhs   c_yylhs
98 #define yylen   c_yylen
99 #define yydefred c_yydefred
100 #define yydgoto c_yydgoto
101 #define yysindex c_yysindex
102 #define yyrindex c_yyrindex
103 #define yygindex c_yygindex
104 #define yytable  c_yytable
105 #define yycheck  c_yycheck
106 #define yyss    c_yyss
107 #define yysslim c_yysslim
108 #define yyssp   c_yyssp
109 #define yystacksize c_yystacksize
110 #define yyvs    c_yyvs
111 #define yyvsp   c_yyvsp
112
113 #ifndef YYDEBUG
114 #define YYDEBUG 1               /* Default to yydebug support */
115 #endif
116
117 #define YYFPRINTF parser_fprintf
118
119 int yyparse (void);
120
121 static int yylex (void);
122
123 void yyerror (char *);
124
125 %}
126
127 /* Although the yacc "value" of an expression is not used,
128    since the result is stored in the structure being created,
129    other node types do have values.  */
130
131 %union
132   {
133     LONGEST lval;
134     struct {
135       LONGEST val;
136       struct type *type;
137     } typed_val_int;
138     struct {
139       DOUBLEST dval;
140       struct type *type;
141     } typed_val_float;
142     struct {
143       gdb_byte val[16];
144       struct type *type;
145     } typed_val_decfloat;
146     struct symbol *sym;
147     struct type *tval;
148     struct stoken sval;
149     struct typed_stoken tsval;
150     struct ttype tsym;
151     struct symtoken ssym;
152     int voidval;
153     struct block *bval;
154     enum exp_opcode opcode;
155     struct internalvar *ivar;
156
157     struct stoken_vector svec;
158     VEC (type_ptr) *tvec;
159     int *ivec;
160
161     struct type_stack *type_stack;
162   }
163
164 %{
165 /* YYSTYPE gets defined by %union */
166 static int parse_number (char *, int, int, YYSTYPE *);
167 static struct stoken operator_stoken (const char *);
168 static void check_parameter_typelist (VEC (type_ptr) *);
169 %}
170
171 %type <voidval> exp exp1 type_exp start variable qualified_name lcurly
172 %type <lval> rcurly
173 %type <tval> type typebase
174 %type <tvec> nonempty_typelist func_mod parameter_typelist
175 /* %type <bval> block */
176
177 /* Fancy type parsing.  */
178 %type <tval> ptype
179 %type <lval> array_mod
180 %type <tval> conversion_type_id
181
182 %type <type_stack> ptr_operator_ts abs_decl direct_abs_decl
183
184 %token <typed_val_int> INT
185 %token <typed_val_float> FLOAT
186 %token <typed_val_decfloat> DECFLOAT
187
188 /* Both NAME and TYPENAME tokens represent symbols in the input,
189    and both convey their data as strings.
190    But a TYPENAME is a string that happens to be defined as a typedef
191    or builtin type name (such as int or char)
192    and a NAME is any other symbol.
193    Contexts where this distinction is not important can use the
194    nonterminal "name", which matches either NAME or TYPENAME.  */
195
196 %token <tsval> STRING
197 %token <tsval> CHAR
198 %token <ssym> NAME /* BLOCKNAME defined below to give it higher precedence. */
199 %token <ssym> UNKNOWN_CPP_NAME
200 %token <voidval> COMPLETE
201 %token <tsym> TYPENAME
202 %type <sval> name
203 %type <svec> string_exp
204 %type <ssym> name_not_typename
205 %type <tsym> typename
206
207 /* A NAME_OR_INT is a symbol which is not known in the symbol table,
208    but which would parse as a valid number in the current input radix.
209    E.g. "c" when input_radix==16.  Depending on the parse, it will be
210    turned into a name or into a number.  */
211
212 %token <ssym> NAME_OR_INT 
213
214 %token OPERATOR
215 %token STRUCT CLASS UNION ENUM SIZEOF UNSIGNED COLONCOLON
216 %token TEMPLATE
217 %token ERROR
218 %token NEW DELETE
219 %type <sval> operator
220 %token REINTERPRET_CAST DYNAMIC_CAST STATIC_CAST CONST_CAST
221 %token ENTRY
222
223 /* Special type cases, put in to allow the parser to distinguish different
224    legal basetypes.  */
225 %token SIGNED_KEYWORD LONG SHORT INT_KEYWORD CONST_KEYWORD VOLATILE_KEYWORD DOUBLE_KEYWORD
226
227 %token <sval> VARIABLE
228
229 %token <opcode> ASSIGN_MODIFY
230
231 /* C++ */
232 %token TRUEKEYWORD
233 %token FALSEKEYWORD
234
235
236 %left ','
237 %left ABOVE_COMMA
238 %right '=' ASSIGN_MODIFY
239 %right '?'
240 %left OROR
241 %left ANDAND
242 %left '|'
243 %left '^'
244 %left '&'
245 %left EQUAL NOTEQUAL
246 %left '<' '>' LEQ GEQ
247 %left LSH RSH
248 %left '@'
249 %left '+' '-'
250 %left '*' '/' '%'
251 %right UNARY INCREMENT DECREMENT
252 %right ARROW ARROW_STAR '.' DOT_STAR '[' '('
253 %token <ssym> BLOCKNAME 
254 %token <bval> FILENAME
255 %type <bval> block
256 %left COLONCOLON
257
258 %token DOTDOTDOT
259
260 \f
261 %%
262
263 start   :       exp1
264         |       type_exp
265         ;
266
267 type_exp:       type
268                         { write_exp_elt_opcode(OP_TYPE);
269                           write_exp_elt_type($1);
270                           write_exp_elt_opcode(OP_TYPE);}
271         ;
272
273 /* Expressions, including the comma operator.  */
274 exp1    :       exp
275         |       exp1 ',' exp
276                         { write_exp_elt_opcode (BINOP_COMMA); }
277         ;
278
279 /* Expressions, not including the comma operator.  */
280 exp     :       '*' exp    %prec UNARY
281                         { write_exp_elt_opcode (UNOP_IND); }
282         ;
283
284 exp     :       '&' exp    %prec UNARY
285                         { write_exp_elt_opcode (UNOP_ADDR); }
286         ;
287
288 exp     :       '-' exp    %prec UNARY
289                         { write_exp_elt_opcode (UNOP_NEG); }
290         ;
291
292 exp     :       '+' exp    %prec UNARY
293                         { write_exp_elt_opcode (UNOP_PLUS); }
294         ;
295
296 exp     :       '!' exp    %prec UNARY
297                         { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
298         ;
299
300 exp     :       '~' exp    %prec UNARY
301                         { write_exp_elt_opcode (UNOP_COMPLEMENT); }
302         ;
303
304 exp     :       INCREMENT exp    %prec UNARY
305                         { write_exp_elt_opcode (UNOP_PREINCREMENT); }
306         ;
307
308 exp     :       DECREMENT exp    %prec UNARY
309                         { write_exp_elt_opcode (UNOP_PREDECREMENT); }
310         ;
311
312 exp     :       exp INCREMENT    %prec UNARY
313                         { write_exp_elt_opcode (UNOP_POSTINCREMENT); }
314         ;
315
316 exp     :       exp DECREMENT    %prec UNARY
317                         { write_exp_elt_opcode (UNOP_POSTDECREMENT); }
318         ;
319
320 exp     :       SIZEOF exp       %prec UNARY
321                         { write_exp_elt_opcode (UNOP_SIZEOF); }
322         ;
323
324 exp     :       exp ARROW name
325                         { write_exp_elt_opcode (STRUCTOP_PTR);
326                           write_exp_string ($3);
327                           write_exp_elt_opcode (STRUCTOP_PTR); }
328         ;
329
330 exp     :       exp ARROW name COMPLETE
331                         { mark_struct_expression ();
332                           write_exp_elt_opcode (STRUCTOP_PTR);
333                           write_exp_string ($3);
334                           write_exp_elt_opcode (STRUCTOP_PTR); }
335         ;
336
337 exp     :       exp ARROW COMPLETE
338                         { struct stoken s;
339                           mark_struct_expression ();
340                           write_exp_elt_opcode (STRUCTOP_PTR);
341                           s.ptr = "";
342                           s.length = 0;
343                           write_exp_string (s);
344                           write_exp_elt_opcode (STRUCTOP_PTR); }
345         ;
346
347 exp     :       exp ARROW qualified_name
348                         { /* exp->type::name becomes exp->*(&type::name) */
349                           /* Note: this doesn't work if name is a
350                              static member!  FIXME */
351                           write_exp_elt_opcode (UNOP_ADDR);
352                           write_exp_elt_opcode (STRUCTOP_MPTR); }
353         ;
354
355 exp     :       exp ARROW_STAR exp
356                         { write_exp_elt_opcode (STRUCTOP_MPTR); }
357         ;
358
359 exp     :       exp '.' name
360                         { write_exp_elt_opcode (STRUCTOP_STRUCT);
361                           write_exp_string ($3);
362                           write_exp_elt_opcode (STRUCTOP_STRUCT); }
363         ;
364
365 exp     :       exp '.' name COMPLETE
366                         { mark_struct_expression ();
367                           write_exp_elt_opcode (STRUCTOP_STRUCT);
368                           write_exp_string ($3);
369                           write_exp_elt_opcode (STRUCTOP_STRUCT); }
370         ;
371
372 exp     :       exp '.' COMPLETE
373                         { struct stoken s;
374                           mark_struct_expression ();
375                           write_exp_elt_opcode (STRUCTOP_STRUCT);
376                           s.ptr = "";
377                           s.length = 0;
378                           write_exp_string (s);
379                           write_exp_elt_opcode (STRUCTOP_STRUCT); }
380         ;
381
382 exp     :       exp '.' qualified_name
383                         { /* exp.type::name becomes exp.*(&type::name) */
384                           /* Note: this doesn't work if name is a
385                              static member!  FIXME */
386                           write_exp_elt_opcode (UNOP_ADDR);
387                           write_exp_elt_opcode (STRUCTOP_MEMBER); }
388         ;
389
390 exp     :       exp DOT_STAR exp
391                         { write_exp_elt_opcode (STRUCTOP_MEMBER); }
392         ;
393
394 exp     :       exp '[' exp1 ']'
395                         { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
396         ;
397
398 exp     :       exp '(' 
399                         /* This is to save the value of arglist_len
400                            being accumulated by an outer function call.  */
401                         { start_arglist (); }
402                 arglist ')'     %prec ARROW
403                         { write_exp_elt_opcode (OP_FUNCALL);
404                           write_exp_elt_longcst ((LONGEST) end_arglist ());
405                           write_exp_elt_opcode (OP_FUNCALL); }
406         ;
407
408 exp     :       UNKNOWN_CPP_NAME '('
409                         {
410                           /* This could potentially be a an argument defined
411                              lookup function (Koenig).  */
412                           write_exp_elt_opcode (OP_ADL_FUNC);
413                           write_exp_elt_block (expression_context_block);
414                           write_exp_elt_sym (NULL); /* Placeholder.  */
415                           write_exp_string ($1.stoken);
416                           write_exp_elt_opcode (OP_ADL_FUNC);
417
418                         /* This is to save the value of arglist_len
419                            being accumulated by an outer function call.  */
420
421                           start_arglist ();
422                         }
423                 arglist ')'     %prec ARROW
424                         {
425                           write_exp_elt_opcode (OP_FUNCALL);
426                           write_exp_elt_longcst ((LONGEST) end_arglist ());
427                           write_exp_elt_opcode (OP_FUNCALL);
428                         }
429         ;
430
431 lcurly  :       '{'
432                         { start_arglist (); }
433         ;
434
435 arglist :
436         ;
437
438 arglist :       exp
439                         { arglist_len = 1; }
440         ;
441
442 arglist :       arglist ',' exp   %prec ABOVE_COMMA
443                         { arglist_len++; }
444         ;
445
446 exp     :       exp '(' parameter_typelist ')' const_or_volatile
447                         { int i;
448                           VEC (type_ptr) *type_list = $3;
449                           struct type *type_elt;
450                           LONGEST len = VEC_length (type_ptr, type_list);
451
452                           write_exp_elt_opcode (TYPE_INSTANCE);
453                           write_exp_elt_longcst (len);
454                           for (i = 0;
455                                VEC_iterate (type_ptr, type_list, i, type_elt);
456                                ++i)
457                             write_exp_elt_type (type_elt);
458                           write_exp_elt_longcst(len);
459                           write_exp_elt_opcode (TYPE_INSTANCE);
460                           VEC_free (type_ptr, type_list);
461                         }
462         ;
463
464 rcurly  :       '}'
465                         { $$ = end_arglist () - 1; }
466         ;
467 exp     :       lcurly arglist rcurly   %prec ARROW
468                         { write_exp_elt_opcode (OP_ARRAY);
469                           write_exp_elt_longcst ((LONGEST) 0);
470                           write_exp_elt_longcst ((LONGEST) $3);
471                           write_exp_elt_opcode (OP_ARRAY); }
472         ;
473
474 exp     :       lcurly type_exp rcurly exp  %prec UNARY
475                         { write_exp_elt_opcode (UNOP_MEMVAL_TYPE); }
476         ;
477
478 exp     :       '(' type_exp ')' exp  %prec UNARY
479                         { write_exp_elt_opcode (UNOP_CAST_TYPE); }
480         ;
481
482 exp     :       '(' exp1 ')'
483                         { }
484         ;
485
486 /* Binary operators in order of decreasing precedence.  */
487
488 exp     :       exp '@' exp
489                         { write_exp_elt_opcode (BINOP_REPEAT); }
490         ;
491
492 exp     :       exp '*' exp
493                         { write_exp_elt_opcode (BINOP_MUL); }
494         ;
495
496 exp     :       exp '/' exp
497                         { write_exp_elt_opcode (BINOP_DIV); }
498         ;
499
500 exp     :       exp '%' exp
501                         { write_exp_elt_opcode (BINOP_REM); }
502         ;
503
504 exp     :       exp '+' exp
505                         { write_exp_elt_opcode (BINOP_ADD); }
506         ;
507
508 exp     :       exp '-' exp
509                         { write_exp_elt_opcode (BINOP_SUB); }
510         ;
511
512 exp     :       exp LSH exp
513                         { write_exp_elt_opcode (BINOP_LSH); }
514         ;
515
516 exp     :       exp RSH exp
517                         { write_exp_elt_opcode (BINOP_RSH); }
518         ;
519
520 exp     :       exp EQUAL exp
521                         { write_exp_elt_opcode (BINOP_EQUAL); }
522         ;
523
524 exp     :       exp NOTEQUAL exp
525                         { write_exp_elt_opcode (BINOP_NOTEQUAL); }
526         ;
527
528 exp     :       exp LEQ exp
529                         { write_exp_elt_opcode (BINOP_LEQ); }
530         ;
531
532 exp     :       exp GEQ exp
533                         { write_exp_elt_opcode (BINOP_GEQ); }
534         ;
535
536 exp     :       exp '<' exp
537                         { write_exp_elt_opcode (BINOP_LESS); }
538         ;
539
540 exp     :       exp '>' exp
541                         { write_exp_elt_opcode (BINOP_GTR); }
542         ;
543
544 exp     :       exp '&' exp
545                         { write_exp_elt_opcode (BINOP_BITWISE_AND); }
546         ;
547
548 exp     :       exp '^' exp
549                         { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
550         ;
551
552 exp     :       exp '|' exp
553                         { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
554         ;
555
556 exp     :       exp ANDAND exp
557                         { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
558         ;
559
560 exp     :       exp OROR exp
561                         { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
562         ;
563
564 exp     :       exp '?' exp ':' exp     %prec '?'
565                         { write_exp_elt_opcode (TERNOP_COND); }
566         ;
567                           
568 exp     :       exp '=' exp
569                         { write_exp_elt_opcode (BINOP_ASSIGN); }
570         ;
571
572 exp     :       exp ASSIGN_MODIFY exp
573                         { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY);
574                           write_exp_elt_opcode ($2);
575                           write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); }
576         ;
577
578 exp     :       INT
579                         { write_exp_elt_opcode (OP_LONG);
580                           write_exp_elt_type ($1.type);
581                           write_exp_elt_longcst ((LONGEST)($1.val));
582                           write_exp_elt_opcode (OP_LONG); }
583         ;
584
585 exp     :       CHAR
586                         {
587                           struct stoken_vector vec;
588                           vec.len = 1;
589                           vec.tokens = &$1;
590                           write_exp_string_vector ($1.type, &vec);
591                         }
592         ;
593
594 exp     :       NAME_OR_INT
595                         { YYSTYPE val;
596                           parse_number ($1.stoken.ptr, $1.stoken.length, 0, &val);
597                           write_exp_elt_opcode (OP_LONG);
598                           write_exp_elt_type (val.typed_val_int.type);
599                           write_exp_elt_longcst ((LONGEST)val.typed_val_int.val);
600                           write_exp_elt_opcode (OP_LONG);
601                         }
602         ;
603
604
605 exp     :       FLOAT
606                         { write_exp_elt_opcode (OP_DOUBLE);
607                           write_exp_elt_type ($1.type);
608                           write_exp_elt_dblcst ($1.dval);
609                           write_exp_elt_opcode (OP_DOUBLE); }
610         ;
611
612 exp     :       DECFLOAT
613                         { write_exp_elt_opcode (OP_DECFLOAT);
614                           write_exp_elt_type ($1.type);
615                           write_exp_elt_decfloatcst ($1.val);
616                           write_exp_elt_opcode (OP_DECFLOAT); }
617         ;
618
619 exp     :       variable
620         ;
621
622 exp     :       VARIABLE
623                         {
624                           write_dollar_variable ($1);
625                         }
626         ;
627
628 exp     :       SIZEOF '(' type ')'     %prec UNARY
629                         { write_exp_elt_opcode (OP_LONG);
630                           write_exp_elt_type (lookup_signed_typename
631                                               (parse_language, parse_gdbarch,
632                                                "int"));
633                           CHECK_TYPEDEF ($3);
634                           write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
635                           write_exp_elt_opcode (OP_LONG); }
636         ;
637
638 exp     :       REINTERPRET_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
639                         { write_exp_elt_opcode (UNOP_REINTERPRET_CAST); }
640         ;
641
642 exp     :       STATIC_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
643                         { write_exp_elt_opcode (UNOP_CAST_TYPE); }
644         ;
645
646 exp     :       DYNAMIC_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
647                         { write_exp_elt_opcode (UNOP_DYNAMIC_CAST); }
648         ;
649
650 exp     :       CONST_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
651                         { /* We could do more error checking here, but
652                              it doesn't seem worthwhile.  */
653                           write_exp_elt_opcode (UNOP_CAST_TYPE); }
654         ;
655
656 string_exp:
657                 STRING
658                         {
659                           /* We copy the string here, and not in the
660                              lexer, to guarantee that we do not leak a
661                              string.  Note that we follow the
662                              NUL-termination convention of the
663                              lexer.  */
664                           struct typed_stoken *vec = XNEW (struct typed_stoken);
665                           $$.len = 1;
666                           $$.tokens = vec;
667
668                           vec->type = $1.type;
669                           vec->length = $1.length;
670                           vec->ptr = malloc ($1.length + 1);
671                           memcpy (vec->ptr, $1.ptr, $1.length + 1);
672                         }
673
674         |       string_exp STRING
675                         {
676                           /* Note that we NUL-terminate here, but just
677                              for convenience.  */
678                           char *p;
679                           ++$$.len;
680                           $$.tokens = realloc ($$.tokens,
681                                                $$.len * sizeof (struct typed_stoken));
682
683                           p = malloc ($2.length + 1);
684                           memcpy (p, $2.ptr, $2.length + 1);
685
686                           $$.tokens[$$.len - 1].type = $2.type;
687                           $$.tokens[$$.len - 1].length = $2.length;
688                           $$.tokens[$$.len - 1].ptr = p;
689                         }
690                 ;
691
692 exp     :       string_exp
693                         {
694                           int i;
695                           enum c_string_type type = C_STRING;
696
697                           for (i = 0; i < $1.len; ++i)
698                             {
699                               switch ($1.tokens[i].type)
700                                 {
701                                 case C_STRING:
702                                   break;
703                                 case C_WIDE_STRING:
704                                 case C_STRING_16:
705                                 case C_STRING_32:
706                                   if (type != C_STRING
707                                       && type != $1.tokens[i].type)
708                                     error (_("Undefined string concatenation."));
709                                   type = $1.tokens[i].type;
710                                   break;
711                                 default:
712                                   /* internal error */
713                                   internal_error (__FILE__, __LINE__,
714                                                   "unrecognized type in string concatenation");
715                                 }
716                             }
717
718                           write_exp_string_vector (type, &$1);
719                           for (i = 0; i < $1.len; ++i)
720                             free ($1.tokens[i].ptr);
721                           free ($1.tokens);
722                         }
723         ;
724
725 /* C++.  */
726 exp     :       TRUEKEYWORD    
727                         { write_exp_elt_opcode (OP_LONG);
728                           write_exp_elt_type (parse_type->builtin_bool);
729                           write_exp_elt_longcst ((LONGEST) 1);
730                           write_exp_elt_opcode (OP_LONG); }
731         ;
732
733 exp     :       FALSEKEYWORD   
734                         { write_exp_elt_opcode (OP_LONG);
735                           write_exp_elt_type (parse_type->builtin_bool);
736                           write_exp_elt_longcst ((LONGEST) 0);
737                           write_exp_elt_opcode (OP_LONG); }
738         ;
739
740 /* end of C++.  */
741
742 block   :       BLOCKNAME
743                         {
744                           if ($1.sym)
745                             $$ = SYMBOL_BLOCK_VALUE ($1.sym);
746                           else
747                             error (_("No file or function \"%s\"."),
748                                    copy_name ($1.stoken));
749                         }
750         |       FILENAME
751                         {
752                           $$ = $1;
753                         }
754         ;
755
756 block   :       block COLONCOLON name
757                         { struct symbol *tem
758                             = lookup_symbol (copy_name ($3), $1,
759                                              VAR_DOMAIN, (int *) NULL);
760                           if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
761                             error (_("No function \"%s\" in specified context."),
762                                    copy_name ($3));
763                           $$ = SYMBOL_BLOCK_VALUE (tem); }
764         ;
765
766 variable:       name_not_typename ENTRY
767                         { struct symbol *sym = $1.sym;
768
769                           if (sym == NULL || !SYMBOL_IS_ARGUMENT (sym)
770                               || !symbol_read_needs_frame (sym))
771                             error (_("@entry can be used only for function "
772                                      "parameters, not for \"%s\""),
773                                    copy_name ($1.stoken));
774
775                           write_exp_elt_opcode (OP_VAR_ENTRY_VALUE);
776                           write_exp_elt_sym (sym);
777                           write_exp_elt_opcode (OP_VAR_ENTRY_VALUE);
778                         }
779         ;
780
781 variable:       block COLONCOLON name
782                         { struct symbol *sym;
783                           sym = lookup_symbol (copy_name ($3), $1,
784                                                VAR_DOMAIN, (int *) NULL);
785                           if (sym == 0)
786                             error (_("No symbol \"%s\" in specified context."),
787                                    copy_name ($3));
788                           if (symbol_read_needs_frame (sym))
789                             {
790                               if (innermost_block == 0
791                                   || contained_in (block_found,
792                                                    innermost_block))
793                                 innermost_block = block_found;
794                             }
795
796                           write_exp_elt_opcode (OP_VAR_VALUE);
797                           /* block_found is set by lookup_symbol.  */
798                           write_exp_elt_block (block_found);
799                           write_exp_elt_sym (sym);
800                           write_exp_elt_opcode (OP_VAR_VALUE); }
801         ;
802
803 qualified_name: TYPENAME COLONCOLON name
804                         {
805                           struct type *type = $1.type;
806                           CHECK_TYPEDEF (type);
807                           if (TYPE_CODE (type) != TYPE_CODE_STRUCT
808                               && TYPE_CODE (type) != TYPE_CODE_UNION
809                               && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
810                             error (_("`%s' is not defined as an aggregate type."),
811                                    TYPE_NAME (type));
812
813                           write_exp_elt_opcode (OP_SCOPE);
814                           write_exp_elt_type (type);
815                           write_exp_string ($3);
816                           write_exp_elt_opcode (OP_SCOPE);
817                         }
818         |       TYPENAME COLONCOLON '~' name
819                         {
820                           struct type *type = $1.type;
821                           struct stoken tmp_token;
822                           CHECK_TYPEDEF (type);
823                           if (TYPE_CODE (type) != TYPE_CODE_STRUCT
824                               && TYPE_CODE (type) != TYPE_CODE_UNION
825                               && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
826                             error (_("`%s' is not defined as an aggregate type."),
827                                    TYPE_NAME (type));
828
829                           tmp_token.ptr = (char*) alloca ($4.length + 2);
830                           tmp_token.length = $4.length + 1;
831                           tmp_token.ptr[0] = '~';
832                           memcpy (tmp_token.ptr+1, $4.ptr, $4.length);
833                           tmp_token.ptr[tmp_token.length] = 0;
834
835                           /* Check for valid destructor name.  */
836                           destructor_name_p (tmp_token.ptr, $1.type);
837                           write_exp_elt_opcode (OP_SCOPE);
838                           write_exp_elt_type (type);
839                           write_exp_string (tmp_token);
840                           write_exp_elt_opcode (OP_SCOPE);
841                         }
842         |       TYPENAME COLONCOLON name COLONCOLON name
843                         {
844                           char *copy = copy_name ($3);
845                           error (_("No type \"%s\" within class "
846                                    "or namespace \"%s\"."),
847                                  copy, TYPE_NAME ($1.type));
848                         }
849         ;
850
851 variable:       qualified_name
852         |       COLONCOLON name_not_typename
853                         {
854                           char *name = copy_name ($2.stoken);
855                           struct symbol *sym;
856                           struct minimal_symbol *msymbol;
857
858                           sym =
859                             lookup_symbol (name, (const struct block *) NULL,
860                                            VAR_DOMAIN, (int *) NULL);
861                           if (sym)
862                             {
863                               write_exp_elt_opcode (OP_VAR_VALUE);
864                               write_exp_elt_block (NULL);
865                               write_exp_elt_sym (sym);
866                               write_exp_elt_opcode (OP_VAR_VALUE);
867                               break;
868                             }
869
870                           msymbol = lookup_minimal_symbol (name, NULL, NULL);
871                           if (msymbol != NULL)
872                             write_exp_msymbol (msymbol);
873                           else if (!have_full_symbols () && !have_partial_symbols ())
874                             error (_("No symbol table is loaded.  Use the \"file\" command."));
875                           else
876                             error (_("No symbol \"%s\" in current context."), name);
877                         }
878         ;
879
880 variable:       name_not_typename
881                         { struct symbol *sym = $1.sym;
882
883                           if (sym)
884                             {
885                               if (symbol_read_needs_frame (sym))
886                                 {
887                                   if (innermost_block == 0
888                                       || contained_in (block_found, 
889                                                        innermost_block))
890                                     innermost_block = block_found;
891                                 }
892
893                               write_exp_elt_opcode (OP_VAR_VALUE);
894                               /* We want to use the selected frame, not
895                                  another more inner frame which happens to
896                                  be in the same block.  */
897                               write_exp_elt_block (NULL);
898                               write_exp_elt_sym (sym);
899                               write_exp_elt_opcode (OP_VAR_VALUE);
900                             }
901                           else if ($1.is_a_field_of_this)
902                             {
903                               /* C++: it hangs off of `this'.  Must
904                                  not inadvertently convert from a method call
905                                  to data ref.  */
906                               if (innermost_block == 0
907                                   || contained_in (block_found,
908                                                    innermost_block))
909                                 innermost_block = block_found;
910                               write_exp_elt_opcode (OP_THIS);
911                               write_exp_elt_opcode (OP_THIS);
912                               write_exp_elt_opcode (STRUCTOP_PTR);
913                               write_exp_string ($1.stoken);
914                               write_exp_elt_opcode (STRUCTOP_PTR);
915                             }
916                           else
917                             {
918                               struct minimal_symbol *msymbol;
919                               char *arg = copy_name ($1.stoken);
920
921                               msymbol =
922                                 lookup_minimal_symbol (arg, NULL, NULL);
923                               if (msymbol != NULL)
924                                 write_exp_msymbol (msymbol);
925                               else if (!have_full_symbols () && !have_partial_symbols ())
926                                 error (_("No symbol table is loaded.  Use the \"file\" command."));
927                               else
928                                 error (_("No symbol \"%s\" in current context."),
929                                        copy_name ($1.stoken));
930                             }
931                         }
932         ;
933
934 space_identifier : '@' NAME
935                 { insert_type_address_space (copy_name ($2.stoken)); }
936         ;
937
938 const_or_volatile: const_or_volatile_noopt
939         |
940         ;
941
942 cv_with_space_id : const_or_volatile space_identifier const_or_volatile
943         ;
944
945 const_or_volatile_or_space_identifier_noopt: cv_with_space_id
946         | const_or_volatile_noopt 
947         ;
948
949 const_or_volatile_or_space_identifier: 
950                 const_or_volatile_or_space_identifier_noopt
951         |
952         ;
953
954 ptr_operator:
955                 ptr_operator '*'
956                         { insert_type (tp_pointer); }
957                 const_or_volatile_or_space_identifier
958         |       '*' 
959                         { insert_type (tp_pointer); }
960                 const_or_volatile_or_space_identifier
961         |       '&'
962                         { insert_type (tp_reference); }
963         |       '&' ptr_operator
964                         { insert_type (tp_reference); }
965         ;
966
967 ptr_operator_ts: ptr_operator
968                         {
969                           $$ = get_type_stack ();
970                           /* This cleanup is eventually run by
971                              c_parse.  */
972                           make_cleanup (type_stack_cleanup, $$);
973                         }
974         ;
975
976 abs_decl:       ptr_operator_ts direct_abs_decl
977                         { $$ = append_type_stack ($2, $1); }
978         |       ptr_operator_ts 
979         |       direct_abs_decl
980         ;
981
982 direct_abs_decl: '(' abs_decl ')'
983                         { $$ = $2; }
984         |       direct_abs_decl array_mod
985                         {
986                           push_type_stack ($1);
987                           push_type_int ($2);
988                           push_type (tp_array);
989                           $$ = get_type_stack ();
990                         }
991         |       array_mod
992                         {
993                           push_type_int ($1);
994                           push_type (tp_array);
995                           $$ = get_type_stack ();
996                         }
997
998         |       direct_abs_decl func_mod
999                         {
1000                           push_type_stack ($1);
1001                           push_typelist ($2);
1002                           $$ = get_type_stack ();
1003                         }
1004         |       func_mod
1005                         {
1006                           push_typelist ($1);
1007                           $$ = get_type_stack ();
1008                         }
1009         ;
1010
1011 array_mod:      '[' ']'
1012                         { $$ = -1; }
1013         |       '[' INT ']'
1014                         { $$ = $2.val; }
1015         ;
1016
1017 func_mod:       '(' ')'
1018                         { $$ = NULL; }
1019         |       '(' parameter_typelist ')'
1020                         { $$ = $2; }
1021         ;
1022
1023 /* We used to try to recognize pointer to member types here, but
1024    that didn't work (shift/reduce conflicts meant that these rules never
1025    got executed).  The problem is that
1026      int (foo::bar::baz::bizzle)
1027    is a function type but
1028      int (foo::bar::baz::bizzle::*)
1029    is a pointer to member type.  Stroustrup loses again!  */
1030
1031 type    :       ptype
1032         ;
1033
1034 typebase  /* Implements (approximately): (type-qualifier)* type-specifier */
1035         :       TYPENAME
1036                         { $$ = $1.type; }
1037         |       INT_KEYWORD
1038                         { $$ = lookup_signed_typename (parse_language,
1039                                                        parse_gdbarch,
1040                                                        "int"); }
1041         |       LONG
1042                         { $$ = lookup_signed_typename (parse_language,
1043                                                        parse_gdbarch,
1044                                                        "long"); }
1045         |       SHORT
1046                         { $$ = lookup_signed_typename (parse_language,
1047                                                        parse_gdbarch,
1048                                                        "short"); }
1049         |       LONG INT_KEYWORD
1050                         { $$ = lookup_signed_typename (parse_language,
1051                                                        parse_gdbarch,
1052                                                        "long"); }
1053         |       LONG SIGNED_KEYWORD INT_KEYWORD
1054                         { $$ = lookup_signed_typename (parse_language,
1055                                                        parse_gdbarch,
1056                                                        "long"); }
1057         |       LONG SIGNED_KEYWORD
1058                         { $$ = lookup_signed_typename (parse_language,
1059                                                        parse_gdbarch,
1060                                                        "long"); }
1061         |       SIGNED_KEYWORD LONG INT_KEYWORD
1062                         { $$ = lookup_signed_typename (parse_language,
1063                                                        parse_gdbarch,
1064                                                        "long"); }
1065         |       UNSIGNED LONG INT_KEYWORD
1066                         { $$ = lookup_unsigned_typename (parse_language,
1067                                                          parse_gdbarch,
1068                                                          "long"); }
1069         |       LONG UNSIGNED INT_KEYWORD
1070                         { $$ = lookup_unsigned_typename (parse_language,
1071                                                          parse_gdbarch,
1072                                                          "long"); }
1073         |       LONG UNSIGNED
1074                         { $$ = lookup_unsigned_typename (parse_language,
1075                                                          parse_gdbarch,
1076                                                          "long"); }
1077         |       LONG LONG
1078                         { $$ = lookup_signed_typename (parse_language,
1079                                                        parse_gdbarch,
1080                                                        "long long"); }
1081         |       LONG LONG INT_KEYWORD
1082                         { $$ = lookup_signed_typename (parse_language,
1083                                                        parse_gdbarch,
1084                                                        "long long"); }
1085         |       LONG LONG SIGNED_KEYWORD INT_KEYWORD
1086                         { $$ = lookup_signed_typename (parse_language,
1087                                                        parse_gdbarch,
1088                                                        "long long"); }
1089         |       LONG LONG SIGNED_KEYWORD
1090                         { $$ = lookup_signed_typename (parse_language,
1091                                                        parse_gdbarch,
1092                                                        "long long"); }
1093         |       SIGNED_KEYWORD LONG LONG
1094                         { $$ = lookup_signed_typename (parse_language,
1095                                                        parse_gdbarch,
1096                                                        "long long"); }
1097         |       SIGNED_KEYWORD LONG LONG INT_KEYWORD
1098                         { $$ = lookup_signed_typename (parse_language,
1099                                                        parse_gdbarch,
1100                                                        "long long"); }
1101         |       UNSIGNED LONG LONG
1102                         { $$ = lookup_unsigned_typename (parse_language,
1103                                                          parse_gdbarch,
1104                                                          "long long"); }
1105         |       UNSIGNED LONG LONG INT_KEYWORD
1106                         { $$ = lookup_unsigned_typename (parse_language,
1107                                                          parse_gdbarch,
1108                                                          "long long"); }
1109         |       LONG LONG UNSIGNED
1110                         { $$ = lookup_unsigned_typename (parse_language,
1111                                                          parse_gdbarch,
1112                                                          "long long"); }
1113         |       LONG LONG UNSIGNED INT_KEYWORD
1114                         { $$ = lookup_unsigned_typename (parse_language,
1115                                                          parse_gdbarch,
1116                                                          "long long"); }
1117         |       SHORT INT_KEYWORD
1118                         { $$ = lookup_signed_typename (parse_language,
1119                                                        parse_gdbarch,
1120                                                        "short"); }
1121         |       SHORT SIGNED_KEYWORD INT_KEYWORD
1122                         { $$ = lookup_signed_typename (parse_language,
1123                                                        parse_gdbarch,
1124                                                        "short"); }
1125         |       SHORT SIGNED_KEYWORD
1126                         { $$ = lookup_signed_typename (parse_language,
1127                                                        parse_gdbarch,
1128                                                        "short"); }
1129         |       UNSIGNED SHORT INT_KEYWORD
1130                         { $$ = lookup_unsigned_typename (parse_language,
1131                                                          parse_gdbarch,
1132                                                          "short"); }
1133         |       SHORT UNSIGNED 
1134                         { $$ = lookup_unsigned_typename (parse_language,
1135                                                          parse_gdbarch,
1136                                                          "short"); }
1137         |       SHORT UNSIGNED INT_KEYWORD
1138                         { $$ = lookup_unsigned_typename (parse_language,
1139                                                          parse_gdbarch,
1140                                                          "short"); }
1141         |       DOUBLE_KEYWORD
1142                         { $$ = lookup_typename (parse_language, parse_gdbarch,
1143                                                 "double", (struct block *) NULL,
1144                                                 0); }
1145         |       LONG DOUBLE_KEYWORD
1146                         { $$ = lookup_typename (parse_language, parse_gdbarch,
1147                                                 "long double",
1148                                                 (struct block *) NULL, 0); }
1149         |       STRUCT name
1150                         { $$ = lookup_struct (copy_name ($2),
1151                                               expression_context_block); }
1152         |       CLASS name
1153                         { $$ = lookup_struct (copy_name ($2),
1154                                               expression_context_block); }
1155         |       UNION name
1156                         { $$ = lookup_union (copy_name ($2),
1157                                              expression_context_block); }
1158         |       ENUM name
1159                         { $$ = lookup_enum (copy_name ($2),
1160                                             expression_context_block); }
1161         |       UNSIGNED typename
1162                         { $$ = lookup_unsigned_typename (parse_language,
1163                                                          parse_gdbarch,
1164                                                          TYPE_NAME($2.type)); }
1165         |       UNSIGNED
1166                         { $$ = lookup_unsigned_typename (parse_language,
1167                                                          parse_gdbarch,
1168                                                          "int"); }
1169         |       SIGNED_KEYWORD typename
1170                         { $$ = lookup_signed_typename (parse_language,
1171                                                        parse_gdbarch,
1172                                                        TYPE_NAME($2.type)); }
1173         |       SIGNED_KEYWORD
1174                         { $$ = lookup_signed_typename (parse_language,
1175                                                        parse_gdbarch,
1176                                                        "int"); }
1177                 /* It appears that this rule for templates is never
1178                    reduced; template recognition happens by lookahead
1179                    in the token processing code in yylex. */         
1180         |       TEMPLATE name '<' type '>'
1181                         { $$ = lookup_template_type(copy_name($2), $4,
1182                                                     expression_context_block);
1183                         }
1184         | const_or_volatile_or_space_identifier_noopt typebase 
1185                         { $$ = follow_types ($2); }
1186         | typebase const_or_volatile_or_space_identifier_noopt 
1187                         { $$ = follow_types ($1); }
1188         ;
1189
1190 typename:       TYPENAME
1191         |       INT_KEYWORD
1192                 {
1193                   $$.stoken.ptr = "int";
1194                   $$.stoken.length = 3;
1195                   $$.type = lookup_signed_typename (parse_language,
1196                                                     parse_gdbarch,
1197                                                     "int");
1198                 }
1199         |       LONG
1200                 {
1201                   $$.stoken.ptr = "long";
1202                   $$.stoken.length = 4;
1203                   $$.type = lookup_signed_typename (parse_language,
1204                                                     parse_gdbarch,
1205                                                     "long");
1206                 }
1207         |       SHORT
1208                 {
1209                   $$.stoken.ptr = "short";
1210                   $$.stoken.length = 5;
1211                   $$.type = lookup_signed_typename (parse_language,
1212                                                     parse_gdbarch,
1213                                                     "short");
1214                 }
1215         ;
1216
1217 parameter_typelist:
1218                 nonempty_typelist
1219                         { check_parameter_typelist ($1); }
1220         |       nonempty_typelist ',' DOTDOTDOT
1221                         {
1222                           VEC_safe_push (type_ptr, $1, NULL);
1223                           check_parameter_typelist ($1);
1224                           $$ = $1;
1225                         }
1226         ;
1227
1228 nonempty_typelist
1229         :       type
1230                 {
1231                   VEC (type_ptr) *typelist = NULL;
1232                   VEC_safe_push (type_ptr, typelist, $1);
1233                   $$ = typelist;
1234                 }
1235         |       nonempty_typelist ',' type
1236                 {
1237                   VEC_safe_push (type_ptr, $1, $3);
1238                   $$ = $1;
1239                 }
1240         ;
1241
1242 ptype   :       typebase
1243         |       ptype abs_decl
1244                 {
1245                   push_type_stack ($2);
1246                   $$ = follow_types ($1);
1247                 }
1248         ;
1249
1250 conversion_type_id: typebase conversion_declarator
1251                 { $$ = follow_types ($1); }
1252         ;
1253
1254 conversion_declarator:  /* Nothing.  */
1255         | ptr_operator conversion_declarator
1256         ;
1257
1258 const_and_volatile:     CONST_KEYWORD VOLATILE_KEYWORD
1259         |               VOLATILE_KEYWORD CONST_KEYWORD
1260         ;
1261
1262 const_or_volatile_noopt:        const_and_volatile 
1263                         { insert_type (tp_const);
1264                           insert_type (tp_volatile); 
1265                         }
1266         |               CONST_KEYWORD
1267                         { insert_type (tp_const); }
1268         |               VOLATILE_KEYWORD
1269                         { insert_type (tp_volatile); }
1270         ;
1271
1272 operator:       OPERATOR NEW
1273                         { $$ = operator_stoken (" new"); }
1274         |       OPERATOR DELETE
1275                         { $$ = operator_stoken (" delete"); }
1276         |       OPERATOR NEW '[' ']'
1277                         { $$ = operator_stoken (" new[]"); }
1278         |       OPERATOR DELETE '[' ']'
1279                         { $$ = operator_stoken (" delete[]"); }
1280         |       OPERATOR '+'
1281                         { $$ = operator_stoken ("+"); }
1282         |       OPERATOR '-'
1283                         { $$ = operator_stoken ("-"); }
1284         |       OPERATOR '*'
1285                         { $$ = operator_stoken ("*"); }
1286         |       OPERATOR '/'
1287                         { $$ = operator_stoken ("/"); }
1288         |       OPERATOR '%'
1289                         { $$ = operator_stoken ("%"); }
1290         |       OPERATOR '^'
1291                         { $$ = operator_stoken ("^"); }
1292         |       OPERATOR '&'
1293                         { $$ = operator_stoken ("&"); }
1294         |       OPERATOR '|'
1295                         { $$ = operator_stoken ("|"); }
1296         |       OPERATOR '~'
1297                         { $$ = operator_stoken ("~"); }
1298         |       OPERATOR '!'
1299                         { $$ = operator_stoken ("!"); }
1300         |       OPERATOR '='
1301                         { $$ = operator_stoken ("="); }
1302         |       OPERATOR '<'
1303                         { $$ = operator_stoken ("<"); }
1304         |       OPERATOR '>'
1305                         { $$ = operator_stoken (">"); }
1306         |       OPERATOR ASSIGN_MODIFY
1307                         { const char *op = "unknown";
1308                           switch ($2)
1309                             {
1310                             case BINOP_RSH:
1311                               op = ">>=";
1312                               break;
1313                             case BINOP_LSH:
1314                               op = "<<=";
1315                               break;
1316                             case BINOP_ADD:
1317                               op = "+=";
1318                               break;
1319                             case BINOP_SUB:
1320                               op = "-=";
1321                               break;
1322                             case BINOP_MUL:
1323                               op = "*=";
1324                               break;
1325                             case BINOP_DIV:
1326                               op = "/=";
1327                               break;
1328                             case BINOP_REM:
1329                               op = "%=";
1330                               break;
1331                             case BINOP_BITWISE_IOR:
1332                               op = "|=";
1333                               break;
1334                             case BINOP_BITWISE_AND:
1335                               op = "&=";
1336                               break;
1337                             case BINOP_BITWISE_XOR:
1338                               op = "^=";
1339                               break;
1340                             default:
1341                               break;
1342                             }
1343
1344                           $$ = operator_stoken (op);
1345                         }
1346         |       OPERATOR LSH
1347                         { $$ = operator_stoken ("<<"); }
1348         |       OPERATOR RSH
1349                         { $$ = operator_stoken (">>"); }
1350         |       OPERATOR EQUAL
1351                         { $$ = operator_stoken ("=="); }
1352         |       OPERATOR NOTEQUAL
1353                         { $$ = operator_stoken ("!="); }
1354         |       OPERATOR LEQ
1355                         { $$ = operator_stoken ("<="); }
1356         |       OPERATOR GEQ
1357                         { $$ = operator_stoken (">="); }
1358         |       OPERATOR ANDAND
1359                         { $$ = operator_stoken ("&&"); }
1360         |       OPERATOR OROR
1361                         { $$ = operator_stoken ("||"); }
1362         |       OPERATOR INCREMENT
1363                         { $$ = operator_stoken ("++"); }
1364         |       OPERATOR DECREMENT
1365                         { $$ = operator_stoken ("--"); }
1366         |       OPERATOR ','
1367                         { $$ = operator_stoken (","); }
1368         |       OPERATOR ARROW_STAR
1369                         { $$ = operator_stoken ("->*"); }
1370         |       OPERATOR ARROW
1371                         { $$ = operator_stoken ("->"); }
1372         |       OPERATOR '(' ')'
1373                         { $$ = operator_stoken ("()"); }
1374         |       OPERATOR '[' ']'
1375                         { $$ = operator_stoken ("[]"); }
1376         |       OPERATOR conversion_type_id
1377                         { char *name;
1378                           long length;
1379                           struct ui_file *buf = mem_fileopen ();
1380
1381                           c_print_type ($2, NULL, buf, -1, 0);
1382                           name = ui_file_xstrdup (buf, &length);
1383                           ui_file_delete (buf);
1384                           $$ = operator_stoken (name);
1385                           free (name);
1386                         }
1387         ;
1388
1389
1390
1391 name    :       NAME { $$ = $1.stoken; }
1392         |       BLOCKNAME { $$ = $1.stoken; }
1393         |       TYPENAME { $$ = $1.stoken; }
1394         |       NAME_OR_INT  { $$ = $1.stoken; }
1395         |       UNKNOWN_CPP_NAME  { $$ = $1.stoken; }
1396         |       operator { $$ = $1; }
1397         ;
1398
1399 name_not_typename :     NAME
1400         |       BLOCKNAME
1401 /* These would be useful if name_not_typename was useful, but it is just
1402    a fake for "variable", so these cause reduce/reduce conflicts because
1403    the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable,
1404    =exp) or just an exp.  If name_not_typename was ever used in an lvalue
1405    context where only a name could occur, this might be useful.
1406         |       NAME_OR_INT
1407  */
1408         |       operator
1409                         {
1410                           $$.stoken = $1;
1411                           $$.sym = lookup_symbol ($1.ptr,
1412                                                   expression_context_block,
1413                                                   VAR_DOMAIN,
1414                                                   &$$.is_a_field_of_this);
1415                         }
1416         |       UNKNOWN_CPP_NAME
1417         ;
1418
1419 %%
1420
1421 /* Returns a stoken of the operator name given by OP (which does not
1422    include the string "operator").  */ 
1423 static struct stoken
1424 operator_stoken (const char *op)
1425 {
1426   static const char *operator_string = "operator";
1427   struct stoken st = { NULL, 0 };
1428   st.length = strlen (operator_string) + strlen (op);
1429   st.ptr = malloc (st.length + 1);
1430   strcpy (st.ptr, operator_string);
1431   strcat (st.ptr, op);
1432
1433   /* The toplevel (c_parse) will free the memory allocated here.  */
1434   make_cleanup (free, st.ptr);
1435   return st;
1436 };
1437
1438 /* Validate a parameter typelist.  */
1439
1440 static void
1441 check_parameter_typelist (VEC (type_ptr) *params)
1442 {
1443   struct type *type;
1444   int ix;
1445
1446   for (ix = 0; VEC_iterate (type_ptr, params, ix, type); ++ix)
1447     {
1448       if (type != NULL && TYPE_CODE (check_typedef (type)) == TYPE_CODE_VOID)
1449         {
1450           if (ix == 0)
1451             {
1452               if (VEC_length (type_ptr, params) == 1)
1453                 {
1454                   /* Ok.  */
1455                   break;
1456                 }
1457               VEC_free (type_ptr, params);
1458               error (_("parameter types following 'void'"));
1459             }
1460           else
1461             {
1462               VEC_free (type_ptr, params);
1463               error (_("'void' invalid as parameter type"));
1464             }
1465         }
1466     }
1467 }
1468
1469 /* Take care of parsing a number (anything that starts with a digit).
1470    Set yylval and return the token type; update lexptr.
1471    LEN is the number of characters in it.  */
1472
1473 /*** Needs some error checking for the float case ***/
1474
1475 static int
1476 parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
1477 {
1478   /* FIXME: Shouldn't these be unsigned?  We don't deal with negative values
1479      here, and we do kind of silly things like cast to unsigned.  */
1480   LONGEST n = 0;
1481   LONGEST prevn = 0;
1482   ULONGEST un;
1483
1484   int i = 0;
1485   int c;
1486   int base = input_radix;
1487   int unsigned_p = 0;
1488
1489   /* Number of "L" suffixes encountered.  */
1490   int long_p = 0;
1491
1492   /* We have found a "L" or "U" suffix.  */
1493   int found_suffix = 0;
1494
1495   ULONGEST high_bit;
1496   struct type *signed_type;
1497   struct type *unsigned_type;
1498
1499   if (parsed_float)
1500     {
1501       /* If it ends at "df", "dd" or "dl", take it as type of decimal floating
1502          point.  Return DECFLOAT.  */
1503
1504       if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'f')
1505         {
1506           p[len - 2] = '\0';
1507           putithere->typed_val_decfloat.type
1508             = parse_type->builtin_decfloat;
1509           decimal_from_string (putithere->typed_val_decfloat.val, 4,
1510                                gdbarch_byte_order (parse_gdbarch), p);
1511           p[len - 2] = 'd';
1512           return DECFLOAT;
1513         }
1514
1515       if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'd')
1516         {
1517           p[len - 2] = '\0';
1518           putithere->typed_val_decfloat.type
1519             = parse_type->builtin_decdouble;
1520           decimal_from_string (putithere->typed_val_decfloat.val, 8,
1521                                gdbarch_byte_order (parse_gdbarch), p);
1522           p[len - 2] = 'd';
1523           return DECFLOAT;
1524         }
1525
1526       if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'l')
1527         {
1528           p[len - 2] = '\0';
1529           putithere->typed_val_decfloat.type
1530             = parse_type->builtin_declong;
1531           decimal_from_string (putithere->typed_val_decfloat.val, 16,
1532                                gdbarch_byte_order (parse_gdbarch), p);
1533           p[len - 2] = 'd';
1534           return DECFLOAT;
1535         }
1536
1537       if (! parse_c_float (parse_gdbarch, p, len,
1538                            &putithere->typed_val_float.dval,
1539                            &putithere->typed_val_float.type))
1540         return ERROR;
1541       return FLOAT;
1542     }
1543
1544   /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
1545   if (p[0] == '0')
1546     switch (p[1])
1547       {
1548       case 'x':
1549       case 'X':
1550         if (len >= 3)
1551           {
1552             p += 2;
1553             base = 16;
1554             len -= 2;
1555           }
1556         break;
1557
1558       case 'b':
1559       case 'B':
1560         if (len >= 3)
1561           {
1562             p += 2;
1563             base = 2;
1564             len -= 2;
1565           }
1566         break;
1567
1568       case 't':
1569       case 'T':
1570       case 'd':
1571       case 'D':
1572         if (len >= 3)
1573           {
1574             p += 2;
1575             base = 10;
1576             len -= 2;
1577           }
1578         break;
1579
1580       default:
1581         base = 8;
1582         break;
1583       }
1584
1585   while (len-- > 0)
1586     {
1587       c = *p++;
1588       if (c >= 'A' && c <= 'Z')
1589         c += 'a' - 'A';
1590       if (c != 'l' && c != 'u')
1591         n *= base;
1592       if (c >= '0' && c <= '9')
1593         {
1594           if (found_suffix)
1595             return ERROR;
1596           n += i = c - '0';
1597         }
1598       else
1599         {
1600           if (base > 10 && c >= 'a' && c <= 'f')
1601             {
1602               if (found_suffix)
1603                 return ERROR;
1604               n += i = c - 'a' + 10;
1605             }
1606           else if (c == 'l')
1607             {
1608               ++long_p;
1609               found_suffix = 1;
1610             }
1611           else if (c == 'u')
1612             {
1613               unsigned_p = 1;
1614               found_suffix = 1;
1615             }
1616           else
1617             return ERROR;       /* Char not a digit */
1618         }
1619       if (i >= base)
1620         return ERROR;           /* Invalid digit in this base */
1621
1622       /* Portably test for overflow (only works for nonzero values, so make
1623          a second check for zero).  FIXME: Can't we just make n and prevn
1624          unsigned and avoid this?  */
1625       if (c != 'l' && c != 'u' && (prevn >= n) && n != 0)
1626         unsigned_p = 1;         /* Try something unsigned */
1627
1628       /* Portably test for unsigned overflow.
1629          FIXME: This check is wrong; for example it doesn't find overflow
1630          on 0x123456789 when LONGEST is 32 bits.  */
1631       if (c != 'l' && c != 'u' && n != 0)
1632         {       
1633           if ((unsigned_p && (ULONGEST) prevn >= (ULONGEST) n))
1634             error (_("Numeric constant too large."));
1635         }
1636       prevn = n;
1637     }
1638
1639   /* An integer constant is an int, a long, or a long long.  An L
1640      suffix forces it to be long; an LL suffix forces it to be long
1641      long.  If not forced to a larger size, it gets the first type of
1642      the above that it fits in.  To figure out whether it fits, we
1643      shift it right and see whether anything remains.  Note that we
1644      can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one
1645      operation, because many compilers will warn about such a shift
1646      (which always produces a zero result).  Sometimes gdbarch_int_bit
1647      or gdbarch_long_bit will be that big, sometimes not.  To deal with
1648      the case where it is we just always shift the value more than
1649      once, with fewer bits each time.  */
1650
1651   un = (ULONGEST)n >> 2;
1652   if (long_p == 0
1653       && (un >> (gdbarch_int_bit (parse_gdbarch) - 2)) == 0)
1654     {
1655       high_bit = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch) - 1);
1656
1657       /* A large decimal (not hex or octal) constant (between INT_MAX
1658          and UINT_MAX) is a long or unsigned long, according to ANSI,
1659          never an unsigned int, but this code treats it as unsigned
1660          int.  This probably should be fixed.  GCC gives a warning on
1661          such constants.  */
1662
1663       unsigned_type = parse_type->builtin_unsigned_int;
1664       signed_type = parse_type->builtin_int;
1665     }
1666   else if (long_p <= 1
1667            && (un >> (gdbarch_long_bit (parse_gdbarch) - 2)) == 0)
1668     {
1669       high_bit = ((ULONGEST)1) << (gdbarch_long_bit (parse_gdbarch) - 1);
1670       unsigned_type = parse_type->builtin_unsigned_long;
1671       signed_type = parse_type->builtin_long;
1672     }
1673   else
1674     {
1675       int shift;
1676       if (sizeof (ULONGEST) * HOST_CHAR_BIT 
1677           < gdbarch_long_long_bit (parse_gdbarch))
1678         /* A long long does not fit in a LONGEST.  */
1679         shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1);
1680       else
1681         shift = (gdbarch_long_long_bit (parse_gdbarch) - 1);
1682       high_bit = (ULONGEST) 1 << shift;
1683       unsigned_type = parse_type->builtin_unsigned_long_long;
1684       signed_type = parse_type->builtin_long_long;
1685     }
1686
1687    putithere->typed_val_int.val = n;
1688
1689    /* If the high bit of the worked out type is set then this number
1690       has to be unsigned. */
1691
1692    if (unsigned_p || (n & high_bit)) 
1693      {
1694        putithere->typed_val_int.type = unsigned_type;
1695      }
1696    else 
1697      {
1698        putithere->typed_val_int.type = signed_type;
1699      }
1700
1701    return INT;
1702 }
1703
1704 /* Temporary obstack used for holding strings.  */
1705 static struct obstack tempbuf;
1706 static int tempbuf_init;
1707
1708 /* Parse a C escape sequence.  The initial backslash of the sequence
1709    is at (*PTR)[-1].  *PTR will be updated to point to just after the
1710    last character of the sequence.  If OUTPUT is not NULL, the
1711    translated form of the escape sequence will be written there.  If
1712    OUTPUT is NULL, no output is written and the call will only affect
1713    *PTR.  If an escape sequence is expressed in target bytes, then the
1714    entire sequence will simply be copied to OUTPUT.  Return 1 if any
1715    character was emitted, 0 otherwise.  */
1716
1717 int
1718 c_parse_escape (char **ptr, struct obstack *output)
1719 {
1720   char *tokptr = *ptr;
1721   int result = 1;
1722
1723   /* Some escape sequences undergo character set conversion.  Those we
1724      translate here.  */
1725   switch (*tokptr)
1726     {
1727       /* Hex escapes do not undergo character set conversion, so keep
1728          the escape sequence for later.  */
1729     case 'x':
1730       if (output)
1731         obstack_grow_str (output, "\\x");
1732       ++tokptr;
1733       if (!isxdigit (*tokptr))
1734         error (_("\\x escape without a following hex digit"));
1735       while (isxdigit (*tokptr))
1736         {
1737           if (output)
1738             obstack_1grow (output, *tokptr);
1739           ++tokptr;
1740         }
1741       break;
1742
1743       /* Octal escapes do not undergo character set conversion, so
1744          keep the escape sequence for later.  */
1745     case '0':
1746     case '1':
1747     case '2':
1748     case '3':
1749     case '4':
1750     case '5':
1751     case '6':
1752     case '7':
1753       {
1754         int i;
1755         if (output)
1756           obstack_grow_str (output, "\\");
1757         for (i = 0;
1758              i < 3 && isdigit (*tokptr) && *tokptr != '8' && *tokptr != '9';
1759              ++i)
1760           {
1761             if (output)
1762               obstack_1grow (output, *tokptr);
1763             ++tokptr;
1764           }
1765       }
1766       break;
1767
1768       /* We handle UCNs later.  We could handle them here, but that
1769          would mean a spurious error in the case where the UCN could
1770          be converted to the target charset but not the host
1771          charset.  */
1772     case 'u':
1773     case 'U':
1774       {
1775         char c = *tokptr;
1776         int i, len = c == 'U' ? 8 : 4;
1777         if (output)
1778           {
1779             obstack_1grow (output, '\\');
1780             obstack_1grow (output, *tokptr);
1781           }
1782         ++tokptr;
1783         if (!isxdigit (*tokptr))
1784           error (_("\\%c escape without a following hex digit"), c);
1785         for (i = 0; i < len && isxdigit (*tokptr); ++i)
1786           {
1787             if (output)
1788               obstack_1grow (output, *tokptr);
1789             ++tokptr;
1790           }
1791       }
1792       break;
1793
1794       /* We must pass backslash through so that it does not
1795          cause quoting during the second expansion.  */
1796     case '\\':
1797       if (output)
1798         obstack_grow_str (output, "\\\\");
1799       ++tokptr;
1800       break;
1801
1802       /* Escapes which undergo conversion.  */
1803     case 'a':
1804       if (output)
1805         obstack_1grow (output, '\a');
1806       ++tokptr;
1807       break;
1808     case 'b':
1809       if (output)
1810         obstack_1grow (output, '\b');
1811       ++tokptr;
1812       break;
1813     case 'f':
1814       if (output)
1815         obstack_1grow (output, '\f');
1816       ++tokptr;
1817       break;
1818     case 'n':
1819       if (output)
1820         obstack_1grow (output, '\n');
1821       ++tokptr;
1822       break;
1823     case 'r':
1824       if (output)
1825         obstack_1grow (output, '\r');
1826       ++tokptr;
1827       break;
1828     case 't':
1829       if (output)
1830         obstack_1grow (output, '\t');
1831       ++tokptr;
1832       break;
1833     case 'v':
1834       if (output)
1835         obstack_1grow (output, '\v');
1836       ++tokptr;
1837       break;
1838
1839       /* GCC extension.  */
1840     case 'e':
1841       if (output)
1842         obstack_1grow (output, HOST_ESCAPE_CHAR);
1843       ++tokptr;
1844       break;
1845
1846       /* Backslash-newline expands to nothing at all.  */
1847     case '\n':
1848       ++tokptr;
1849       result = 0;
1850       break;
1851
1852       /* A few escapes just expand to the character itself.  */
1853     case '\'':
1854     case '\"':
1855     case '?':
1856       /* GCC extensions.  */
1857     case '(':
1858     case '{':
1859     case '[':
1860     case '%':
1861       /* Unrecognized escapes turn into the character itself.  */
1862     default:
1863       if (output)
1864         obstack_1grow (output, *tokptr);
1865       ++tokptr;
1866       break;
1867     }
1868   *ptr = tokptr;
1869   return result;
1870 }
1871
1872 /* Parse a string or character literal from TOKPTR.  The string or
1873    character may be wide or unicode.  *OUTPTR is set to just after the
1874    end of the literal in the input string.  The resulting token is
1875    stored in VALUE.  This returns a token value, either STRING or
1876    CHAR, depending on what was parsed.  *HOST_CHARS is set to the
1877    number of host characters in the literal.  */
1878 static int
1879 parse_string_or_char (char *tokptr, char **outptr, struct typed_stoken *value,
1880                       int *host_chars)
1881 {
1882   int quote;
1883   enum c_string_type type;
1884
1885   /* Build the gdb internal form of the input string in tempbuf.  Note
1886      that the buffer is null byte terminated *only* for the
1887      convenience of debugging gdb itself and printing the buffer
1888      contents when the buffer contains no embedded nulls.  Gdb does
1889      not depend upon the buffer being null byte terminated, it uses
1890      the length string instead.  This allows gdb to handle C strings
1891      (as well as strings in other languages) with embedded null
1892      bytes */
1893
1894   if (!tempbuf_init)
1895     tempbuf_init = 1;
1896   else
1897     obstack_free (&tempbuf, NULL);
1898   obstack_init (&tempbuf);
1899
1900   /* Record the string type.  */
1901   if (*tokptr == 'L')
1902     {
1903       type = C_WIDE_STRING;
1904       ++tokptr;
1905     }
1906   else if (*tokptr == 'u')
1907     {
1908       type = C_STRING_16;
1909       ++tokptr;
1910     }
1911   else if (*tokptr == 'U')
1912     {
1913       type = C_STRING_32;
1914       ++tokptr;
1915     }
1916   else
1917     type = C_STRING;
1918
1919   /* Skip the quote.  */
1920   quote = *tokptr;
1921   if (quote == '\'')
1922     type |= C_CHAR;
1923   ++tokptr;
1924
1925   *host_chars = 0;
1926
1927   while (*tokptr)
1928     {
1929       char c = *tokptr;
1930       if (c == '\\')
1931         {
1932           ++tokptr;
1933           *host_chars += c_parse_escape (&tokptr, &tempbuf);
1934         }
1935       else if (c == quote)
1936         break;
1937       else
1938         {
1939           obstack_1grow (&tempbuf, c);
1940           ++tokptr;
1941           /* FIXME: this does the wrong thing with multi-byte host
1942              characters.  We could use mbrlen here, but that would
1943              make "set host-charset" a bit less useful.  */
1944           ++*host_chars;
1945         }
1946     }
1947
1948   if (*tokptr != quote)
1949     {
1950       if (quote == '"')
1951         error (_("Unterminated string in expression."));
1952       else
1953         error (_("Unmatched single quote."));
1954     }
1955   ++tokptr;
1956
1957   value->type = type;
1958   value->ptr = obstack_base (&tempbuf);
1959   value->length = obstack_object_size (&tempbuf);
1960
1961   *outptr = tokptr;
1962
1963   return quote == '"' ? STRING : CHAR;
1964 }
1965
1966 /* This is used to associate some attributes with a token.  */
1967
1968 enum token_flags
1969 {
1970   /* If this bit is set, the token is C++-only.  */
1971
1972   FLAG_CXX = 1,
1973
1974   /* If this bit is set, the token is conditional: if there is a
1975      symbol of the same name, then the token is a symbol; otherwise,
1976      the token is a keyword.  */
1977
1978   FLAG_SHADOW = 2
1979 };
1980
1981 struct token
1982 {
1983   char *operator;
1984   int token;
1985   enum exp_opcode opcode;
1986   enum token_flags flags;
1987 };
1988
1989 static const struct token tokentab3[] =
1990   {
1991     {">>=", ASSIGN_MODIFY, BINOP_RSH, 0},
1992     {"<<=", ASSIGN_MODIFY, BINOP_LSH, 0},
1993     {"->*", ARROW_STAR, BINOP_END, FLAG_CXX},
1994     {"...", DOTDOTDOT, BINOP_END, 0}
1995   };
1996
1997 static const struct token tokentab2[] =
1998   {
1999     {"+=", ASSIGN_MODIFY, BINOP_ADD, 0},
2000     {"-=", ASSIGN_MODIFY, BINOP_SUB, 0},
2001     {"*=", ASSIGN_MODIFY, BINOP_MUL, 0},
2002     {"/=", ASSIGN_MODIFY, BINOP_DIV, 0},
2003     {"%=", ASSIGN_MODIFY, BINOP_REM, 0},
2004     {"|=", ASSIGN_MODIFY, BINOP_BITWISE_IOR, 0},
2005     {"&=", ASSIGN_MODIFY, BINOP_BITWISE_AND, 0},
2006     {"^=", ASSIGN_MODIFY, BINOP_BITWISE_XOR, 0},
2007     {"++", INCREMENT, BINOP_END, 0},
2008     {"--", DECREMENT, BINOP_END, 0},
2009     {"->", ARROW, BINOP_END, 0},
2010     {"&&", ANDAND, BINOP_END, 0},
2011     {"||", OROR, BINOP_END, 0},
2012     /* "::" is *not* only C++: gdb overrides its meaning in several
2013        different ways, e.g., 'filename'::func, function::variable.  */
2014     {"::", COLONCOLON, BINOP_END, 0},
2015     {"<<", LSH, BINOP_END, 0},
2016     {">>", RSH, BINOP_END, 0},
2017     {"==", EQUAL, BINOP_END, 0},
2018     {"!=", NOTEQUAL, BINOP_END, 0},
2019     {"<=", LEQ, BINOP_END, 0},
2020     {">=", GEQ, BINOP_END, 0},
2021     {".*", DOT_STAR, BINOP_END, FLAG_CXX}
2022   };
2023
2024 /* Identifier-like tokens.  */
2025 static const struct token ident_tokens[] =
2026   {
2027     {"unsigned", UNSIGNED, OP_NULL, 0},
2028     {"template", TEMPLATE, OP_NULL, FLAG_CXX},
2029     {"volatile", VOLATILE_KEYWORD, OP_NULL, 0},
2030     {"struct", STRUCT, OP_NULL, 0},
2031     {"signed", SIGNED_KEYWORD, OP_NULL, 0},
2032     {"sizeof", SIZEOF, OP_NULL, 0},
2033     {"double", DOUBLE_KEYWORD, OP_NULL, 0},
2034     {"false", FALSEKEYWORD, OP_NULL, FLAG_CXX},
2035     {"class", CLASS, OP_NULL, FLAG_CXX},
2036     {"union", UNION, OP_NULL, 0},
2037     {"short", SHORT, OP_NULL, 0},
2038     {"const", CONST_KEYWORD, OP_NULL, 0},
2039     {"enum", ENUM, OP_NULL, 0},
2040     {"long", LONG, OP_NULL, 0},
2041     {"true", TRUEKEYWORD, OP_NULL, FLAG_CXX},
2042     {"int", INT_KEYWORD, OP_NULL, 0},
2043     {"new", NEW, OP_NULL, FLAG_CXX},
2044     {"delete", DELETE, OP_NULL, FLAG_CXX},
2045     {"operator", OPERATOR, OP_NULL, FLAG_CXX},
2046
2047     {"and", ANDAND, BINOP_END, FLAG_CXX},
2048     {"and_eq", ASSIGN_MODIFY, BINOP_BITWISE_AND, FLAG_CXX},
2049     {"bitand", '&', OP_NULL, FLAG_CXX},
2050     {"bitor", '|', OP_NULL, FLAG_CXX},
2051     {"compl", '~', OP_NULL, FLAG_CXX},
2052     {"not", '!', OP_NULL, FLAG_CXX},
2053     {"not_eq", NOTEQUAL, BINOP_END, FLAG_CXX},
2054     {"or", OROR, BINOP_END, FLAG_CXX},
2055     {"or_eq", ASSIGN_MODIFY, BINOP_BITWISE_IOR, FLAG_CXX},
2056     {"xor", '^', OP_NULL, FLAG_CXX},
2057     {"xor_eq", ASSIGN_MODIFY, BINOP_BITWISE_XOR, FLAG_CXX},
2058
2059     {"const_cast", CONST_CAST, OP_NULL, FLAG_CXX },
2060     {"dynamic_cast", DYNAMIC_CAST, OP_NULL, FLAG_CXX },
2061     {"static_cast", STATIC_CAST, OP_NULL, FLAG_CXX },
2062     {"reinterpret_cast", REINTERPRET_CAST, OP_NULL, FLAG_CXX }
2063   };
2064
2065 /* When we find that lexptr (the global var defined in parse.c) is
2066    pointing at a macro invocation, we expand the invocation, and call
2067    scan_macro_expansion to save the old lexptr here and point lexptr
2068    into the expanded text.  When we reach the end of that, we call
2069    end_macro_expansion to pop back to the value we saved here.  The
2070    macro expansion code promises to return only fully-expanded text,
2071    so we don't need to "push" more than one level.
2072
2073    This is disgusting, of course.  It would be cleaner to do all macro
2074    expansion beforehand, and then hand that to lexptr.  But we don't
2075    really know where the expression ends.  Remember, in a command like
2076
2077      (gdb) break *ADDRESS if CONDITION
2078
2079    we evaluate ADDRESS in the scope of the current frame, but we
2080    evaluate CONDITION in the scope of the breakpoint's location.  So
2081    it's simply wrong to try to macro-expand the whole thing at once.  */
2082 static char *macro_original_text;
2083
2084 /* We save all intermediate macro expansions on this obstack for the
2085    duration of a single parse.  The expansion text may sometimes have
2086    to live past the end of the expansion, due to yacc lookahead.
2087    Rather than try to be clever about saving the data for a single
2088    token, we simply keep it all and delete it after parsing has
2089    completed.  */
2090 static struct obstack expansion_obstack;
2091
2092 static void
2093 scan_macro_expansion (char *expansion)
2094 {
2095   char *copy;
2096
2097   /* We'd better not be trying to push the stack twice.  */
2098   gdb_assert (! macro_original_text);
2099
2100   /* Copy to the obstack, and then free the intermediate
2101      expansion.  */
2102   copy = obstack_copy0 (&expansion_obstack, expansion, strlen (expansion));
2103   xfree (expansion);
2104
2105   /* Save the old lexptr value, so we can return to it when we're done
2106      parsing the expanded text.  */
2107   macro_original_text = lexptr;
2108   lexptr = copy;
2109 }
2110
2111
2112 static int
2113 scanning_macro_expansion (void)
2114 {
2115   return macro_original_text != 0;
2116 }
2117
2118
2119 static void 
2120 finished_macro_expansion (void)
2121 {
2122   /* There'd better be something to pop back to.  */
2123   gdb_assert (macro_original_text);
2124
2125   /* Pop back to the original text.  */
2126   lexptr = macro_original_text;
2127   macro_original_text = 0;
2128 }
2129
2130
2131 static void
2132 scan_macro_cleanup (void *dummy)
2133 {
2134   if (macro_original_text)
2135     finished_macro_expansion ();
2136
2137   obstack_free (&expansion_obstack, NULL);
2138 }
2139
2140 /* Return true iff the token represents a C++ cast operator.  */
2141
2142 static int
2143 is_cast_operator (const char *token, int len)
2144 {
2145   return (! strncmp (token, "dynamic_cast", len)
2146           || ! strncmp (token, "static_cast", len)
2147           || ! strncmp (token, "reinterpret_cast", len)
2148           || ! strncmp (token, "const_cast", len));
2149 }
2150
2151 /* The scope used for macro expansion.  */
2152 static struct macro_scope *expression_macro_scope;
2153
2154 /* This is set if a NAME token appeared at the very end of the input
2155    string, with no whitespace separating the name from the EOF.  This
2156    is used only when parsing to do field name completion.  */
2157 static int saw_name_at_eof;
2158
2159 /* This is set if the previously-returned token was a structure
2160    operator -- either '.' or ARROW.  This is used only when parsing to
2161    do field name completion.  */
2162 static int last_was_structop;
2163
2164 /* Read one token, getting characters through lexptr.  */
2165
2166 static int
2167 lex_one_token (void)
2168 {
2169   int c;
2170   int namelen;
2171   unsigned int i;
2172   char *tokstart;
2173   int saw_structop = last_was_structop;
2174   char *copy;
2175
2176   last_was_structop = 0;
2177
2178  retry:
2179
2180   /* Check if this is a macro invocation that we need to expand.  */
2181   if (! scanning_macro_expansion ())
2182     {
2183       char *expanded = macro_expand_next (&lexptr,
2184                                           standard_macro_lookup,
2185                                           expression_macro_scope);
2186
2187       if (expanded)
2188         scan_macro_expansion (expanded);
2189     }
2190
2191   prev_lexptr = lexptr;
2192
2193   tokstart = lexptr;
2194   /* See if it is a special token of length 3.  */
2195   for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++)
2196     if (strncmp (tokstart, tokentab3[i].operator, 3) == 0)
2197       {
2198         if ((tokentab3[i].flags & FLAG_CXX) != 0
2199             && parse_language->la_language != language_cplus)
2200           break;
2201
2202         lexptr += 3;
2203         yylval.opcode = tokentab3[i].opcode;
2204         return tokentab3[i].token;
2205       }
2206
2207   /* See if it is a special token of length 2.  */
2208   for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++)
2209     if (strncmp (tokstart, tokentab2[i].operator, 2) == 0)
2210       {
2211         if ((tokentab2[i].flags & FLAG_CXX) != 0
2212             && parse_language->la_language != language_cplus)
2213           break;
2214
2215         lexptr += 2;
2216         yylval.opcode = tokentab2[i].opcode;
2217         if (in_parse_field && tokentab2[i].token == ARROW)
2218           last_was_structop = 1;
2219         return tokentab2[i].token;
2220       }
2221
2222   switch (c = *tokstart)
2223     {
2224     case 0:
2225       /* If we were just scanning the result of a macro expansion,
2226          then we need to resume scanning the original text.
2227          If we're parsing for field name completion, and the previous
2228          token allows such completion, return a COMPLETE token.
2229          Otherwise, we were already scanning the original text, and
2230          we're really done.  */
2231       if (scanning_macro_expansion ())
2232         {
2233           finished_macro_expansion ();
2234           goto retry;
2235         }
2236       else if (saw_name_at_eof)
2237         {
2238           saw_name_at_eof = 0;
2239           return COMPLETE;
2240         }
2241       else if (saw_structop)
2242         return COMPLETE;
2243       else
2244         return 0;
2245
2246     case ' ':
2247     case '\t':
2248     case '\n':
2249       lexptr++;
2250       goto retry;
2251
2252     case '[':
2253     case '(':
2254       paren_depth++;
2255       lexptr++;
2256       return c;
2257
2258     case ']':
2259     case ')':
2260       if (paren_depth == 0)
2261         return 0;
2262       paren_depth--;
2263       lexptr++;
2264       return c;
2265
2266     case ',':
2267       if (comma_terminates
2268           && paren_depth == 0
2269           && ! scanning_macro_expansion ())
2270         return 0;
2271       lexptr++;
2272       return c;
2273
2274     case '.':
2275       /* Might be a floating point number.  */
2276       if (lexptr[1] < '0' || lexptr[1] > '9')
2277         {
2278           if (in_parse_field)
2279             last_was_structop = 1;
2280           goto symbol;          /* Nope, must be a symbol. */
2281         }
2282       /* FALL THRU into number case.  */
2283
2284     case '0':
2285     case '1':
2286     case '2':
2287     case '3':
2288     case '4':
2289     case '5':
2290     case '6':
2291     case '7':
2292     case '8':
2293     case '9':
2294       {
2295         /* It's a number.  */
2296         int got_dot = 0, got_e = 0, toktype;
2297         char *p = tokstart;
2298         int hex = input_radix > 10;
2299
2300         if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
2301           {
2302             p += 2;
2303             hex = 1;
2304           }
2305         else if (c == '0' && (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))
2306           {
2307             p += 2;
2308             hex = 0;
2309           }
2310
2311         for (;; ++p)
2312           {
2313             /* This test includes !hex because 'e' is a valid hex digit
2314                and thus does not indicate a floating point number when
2315                the radix is hex.  */
2316             if (!hex && !got_e && (*p == 'e' || *p == 'E'))
2317               got_dot = got_e = 1;
2318             /* This test does not include !hex, because a '.' always indicates
2319                a decimal floating point number regardless of the radix.  */
2320             else if (!got_dot && *p == '.')
2321               got_dot = 1;
2322             else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
2323                      && (*p == '-' || *p == '+'))
2324               /* This is the sign of the exponent, not the end of the
2325                  number.  */
2326               continue;
2327             /* We will take any letters or digits.  parse_number will
2328                complain if past the radix, or if L or U are not final.  */
2329             else if ((*p < '0' || *p > '9')
2330                      && ((*p < 'a' || *p > 'z')
2331                                   && (*p < 'A' || *p > 'Z')))
2332               break;
2333           }
2334         toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval);
2335         if (toktype == ERROR)
2336           {
2337             char *err_copy = (char *) alloca (p - tokstart + 1);
2338
2339             memcpy (err_copy, tokstart, p - tokstart);
2340             err_copy[p - tokstart] = 0;
2341             error (_("Invalid number \"%s\"."), err_copy);
2342           }
2343         lexptr = p;
2344         return toktype;
2345       }
2346
2347     case '@':
2348       {
2349         char *p = &tokstart[1];
2350         size_t len = strlen ("entry");
2351
2352         while (isspace (*p))
2353           p++;
2354         if (strncmp (p, "entry", len) == 0 && !isalnum (p[len])
2355             && p[len] != '_')
2356           {
2357             lexptr = &p[len];
2358             return ENTRY;
2359           }
2360       }
2361       /* FALLTHRU */
2362     case '+':
2363     case '-':
2364     case '*':
2365     case '/':
2366     case '%':
2367     case '|':
2368     case '&':
2369     case '^':
2370     case '~':
2371     case '!':
2372     case '<':
2373     case '>':
2374     case '?':
2375     case ':':
2376     case '=':
2377     case '{':
2378     case '}':
2379     symbol:
2380       lexptr++;
2381       return c;
2382
2383     case 'L':
2384     case 'u':
2385     case 'U':
2386       if (tokstart[1] != '"' && tokstart[1] != '\'')
2387         break;
2388       /* Fall through.  */
2389     case '\'':
2390     case '"':
2391       {
2392         int host_len;
2393         int result = parse_string_or_char (tokstart, &lexptr, &yylval.tsval,
2394                                            &host_len);
2395         if (result == CHAR)
2396           {
2397             if (host_len == 0)
2398               error (_("Empty character constant."));
2399             else if (host_len > 2 && c == '\'')
2400               {
2401                 ++tokstart;
2402                 namelen = lexptr - tokstart - 1;
2403                 goto tryname;
2404               }
2405             else if (host_len > 1)
2406               error (_("Invalid character constant."));
2407           }
2408         return result;
2409       }
2410     }
2411
2412   if (!(c == '_' || c == '$'
2413         || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
2414     /* We must have come across a bad character (e.g. ';').  */
2415     error (_("Invalid character '%c' in expression."), c);
2416
2417   /* It's a name.  See how long it is.  */
2418   namelen = 0;
2419   for (c = tokstart[namelen];
2420        (c == '_' || c == '$' || (c >= '0' && c <= '9')
2421         || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '<');)
2422     {
2423       /* Template parameter lists are part of the name.
2424          FIXME: This mishandles `print $a<4&&$a>3'.  */
2425
2426       if (c == '<')
2427         {
2428           if (! is_cast_operator (tokstart, namelen))
2429             {
2430               /* Scan ahead to get rest of the template specification.  Note
2431                  that we look ahead only when the '<' adjoins non-whitespace
2432                  characters; for comparison expressions, e.g. "a < b > c",
2433                  there must be spaces before the '<', etc. */
2434                
2435               char * p = find_template_name_end (tokstart + namelen);
2436               if (p)
2437                 namelen = p - tokstart;
2438             }
2439           break;
2440         }
2441       c = tokstart[++namelen];
2442     }
2443
2444   /* The token "if" terminates the expression and is NOT removed from
2445      the input stream.  It doesn't count if it appears in the
2446      expansion of a macro.  */
2447   if (namelen == 2
2448       && tokstart[0] == 'i'
2449       && tokstart[1] == 'f'
2450       && ! scanning_macro_expansion ())
2451     {
2452       return 0;
2453     }
2454
2455   /* For the same reason (breakpoint conditions), "thread N"
2456      terminates the expression.  "thread" could be an identifier, but
2457      an identifier is never followed by a number without intervening
2458      punctuation.  "task" is similar.  Handle abbreviations of these,
2459      similarly to breakpoint.c:find_condition_and_thread.  */
2460   if (namelen >= 1
2461       && (strncmp (tokstart, "thread", namelen) == 0
2462           || strncmp (tokstart, "task", namelen) == 0)
2463       && (tokstart[namelen] == ' ' || tokstart[namelen] == '\t')
2464       && ! scanning_macro_expansion ())
2465     {
2466       char *p = tokstart + namelen + 1;
2467       while (*p == ' ' || *p == '\t')
2468         p++;
2469       if (*p >= '0' && *p <= '9')
2470         return 0;
2471     }
2472
2473   lexptr += namelen;
2474
2475   tryname:
2476
2477   yylval.sval.ptr = tokstart;
2478   yylval.sval.length = namelen;
2479
2480   /* Catch specific keywords.  */
2481   copy = copy_name (yylval.sval);
2482   for (i = 0; i < sizeof ident_tokens / sizeof ident_tokens[0]; i++)
2483     if (strcmp (copy, ident_tokens[i].operator) == 0)
2484       {
2485         if ((ident_tokens[i].flags & FLAG_CXX) != 0
2486             && parse_language->la_language != language_cplus)
2487           break;
2488
2489         if ((ident_tokens[i].flags & FLAG_SHADOW) != 0)
2490           {
2491             int is_a_field_of_this = 0;
2492
2493             if (lookup_symbol (copy, expression_context_block,
2494                                VAR_DOMAIN,
2495                                (parse_language->la_language == language_cplus
2496                                 ? &is_a_field_of_this
2497                                 : NULL))
2498                 != NULL)
2499               {
2500                 /* The keyword is shadowed.  */
2501                 break;
2502               }
2503           }
2504
2505         /* It is ok to always set this, even though we don't always
2506            strictly need to.  */
2507         yylval.opcode = ident_tokens[i].opcode;
2508         return ident_tokens[i].token;
2509       }
2510
2511   if (*tokstart == '$')
2512     return VARIABLE;
2513
2514   if (in_parse_field && *lexptr == '\0')
2515     saw_name_at_eof = 1;
2516   return NAME;
2517 }
2518
2519 /* An object of this type is pushed on a FIFO by the "outer" lexer.  */
2520 typedef struct
2521 {
2522   int token;
2523   YYSTYPE value;
2524 } token_and_value;
2525
2526 DEF_VEC_O (token_and_value);
2527
2528 /* A FIFO of tokens that have been read but not yet returned to the
2529    parser.  */
2530 static VEC (token_and_value) *token_fifo;
2531
2532 /* Non-zero if the lexer should return tokens from the FIFO.  */
2533 static int popping;
2534
2535 /* Temporary storage for c_lex; this holds symbol names as they are
2536    built up.  */
2537 static struct obstack name_obstack;
2538
2539 /* Classify a NAME token.  The contents of the token are in `yylval'.
2540    Updates yylval and returns the new token type.  BLOCK is the block
2541    in which lookups start; this can be NULL to mean the global
2542    scope.  */
2543 static int
2544 classify_name (struct block *block)
2545 {
2546   struct symbol *sym;
2547   char *copy;
2548   int is_a_field_of_this = 0;
2549
2550   copy = copy_name (yylval.sval);
2551
2552   sym = lookup_symbol (copy, block, VAR_DOMAIN, 
2553                        parse_language->la_language == language_cplus
2554                        ? &is_a_field_of_this : (int *) NULL);
2555
2556   if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
2557     {
2558       yylval.ssym.sym = sym;
2559       yylval.ssym.is_a_field_of_this = is_a_field_of_this;
2560       return BLOCKNAME;
2561     }
2562   else if (!sym)
2563     {
2564       /* See if it's a file name. */
2565       struct symtab *symtab;
2566
2567       symtab = lookup_symtab (copy);
2568       if (symtab)
2569         {
2570           yylval.bval = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), STATIC_BLOCK);
2571           return FILENAME;
2572         }
2573     }
2574
2575   if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
2576     {
2577       yylval.tsym.type = SYMBOL_TYPE (sym);
2578       return TYPENAME;
2579     }
2580
2581   yylval.tsym.type
2582     = language_lookup_primitive_type_by_name (parse_language,
2583                                               parse_gdbarch, copy);
2584   if (yylval.tsym.type != NULL)
2585     return TYPENAME;
2586
2587   /* Input names that aren't symbols but ARE valid hex numbers, when
2588      the input radix permits them, can be names or numbers depending
2589      on the parse.  Note we support radixes > 16 here.  */
2590   if (!sym
2591       && ((copy[0] >= 'a' && copy[0] < 'a' + input_radix - 10)
2592           || (copy[0] >= 'A' && copy[0] < 'A' + input_radix - 10)))
2593     {
2594       YYSTYPE newlval;  /* Its value is ignored.  */
2595       int hextype = parse_number (copy, yylval.sval.length, 0, &newlval);
2596       if (hextype == INT)
2597         {
2598           yylval.ssym.sym = sym;
2599           yylval.ssym.is_a_field_of_this = is_a_field_of_this;
2600           return NAME_OR_INT;
2601         }
2602     }
2603
2604   /* Any other kind of symbol */
2605   yylval.ssym.sym = sym;
2606   yylval.ssym.is_a_field_of_this = is_a_field_of_this;
2607
2608   if (sym == NULL
2609       && parse_language->la_language == language_cplus
2610       && !is_a_field_of_this
2611       && !lookup_minimal_symbol (copy, NULL, NULL))
2612     return UNKNOWN_CPP_NAME;
2613
2614   return NAME;
2615 }
2616
2617 /* Like classify_name, but used by the inner loop of the lexer, when a
2618    name might have already been seen.  FIRST_NAME is true if the token
2619    in `yylval' is the first component of a name, false otherwise.  */
2620
2621 static int
2622 classify_inner_name (struct block *block, int first_name)
2623 {
2624   struct type *type, *new_type;
2625   char *copy;
2626
2627   if (first_name)
2628     return classify_name (block);
2629
2630   type = check_typedef (yylval.tsym.type);
2631   if (TYPE_CODE (type) != TYPE_CODE_STRUCT
2632       && TYPE_CODE (type) != TYPE_CODE_UNION
2633       && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
2634     return ERROR;
2635
2636   copy = copy_name (yylval.tsym.stoken);
2637   yylval.ssym.sym = cp_lookup_nested_symbol (yylval.tsym.type, copy, block);
2638   if (yylval.ssym.sym == NULL)
2639     return ERROR;
2640
2641   switch (SYMBOL_CLASS (yylval.ssym.sym))
2642     {
2643     case LOC_BLOCK:
2644     case LOC_LABEL:
2645       return ERROR;
2646
2647     case LOC_TYPEDEF:
2648       yylval.tsym.type = SYMBOL_TYPE (yylval.ssym.sym);;
2649       return TYPENAME;
2650
2651     default:
2652       yylval.ssym.is_a_field_of_this = 0;
2653       return NAME;
2654     }
2655   internal_error (__FILE__, __LINE__, _("not reached"));
2656 }
2657
2658 /* The outer level of a two-level lexer.  This calls the inner lexer
2659    to return tokens.  It then either returns these tokens, or
2660    aggregates them into a larger token.  This lets us work around a
2661    problem in our parsing approach, where the parser could not
2662    distinguish between qualified names and qualified types at the
2663    right point.
2664    
2665    This approach is still not ideal, because it mishandles template
2666    types.  See the comment in lex_one_token for an example.  However,
2667    this is still an improvement over the earlier approach, and will
2668    suffice until we move to better parsing technology.  */
2669 static int
2670 yylex (void)
2671 {
2672   token_and_value current;
2673   int first_was_coloncolon, last_was_coloncolon, first_iter;
2674
2675   if (popping && !VEC_empty (token_and_value, token_fifo))
2676     {
2677       token_and_value tv = *VEC_index (token_and_value, token_fifo, 0);
2678       VEC_ordered_remove (token_and_value, token_fifo, 0);
2679       yylval = tv.value;
2680       return tv.token;
2681     }
2682   popping = 0;
2683
2684   current.token = lex_one_token ();
2685   if (current.token == NAME)
2686     current.token = classify_name (expression_context_block);
2687   if (parse_language->la_language != language_cplus
2688       || (current.token != TYPENAME && current.token != COLONCOLON))
2689     return current.token;
2690
2691   first_was_coloncolon = current.token == COLONCOLON;
2692   last_was_coloncolon = first_was_coloncolon;
2693   obstack_free (&name_obstack, obstack_base (&name_obstack));
2694   if (!last_was_coloncolon)
2695     obstack_grow (&name_obstack, yylval.sval.ptr, yylval.sval.length);
2696   current.value = yylval;
2697   first_iter = 1;
2698   while (1)
2699     {
2700       token_and_value next;
2701
2702       next.token = lex_one_token ();
2703       next.value = yylval;
2704
2705       if (next.token == NAME && last_was_coloncolon)
2706         {
2707           int classification;
2708
2709           classification = classify_inner_name (first_was_coloncolon
2710                                                 ? NULL
2711                                                 : expression_context_block,
2712                                                 first_iter);
2713           /* We keep going until we either run out of names, or until
2714              we have a qualified name which is not a type.  */
2715           if (classification != TYPENAME && classification != NAME)
2716             {
2717               /* Push the final component and leave the loop.  */
2718               VEC_safe_push (token_and_value, token_fifo, &next);
2719               break;
2720             }
2721
2722           /* Update the partial name we are constructing.  */
2723           if (!first_iter)
2724             {
2725               /* We don't want to put a leading "::" into the name.  */
2726               obstack_grow_str (&name_obstack, "::");
2727             }
2728           obstack_grow (&name_obstack, next.value.sval.ptr,
2729                         next.value.sval.length);
2730
2731           yylval.sval.ptr = obstack_base (&name_obstack);
2732           yylval.sval.length = obstack_object_size (&name_obstack);
2733           current.value = yylval;
2734           current.token = classification;
2735
2736           last_was_coloncolon = 0;
2737         }
2738       else if (next.token == COLONCOLON && !last_was_coloncolon)
2739         last_was_coloncolon = 1;
2740       else
2741         {
2742           /* We've reached the end of the name.  */
2743           VEC_safe_push (token_and_value, token_fifo, &next);
2744           break;
2745         }
2746
2747       first_iter = 0;
2748     }
2749
2750   popping = 1;
2751
2752   /* If we ended with a "::", insert it too.  */
2753   if (last_was_coloncolon)
2754     {
2755       token_and_value cc;
2756       memset (&cc, 0, sizeof (token_and_value));
2757       if (first_was_coloncolon && first_iter)
2758         {
2759           yylval = cc.value;
2760           return COLONCOLON;
2761         }
2762       cc.token = COLONCOLON;
2763       VEC_safe_insert (token_and_value, token_fifo, 0, &cc);
2764     }
2765
2766   yylval = current.value;
2767   yylval.sval.ptr = obstack_copy0 (&expansion_obstack,
2768                                    yylval.sval.ptr,
2769                                    yylval.sval.length);
2770   return current.token;
2771 }
2772
2773 int
2774 c_parse (void)
2775 {
2776   int result;
2777   struct cleanup *back_to = make_cleanup (free_current_contents,
2778                                           &expression_macro_scope);
2779
2780   /* Set up the scope for macro expansion.  */
2781   expression_macro_scope = NULL;
2782
2783   if (expression_context_block)
2784     expression_macro_scope
2785       = sal_macro_scope (find_pc_line (expression_context_pc, 0));
2786   else
2787     expression_macro_scope = default_macro_scope ();
2788   if (! expression_macro_scope)
2789     expression_macro_scope = user_macro_scope ();
2790
2791   /* Initialize macro expansion code.  */
2792   obstack_init (&expansion_obstack);
2793   gdb_assert (! macro_original_text);
2794   make_cleanup (scan_macro_cleanup, 0);
2795
2796   make_cleanup_restore_integer (&yydebug);
2797   yydebug = parser_debug;
2798
2799   /* Initialize some state used by the lexer.  */
2800   last_was_structop = 0;
2801   saw_name_at_eof = 0;
2802
2803   VEC_free (token_and_value, token_fifo);
2804   popping = 0;
2805   obstack_init (&name_obstack);
2806   make_cleanup_obstack_free (&name_obstack);
2807
2808   result = yyparse ();
2809   do_cleanups (back_to);
2810   return result;
2811 }
2812
2813
2814 void
2815 yyerror (char *msg)
2816 {
2817   if (prev_lexptr)
2818     lexptr = prev_lexptr;
2819
2820   error (_("A %s in expression, near `%s'."), (msg ? msg : "error"), lexptr);
2821 }