OSDN Git Service

* cp/decl2.c (cxx_decode_option): Support -fno-builtin-foo.
[pf3gnuchains/gcc-fork.git] / gcc / cp / parse.y
1 /* YACC parser for C++ syntax.
2    Copyright (C) 1988, 1989, 1993, 1994, 1995, 1996, 1997, 1998,
3    1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4    Hacked by Michael Tiemann (tiemann@cygnus.com)
5
6 This file is part of GNU CC.
7
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING.  If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.  */
22
23
24 /* This grammar is based on the GNU CC grammar.  */
25
26 /* Note: Bison automatically applies a default action of "$$ = $1" for
27    all derivations; this is applied before the explicit action, if one
28    is given.  Keep this in mind when reading the actions.  */
29
30 %{
31 #include "config.h"
32
33 #include "system.h"
34
35 #include "tree.h"
36 #include "input.h"
37 #include "flags.h"
38 #include "cp-tree.h"
39 #include "decl.h"
40 #include "lex.h"
41 #include "c-pragma.h"           /* For YYDEBUG definition.  */
42 #include "output.h"
43 #include "except.h"
44 #include "toplev.h"
45 #include "ggc.h"
46
47 extern struct obstack permanent_obstack;
48
49 /* Like YYERROR but do call yyerror.  */
50 #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
51
52 /* Like the default stack expander, except (1) use realloc when possible,
53    (2) impose no hard maxiumum on stack size, (3) REALLY do not use alloca.
54
55    Irritatingly, YYSTYPE is defined after this %{ %} block, so we cannot
56    give malloced_yyvs its proper type.  This is ok since all we need from
57    it is to be able to free it.  */
58
59 static short *malloced_yyss;
60 static void *malloced_yyvs;
61
62 #define yyoverflow(MSG, SS, SSSIZE, VS, VSSIZE, YYSSZ)                  \
63 do {                                                                    \
64   size_t newsize;                                                       \
65   short *newss;                                                         \
66   YYSTYPE *newvs;                                                       \
67   newsize = *(YYSSZ) *= 2;                                              \
68   if (malloced_yyss)                                                    \
69     {                                                                   \
70       newss = (short *)                                                 \
71         really_call_realloc (*(SS), newsize * sizeof (short));          \
72       newvs = (YYSTYPE *)                                               \
73         really_call_realloc (*(VS), newsize * sizeof (YYSTYPE));        \
74     }                                                                   \
75   else                                                                  \
76     {                                                                   \
77       newss = (short *) really_call_malloc (newsize * sizeof (short));  \
78       newvs = (YYSTYPE *) really_call_malloc (newsize * sizeof (YYSTYPE)); \
79       if (newss)                                                        \
80         memcpy (newss, *(SS), (SSSIZE));                                \
81       if (newvs)                                                        \
82         memcpy (newvs, *(VS), (VSSIZE));                                \
83     }                                                                   \
84   if (!newss || !newvs)                                                 \
85     {                                                                   \
86       yyerror (MSG);                                                    \
87       return 2;                                                         \
88     }                                                                   \
89   *(SS) = newss;                                                        \
90   *(VS) = newvs;                                                        \
91   malloced_yyss = newss;                                                \
92   malloced_yyvs = (void *) newvs;                                       \
93 } while (0)
94 #define OP0(NODE) (TREE_OPERAND (NODE, 0))
95 #define OP1(NODE) (TREE_OPERAND (NODE, 1))
96
97 /* Contains the statement keyword (if/while/do) to include in an
98    error message if the user supplies an empty conditional expression.  */
99 static const char *cond_stmt_keyword;
100
101 /* List of types and structure classes of the current declaration.  */
102 static GTY(()) tree current_declspecs;
103
104 /* List of prefix attributes in effect.
105    Prefix attributes are parsed by the reserved_declspecs and declmods
106    rules.  They create a list that contains *both* declspecs and attrs.  */
107 /* ??? It is not clear yet that all cases where an attribute can now appear in
108    a declspec list have been updated.  */
109 static GTY(()) tree prefix_attributes;
110
111 /* When defining an enumeration, this is the type of the enumeration.  */
112 static GTY(()) tree current_enum_type;
113
114 /* When parsing a conversion operator name, this is the scope of the
115    operator itself.  */
116 static GTY(()) tree saved_scopes;
117
118 static tree empty_parms PARAMS ((void));
119 static tree parse_decl0 PARAMS ((tree, tree, tree, tree, int));
120 static tree parse_decl PARAMS ((tree, tree, int));
121 static void parse_end_decl PARAMS ((tree, tree, tree));
122 static tree parse_field0 PARAMS ((tree, tree, tree, tree, tree, tree));
123 static tree parse_field PARAMS ((tree, tree, tree, tree));
124 static tree parse_bitfield0 PARAMS ((tree, tree, tree, tree, tree));
125 static tree parse_bitfield PARAMS ((tree, tree, tree));
126 static tree parse_method PARAMS ((tree, tree, tree));
127 static void frob_specs PARAMS ((tree, tree));
128 static void check_class_key PARAMS ((tree, tree));
129 static tree parse_scoped_id PARAMS ((tree));
130 static tree parse_xref_tag (tree, tree, int);
131 static tree parse_handle_class_head (tree, tree, tree, int, int *);
132 static void parse_decl_instantiation (tree, tree, tree);
133 static int parse_begin_function_definition (tree, tree);
134
135 /* Cons up an empty parameter list.  */
136 static inline tree
137 empty_parms ()
138 {
139   tree parms;
140
141 #ifndef NO_IMPLICIT_EXTERN_C
142   if (in_system_header && current_class_type == NULL
143       && current_lang_name == lang_name_c)
144     parms = NULL_TREE;
145   else
146 #endif
147   parms = void_list_node;
148   return parms;
149 }
150
151 /* Record the decl-specifiers, attributes and type lookups from the
152    decl-specifier-seq in a declaration.  */
153
154 static void
155 frob_specs (specs_attrs, lookups)
156      tree specs_attrs, lookups;
157 {
158   save_type_access_control (lookups);
159   split_specs_attrs (specs_attrs, &current_declspecs, &prefix_attributes);
160   if (current_declspecs
161       && TREE_CODE (current_declspecs) != TREE_LIST)
162     current_declspecs = build_tree_list (NULL_TREE, current_declspecs);
163   if (have_extern_spec)
164     {
165       /* We have to indicate that there is an "extern", but that it
166          was part of a language specifier.  For instance,
167
168             extern "C" typedef int (*Ptr) ();
169
170          is well formed.  */
171       current_declspecs = tree_cons (error_mark_node,
172                                      get_identifier ("extern"),
173                                      current_declspecs);
174       have_extern_spec = false;
175     }
176 }
177
178 static tree
179 parse_decl (declarator, attributes, initialized)
180      tree declarator, attributes;
181      int initialized;
182 {
183   return start_decl (declarator, current_declspecs, initialized,
184                      attributes, prefix_attributes);
185 }
186
187 static tree
188 parse_decl0 (declarator, specs_attrs, lookups, attributes, initialized)
189      tree declarator, specs_attrs, lookups, attributes;
190      int initialized;
191 {
192   frob_specs (specs_attrs, lookups);
193   return parse_decl (declarator, attributes, initialized);
194 }
195
196 static void
197 parse_end_decl (decl, init, asmspec)
198      tree decl, init, asmspec;
199 {
200   /* If decl is NULL_TREE, then this was a variable declaration using
201      () syntax for the initializer, so we handled it in grokdeclarator.  */
202   if (decl)
203     decl_type_access_control (decl);
204   cp_finish_decl (decl, init, asmspec, init ? LOOKUP_ONLYCONVERTING : 0);
205 }
206
207 static tree
208 parse_field (declarator, attributes, asmspec, init)
209      tree declarator, attributes, asmspec, init;
210 {
211   tree d = grokfield (declarator, current_declspecs, init, asmspec,
212                       chainon (attributes, prefix_attributes));
213   decl_type_access_control (d);
214   return d;
215 }
216
217 static tree
218 parse_field0 (declarator, specs_attrs, lookups, attributes, asmspec, init)
219      tree declarator, specs_attrs, lookups, attributes, asmspec, init;
220 {
221   frob_specs (specs_attrs, lookups);
222   return parse_field (declarator, attributes, asmspec, init);
223 }
224
225 static tree
226 parse_bitfield (declarator, attributes, width)
227      tree declarator, attributes, width;
228 {
229   tree d = grokbitfield (declarator, current_declspecs, width);
230   cplus_decl_attributes (&d, chainon (attributes, prefix_attributes), 0);
231   decl_type_access_control (d);
232   return d;
233 }
234
235 static tree
236 parse_bitfield0 (declarator, specs_attrs, lookups, attributes, width)
237      tree declarator, specs_attrs, lookups, attributes, width;
238 {
239   frob_specs (specs_attrs, lookups);
240   return parse_bitfield (declarator, attributes, width);
241 }
242
243 static tree
244 parse_method (declarator, specs_attrs, lookups)
245      tree declarator, specs_attrs, lookups;
246 {
247   tree d;
248   frob_specs (specs_attrs, lookups);
249   d = start_method (current_declspecs, declarator, prefix_attributes);
250   decl_type_access_control (d);
251   return d;
252 }
253
254 static void
255 check_class_key (key, aggr)
256      tree key;
257      tree aggr;
258 {
259   if (TREE_CODE (key) == TREE_LIST)
260     key = TREE_VALUE (key);
261   if ((key == union_type_node) != (TREE_CODE (aggr) == UNION_TYPE))
262     pedwarn ("`%s' tag used in naming `%#T'",
263              key == union_type_node ? "union"
264              : key == record_type_node ? "struct" : "class", aggr);
265 }
266
267 %}
268
269 %start program
270
271 %union { GTY(())
272   long itype;
273   tree ttype;
274   char *strtype;
275   enum tree_code code;
276   flagged_type_tree ftype;
277   struct unparsed_text *pi;
278 }
279
280 /* All identifiers that are not reserved words
281    and are not declared typedefs in the current block */
282 %token IDENTIFIER
283
284 /* All identifiers that are declared typedefs in the current block.
285    In some contexts, they are treated just like IDENTIFIER,
286    but they can also serve as typespecs in declarations.  */
287 %token tTYPENAME
288 %token SELFNAME
289
290 /* A template function.  */
291 %token PFUNCNAME
292
293 /* Reserved words that specify storage class.
294    yylval contains an IDENTIFIER_NODE which indicates which one.  */
295 %token SCSPEC
296
297 /* Reserved words that specify type.
298    yylval contains an IDENTIFIER_NODE which indicates which one.  */
299 %token TYPESPEC
300
301 /* Reserved words that qualify type: "const" or "volatile".
302    yylval contains an IDENTIFIER_NODE which indicates which one.  */
303 %token CV_QUALIFIER
304
305 /* Character or numeric constants.
306    yylval is the node for the constant.  */
307 %token CONSTANT
308
309 /* __func__, __FUNCTION__ or __PRETTY_FUNCTION__.
310    yylval contains an IDENTIFIER_NODE which indicates which one.  */
311 %token <ttype> VAR_FUNC_NAME
312
313 /* String constants in raw form.
314    yylval is a STRING_CST node.  */
315 %token STRING
316
317 /* "...", used for functions with variable arglists.  */
318 %token ELLIPSIS
319
320 /* the reserved words */
321 /* SCO include files test "ASM", so use something else.  */
322 %token SIZEOF ENUM /* STRUCT UNION */ IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
323 %token BREAK CONTINUE RETURN_KEYWORD GOTO ASM_KEYWORD TYPEOF ALIGNOF
324 %token SIGOF
325 %token ATTRIBUTE EXTENSION LABEL
326 %token REALPART IMAGPART VA_ARG
327
328 /* the reserved words... C++ extensions */
329 %token <ttype> AGGR
330 %token <ttype> VISSPEC
331 %token DELETE NEW THIS OPERATOR CXX_TRUE CXX_FALSE
332 %token NAMESPACE TYPENAME_KEYWORD USING
333 %token LEFT_RIGHT TEMPLATE
334 %token TYPEID DYNAMIC_CAST STATIC_CAST REINTERPRET_CAST CONST_CAST
335 %token SCOPE EXPORT
336
337 /* Define the operator tokens and their precedences.
338    The value is an integer because, if used, it is the tree code
339    to use in the expression made from the operator.  */
340
341 %left EMPTY                     /* used to resolve s/r with epsilon */
342
343 %left error
344
345 /* Add precedence rules to solve dangling else s/r conflict */
346 %nonassoc IF
347 %nonassoc ELSE
348
349 %left IDENTIFIER PFUNCNAME tTYPENAME SELFNAME PTYPENAME SCSPEC TYPESPEC CV_QUALIFIER ENUM AGGR ELLIPSIS TYPEOF SIGOF OPERATOR NSNAME TYPENAME_KEYWORD ATTRIBUTE
350
351 %left '{' ',' ';'
352
353 %nonassoc THROW
354 %right <code> ':'
355 %right <code> ASSIGN '='
356 %right <code> '?'
357 %left <code> OROR
358 %left <code> ANDAND
359 %left <code> '|'
360 %left <code> '^'
361 %left <code> '&'
362 %left <code> MIN_MAX
363 %left <code> EQCOMPARE
364 %left <code> ARITHCOMPARE '<' '>'
365 %left <code> LSHIFT RSHIFT
366 %left <code> '+' '-'
367 %left <code> '*' '/' '%'
368 %left <code> POINTSAT_STAR DOT_STAR
369 %right <code> UNARY PLUSPLUS MINUSMINUS '~'
370 %left HYPERUNARY
371 %left <ttype> LEFT_RIGHT
372 %left <code> POINTSAT '.' '(' '['
373
374 %right SCOPE                    /* C++ extension */
375 %nonassoc NEW DELETE TRY CATCH
376
377 %type <code> unop
378
379 %type <ttype> identifier IDENTIFIER tTYPENAME CONSTANT expr nonnull_exprlist
380 %type <ttype> PFUNCNAME maybe_identifier
381 %type <ttype> paren_expr_or_null nontrivial_exprlist SELFNAME
382 %type <ttype> expr_no_commas expr_no_comma_rangle
383 %type <ttype> cast_expr unary_expr primary STRING
384 %type <ttype> reserved_declspecs boolean_literal
385 %type <ttype> reserved_typespecquals
386 %type <ttype> SCSPEC TYPESPEC CV_QUALIFIER maybe_cv_qualifier
387 %type <ttype> init initlist maybeasm maybe_init defarg defarg1
388 %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
389 %type <ttype> maybe_attribute attributes attribute attribute_list attrib
390 %type <ttype> any_word
391
392 %type <itype> save_lineno
393 %type <ttype> simple_stmt simple_if
394
395 %type <ttype> declarator notype_declarator after_type_declarator
396 %type <ttype> notype_declarator_intern absdcl_intern
397 %type <ttype> after_type_declarator_intern
398 %type <ttype> direct_notype_declarator direct_after_type_declarator
399 %type <itype> components notype_components
400 %type <ttype> component_decl component_decl_1
401 %type <ttype> component_declarator component_declarator0
402 %type <ttype> notype_component_declarator notype_component_declarator0
403 %type <ttype> after_type_component_declarator after_type_component_declarator0
404 %type <ttype> absdcl cv_qualifiers
405 %type <ttype> direct_abstract_declarator conversion_declarator
406 %type <ttype> new_declarator direct_new_declarator
407 %type <ttype> xexpr parmlist parms bad_parm
408 %type <ttype> identifiers_or_typenames
409 %type <ttype> fcast_or_absdcl regcast_or_absdcl
410 %type <ttype> expr_or_declarator expr_or_declarator_intern
411 %type <ttype> complex_notype_declarator
412 %type <ttype> notype_unqualified_id unqualified_id qualified_id
413 %type <ttype> template_id do_id object_template_id notype_template_declarator
414 %type <ttype> overqualified_id notype_qualified_id any_id
415 %type <ttype> complex_direct_notype_declarator functional_cast
416 %type <ttype> complex_parmlist parms_comma
417 %type <ttype> namespace_qualifier namespace_using_decl
418
419 %type <ftype> type_id new_type_id typed_typespecs typespec typed_declspecs
420 %type <ftype> typed_declspecs1 type_specifier_seq nonempty_cv_qualifiers
421 %type <ftype> structsp typespecqual_reserved parm named_parm full_parm
422 %type <ftype> declmods
423
424 %type <itype> extension
425
426 /* C++ extensions */
427 %token <ttype> PTYPENAME
428 %token <ttype> EXTERN_LANG_STRING ALL
429 %token <ttype> PRE_PARSED_CLASS_DECL DEFARG DEFARG_MARKER
430 %token <pi> PRE_PARSED_FUNCTION_DECL
431 %type <ttype> component_constructor_declarator
432 %type <ttype> fn_def2 return_id constructor_declarator
433 %type <ttype> begin_function_body_
434 %type <ttype> class_head class_head_apparent_template
435 %type <ftype> class_head_decl class_head_defn
436 %type <ttype> base_class_list
437 %type <ttype> base_class_access_list
438 %type <ttype> base_class maybe_base_class_list base_class_1
439 %type <ttype> exception_specification_opt ansi_raise_identifier ansi_raise_identifiers
440 %type <ttype> operator_name
441 %type <ttype> object aggr
442 %type <itype> new delete
443 /* %type <ttype> primary_no_id */
444 %type <ttype> maybe_parmlist
445 %type <ttype> member_init
446 %type <ftype> member_init_list
447 %type <ttype> template_parm_header template_spec_header template_header
448 %type <ttype> template_parm_list template_parm
449 %type <ttype> template_type_parm template_template_parm
450 %type <code>  template_close_bracket
451 %type <ttype> apparent_template_type
452 %type <ttype> template_type template_arg_list template_arg_list_opt
453 %type <ttype> template_arg
454 %type <ttype> condition xcond paren_cond_or_null
455 %type <ttype> type_name nested_name_specifier nested_type ptr_to_mem
456 %type <ttype> complete_type_name notype_identifier nonnested_type
457 %type <ttype> complex_type_name nested_name_specifier_1
458 %type <ttype> new_initializer new_placement
459 %type <ttype> using_decl
460 %type <ttype> typename_sub typename_sub0 typename_sub1 typename_sub2
461 %type <ttype> explicit_template_type
462 /* in order to recognize aggr tags as defining and thus shadowing.  */
463 %token TYPENAME_DEFN IDENTIFIER_DEFN PTYPENAME_DEFN
464 %type <ttype> identifier_defn IDENTIFIER_DEFN TYPENAME_DEFN PTYPENAME_DEFN
465 %type <ttype> handler_args
466 %type <ttype> self_template_type finish_template_type_
467
468 %token NSNAME
469 %type <ttype> NSNAME
470
471 /* Used in lex.c for parsing pragmas.  */
472 %token END_OF_LINE
473
474 /* lex.c and pt.c depend on this being the last token.  Define
475    any new tokens before this one!  */
476 %token END_OF_SAVED_INPUT
477 \f
478 %{
479 /* Tell yyparse how to print a token's value, if yydebug is set.  */
480 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
481 extern void yyprint                     PARAMS ((FILE *, int, YYSTYPE));
482 %}
483 \f
484 %%
485 program:
486           /* empty */
487                { finish_translation_unit (); }
488         | extdefs
489                { finish_translation_unit (); }
490         ;
491
492 /* the reason for the strange actions in this rule
493  is so that notype_initdecls when reached via datadef
494  can find a valid list of type and sc specs in $0.  */
495
496 extdefs:
497                 { $<ttype>$ = NULL_TREE; }
498           lang_extdef
499                 { $<ttype>$ = NULL_TREE; ggc_collect (); }
500         | extdefs lang_extdef
501                 { $<ttype>$ = NULL_TREE; ggc_collect (); }
502         ;
503
504 extdefs_opt:
505           extdefs
506         | /* empty */
507         ;
508
509 .hush_warning:
510                 { have_extern_spec = true;
511                   $<ttype>$ = NULL_TREE; }
512         ;
513 .warning_ok:
514                 { have_extern_spec = false; }
515         ;
516
517 extension:
518         EXTENSION
519                 { $$ = pedantic;
520                   pedantic = 0; }
521         ;
522
523 asm_keyword:
524           ASM_KEYWORD
525         ;
526
527 lang_extdef:
528                 { if (pending_lang_change) do_pending_lang_change();
529                   type_lookups = NULL_TREE; }
530           extdef
531                 { if (! toplevel_bindings_p ())
532                   pop_everything (); }
533         ;
534
535 extdef:
536           fndef eat_saved_input
537                 { do_pending_inlines (); }
538         | datadef
539                 { do_pending_inlines (); }
540
541         | EXPORT
542                 { warning ("keyword `export' not implemented, and will be ignored"); }
543           template_def
544                 { do_pending_inlines (); }
545         | template_def
546                 { do_pending_inlines (); }
547         | asm_keyword '(' STRING ')' ';'
548                 { assemble_asm ($3); }
549         | extern_lang_string '{' extdefs_opt '}'
550                 { pop_lang_context (); }
551         | extern_lang_string .hush_warning fndef .warning_ok eat_saved_input
552                 { do_pending_inlines (); pop_lang_context (); }
553         | extern_lang_string .hush_warning datadef .warning_ok
554                 { do_pending_inlines (); pop_lang_context (); }
555         | NAMESPACE identifier '{'
556                 { push_namespace ($2); }
557           extdefs_opt '}'
558                 { pop_namespace (); }
559         | NAMESPACE '{'
560                 { push_namespace (NULL_TREE); }
561           extdefs_opt '}'
562                 { pop_namespace (); }
563         | namespace_alias
564         | using_decl ';'
565                 { do_toplevel_using_decl ($1); }
566         | using_directive
567         | extension extdef
568                 { pedantic = $1; }
569         ;
570
571 namespace_alias:
572           NAMESPACE identifier '='
573                 { begin_only_namespace_names (); }
574           any_id ';'
575                 {
576                   end_only_namespace_names ();
577                   if (lastiddecl)
578                     $5 = lastiddecl;
579                   do_namespace_alias ($2, $5);
580                 }
581         ;
582
583 using_decl:
584           USING qualified_id
585                 { $$ = $2; }
586         | USING global_scope qualified_id
587                 { $$ = $3; }
588         | USING global_scope unqualified_id
589                 { $$ = $3; }
590         ;
591
592 namespace_using_decl:
593           USING namespace_qualifier identifier
594                 { $$ = build_nt (SCOPE_REF, $2, $3); }
595         | USING global_scope identifier
596                 { $$ = build_nt (SCOPE_REF, global_namespace, $3); }
597         | USING global_scope namespace_qualifier identifier
598                 { $$ = build_nt (SCOPE_REF, $3, $4); }
599         ;
600
601 using_directive:
602           USING NAMESPACE
603                 { begin_only_namespace_names (); }
604           any_id ';'
605                 {
606                   end_only_namespace_names ();
607                   /* If no declaration was found, the using-directive is
608                      invalid. Since that was not reported, we need the
609                      identifier for the error message. */
610                   if (TREE_CODE ($4) == IDENTIFIER_NODE && lastiddecl)
611                     $4 = lastiddecl;
612                   do_using_directive ($4);
613                 }
614         ;
615
616 namespace_qualifier:
617           NSNAME SCOPE
618                 {
619                   if (TREE_CODE ($$) == IDENTIFIER_NODE)
620                     $$ = lastiddecl;
621                   got_scope = $$;
622                 }
623         | namespace_qualifier NSNAME SCOPE
624                 {
625                   $$ = $2;
626                   if (TREE_CODE ($$) == IDENTIFIER_NODE)
627                     $$ = lastiddecl;
628                   got_scope = $$;
629                 }
630         ;
631
632 any_id:
633           unqualified_id
634         | qualified_id
635         | global_scope qualified_id
636                 { $$ = $2; }
637         | global_scope unqualified_id
638                 { $$ = $2; }
639         ;
640
641 extern_lang_string:
642         EXTERN_LANG_STRING
643                 { push_lang_context ($1); }
644         | extern_lang_string EXTERN_LANG_STRING
645                 { if (current_lang_name != $2)
646                     error ("use of linkage spec `%D' is different from previous spec `%D'", $2, current_lang_name);
647                   pop_lang_context (); push_lang_context ($2); }
648         ;
649
650 template_parm_header:
651           TEMPLATE '<'
652                 { begin_template_parm_list (); }
653           template_parm_list '>'
654                 { $$ = end_template_parm_list ($4); }
655         ;
656
657 template_spec_header:
658           TEMPLATE '<' '>'
659                 { begin_specialization();
660                   $$ = NULL_TREE; }
661         ;
662
663 template_header:
664           template_parm_header
665         | template_spec_header
666         ;
667
668 template_parm_list:
669           template_parm
670                 { $$ = process_template_parm (NULL_TREE, $1); }
671         | template_parm_list ',' template_parm
672                 { $$ = process_template_parm ($1, $3); }
673         ;
674
675 maybe_identifier:
676           identifier
677                 { $$ = $1; }
678         |       /* empty */
679                 { $$ = NULL_TREE; }
680         ;
681
682 template_type_parm:
683           aggr maybe_identifier
684                 { $$ = finish_template_type_parm ($1, $2); }
685         | TYPENAME_KEYWORD maybe_identifier
686                 { $$ = finish_template_type_parm (class_type_node, $2); }
687         ;
688
689 template_template_parm:
690           template_parm_header aggr maybe_identifier
691                 { $$ = finish_template_template_parm ($2, $3); }
692         ;
693
694 template_parm:
695         /* The following rules introduce a new reduce/reduce
696            conflict on the ',' and '>' input tokens: they are valid
697            prefixes for a `structsp', which means they could match a
698            nameless parameter.  See 14.6, paragraph 3.
699            By putting them before the `parm' rule, we get
700            their match before considering them nameless parameter
701            declarations.  */
702           template_type_parm
703                 { $$ = build_tree_list (NULL_TREE, $1); }
704         | template_type_parm '=' type_id
705                 { $$ = build_tree_list (groktypename ($3.t), $1); }
706         | parm
707                 { $$ = build_tree_list (NULL_TREE, $1.t); }
708         | parm '=' expr_no_comma_rangle
709                 { $$ = build_tree_list ($3, $1.t); }
710         | template_template_parm
711                 { $$ = build_tree_list (NULL_TREE, $1); }
712         | template_template_parm '=' template_arg
713                 {
714                   $3 = check_template_template_default_arg ($3);
715                   $$ = build_tree_list ($3, $1);
716                 }
717         ;
718
719 template_def:
720           template_header template_extdef
721                 { finish_template_decl ($1); }
722         | template_header error  %prec EMPTY
723                 { finish_template_decl ($1); }
724         ;
725
726 template_extdef:
727           fndef eat_saved_input
728                 { do_pending_inlines (); }
729         | template_datadef
730                 { do_pending_inlines (); }
731         | template_def
732                 { do_pending_inlines (); }
733         | extern_lang_string .hush_warning fndef .warning_ok eat_saved_input
734                 { do_pending_inlines ();
735                   pop_lang_context (); }
736         | extern_lang_string .hush_warning template_datadef .warning_ok
737                 { do_pending_inlines ();
738                   pop_lang_context (); }
739         | extension template_extdef
740                 { pedantic = $1; }
741         ;
742
743 template_datadef:
744           nomods_initdecls ';'
745         | declmods notype_initdecls ';'
746                 {}
747         | typed_declspecs initdecls ';'
748                 { note_list_got_semicolon ($1.t); }
749         | structsp ';'
750                 {
751                   if ($1.t != error_mark_node)
752                     {
753                       maybe_process_partial_specialization ($1.t);
754                       note_got_semicolon ($1.t);
755                     }
756                 }
757         ;
758
759 datadef:
760           nomods_initdecls ';'
761         | declmods notype_initdecls ';'
762                 {}
763         | typed_declspecs initdecls ';'
764                 { note_list_got_semicolon ($1.t); }
765         | declmods ';'
766                 { pedwarn ("empty declaration"); }
767         | explicit_instantiation ';'
768         | typed_declspecs ';'
769                 {
770                   tree t, attrs;
771                   split_specs_attrs ($1.t, &t, &attrs);
772                   shadow_tag (t);
773                   note_list_got_semicolon ($1.t);
774                 }
775         | error ';'
776         | error '}'
777         | error END_OF_SAVED_INPUT
778                 { end_input (); }
779         | ';'
780         | bad_decl
781         ;
782
783 ctor_initializer_opt:
784           nodecls
785         | base_init
786         ;
787
788 maybe_return_init:
789           /* empty */
790         | return_init
791         | return_init ';'
792         ;
793
794 eat_saved_input:
795           /* empty */
796         | END_OF_SAVED_INPUT
797         ;
798
799 /* The outermost block of a function really begins before the
800    mem-initializer-list, so we open one there and suppress the one that
801    actually corresponds to the curly braces.  */
802 function_body:
803           begin_function_body_ ctor_initializer_opt save_lineno '{'
804                 { $<ttype>$ = begin_compound_stmt (/*has_no_scope=*/1); }
805           compstmtend
806                 {
807                   STMT_LINENO ($<ttype>5) = $3;
808                   finish_compound_stmt (/*has_no_scope=*/1, $<ttype>5);
809                   finish_function_body ($1);
810                 }
811         ;
812
813 fndef:
814           fn.def1 maybe_return_init function_body
815                 { expand_body (finish_function (0)); }
816         | fn.def1 maybe_return_init function_try_block
817                 { expand_body (finish_function (0)); }
818         | fn.def1 maybe_return_init error
819                 { }
820         ;
821
822 constructor_declarator:
823           nested_name_specifier SELFNAME '('
824                 { $$ = begin_constructor_declarator ($1, $2); }
825           parmlist ')' cv_qualifiers exception_specification_opt
826                 { $$ = make_call_declarator ($<ttype>4, $5, $7, $8); }
827         | nested_name_specifier SELFNAME LEFT_RIGHT cv_qualifiers exception_specification_opt
828                 { $$ = begin_constructor_declarator ($1, $2);
829                   $$ = make_call_declarator ($$, empty_parms (), $4, $5);
830                 }
831         | global_scope nested_name_specifier SELFNAME '('
832                 { $$ = begin_constructor_declarator ($2, $3); }
833          parmlist ')' cv_qualifiers exception_specification_opt
834                 { $$ = make_call_declarator ($<ttype>5, $6, $8, $9); }
835         | global_scope nested_name_specifier SELFNAME LEFT_RIGHT cv_qualifiers exception_specification_opt
836                 { $$ = begin_constructor_declarator ($2, $3);
837                   $$ = make_call_declarator ($$, empty_parms (), $5, $6);
838                 }
839         | nested_name_specifier self_template_type '('
840                 { $$ = begin_constructor_declarator ($1, $2); }
841           parmlist ')' cv_qualifiers exception_specification_opt
842                 { $$ = make_call_declarator ($<ttype>4, $5, $7, $8); }
843         | nested_name_specifier self_template_type LEFT_RIGHT cv_qualifiers exception_specification_opt
844                 { $$ = begin_constructor_declarator ($1, $2);
845                   $$ = make_call_declarator ($$, empty_parms (), $4, $5);
846                 }
847         | global_scope nested_name_specifier self_template_type '('
848                 { $$ = begin_constructor_declarator ($2, $3); }
849          parmlist ')' cv_qualifiers exception_specification_opt
850                 { $$ = make_call_declarator ($<ttype>5, $6, $8, $9); }
851         | global_scope nested_name_specifier self_template_type LEFT_RIGHT cv_qualifiers exception_specification_opt
852                 { $$ = begin_constructor_declarator ($2, $3);
853                   $$ = make_call_declarator ($$, empty_parms (), $5, $6);
854                 }
855         ;
856
857 fn.def1:
858           typed_declspecs declarator
859                 { check_for_new_type ("return type", $1);
860                   if (!parse_begin_function_definition ($1.t, $2))
861                     YYERROR1; }
862         | declmods notype_declarator
863                 { if (!parse_begin_function_definition ($1.t, $2))
864                     YYERROR1; }
865         | notype_declarator
866                 { if (!parse_begin_function_definition (NULL_TREE, $1))
867                     YYERROR1; }
868         | declmods constructor_declarator
869                 { if (!parse_begin_function_definition ($1.t, $2))
870                     YYERROR1; }
871         | constructor_declarator
872                 { if (!parse_begin_function_definition (NULL_TREE, $1))
873                     YYERROR1; }
874         ;
875
876 /* ANSI allows optional parentheses around constructor class names.
877    See ISO/IEC 14882:1998(E) 12.1.  */
878
879 component_constructor_declarator:
880           SELFNAME '(' parmlist ')' cv_qualifiers exception_specification_opt
881                 { $$ = make_call_declarator ($1, $3, $5, $6); }
882         | '(' SELFNAME ')' '(' parmlist ')' cv_qualifiers
883                 exception_specification_opt
884                 { $$ = make_call_declarator ($2, $5, $7, $8); }
885         | SELFNAME LEFT_RIGHT cv_qualifiers exception_specification_opt
886                 { $$ = make_call_declarator ($1, empty_parms (), $3, $4); }
887         | '(' SELFNAME ')' LEFT_RIGHT cv_qualifiers exception_specification_opt
888                 { $$ = make_call_declarator ($2, empty_parms (), $5, $6); }
889         | self_template_type '(' parmlist ')' cv_qualifiers exception_specification_opt
890                 { $$ = make_call_declarator ($1, $3, $5, $6); }
891         | self_template_type LEFT_RIGHT cv_qualifiers exception_specification_opt
892                 { $$ = make_call_declarator ($1, empty_parms (), $3, $4); }
893         ;
894
895 /* more C++ complexity.  See component_decl for a comment on the
896    reduce/reduce conflict introduced by these rules.  */
897 fn_def2:
898           declmods component_constructor_declarator
899                 { $$ = parse_method ($2, $1.t, $1.lookups);
900                  rest_of_mdef:
901                   if (! $$)
902                     YYERROR1;
903                   if (yychar == YYEMPTY)
904                     yychar = YYLEX;
905                   snarf_method ($$); }
906         | component_constructor_declarator
907                 { $$ = parse_method ($1, NULL_TREE, NULL_TREE);
908                   goto rest_of_mdef; }
909         | typed_declspecs declarator
910                 { $$ = parse_method ($2, $1.t, $1.lookups); goto rest_of_mdef;}
911         | declmods notype_declarator
912                 { $$ = parse_method ($2, $1.t, $1.lookups); goto rest_of_mdef;}
913         | notype_declarator
914                 { $$ = parse_method ($1, NULL_TREE, NULL_TREE);
915                   goto rest_of_mdef; }
916         | declmods constructor_declarator
917                 { $$ = parse_method ($2, $1.t, $1.lookups); goto rest_of_mdef;}
918         | constructor_declarator
919                 { $$ = parse_method ($1, NULL_TREE, NULL_TREE);
920                   goto rest_of_mdef; }
921         ;
922
923 return_id:
924           RETURN_KEYWORD IDENTIFIER
925                 {
926                   $$ = $2;
927                 }
928         ;
929
930 return_init:
931           return_id maybe_init
932                 { finish_named_return_value ($<ttype>$, $2); }
933         | return_id '(' nonnull_exprlist ')'
934                 { finish_named_return_value ($<ttype>$, $3); }
935         | return_id LEFT_RIGHT
936                 { finish_named_return_value ($<ttype>$, NULL_TREE); }
937         ;
938
939 base_init:
940           ':' { begin_mem_initializers (); } member_init_list
941                 {
942                   if ($3.new_type_flag == 0)
943                     error ("no base or member initializers given following ':'");
944                   finish_mem_initializers ($3.t);
945                 }
946         ;
947
948 begin_function_body_:
949           /* empty */
950                 {
951                   $$ = begin_function_body ();
952                 }
953         ;
954
955 member_init_list:
956           /* empty */
957                 {
958                   $$.new_type_flag = 0;
959                   $$.t = NULL_TREE;
960                 }
961         | member_init
962                 {
963                   $$.new_type_flag = 1;
964                   $$.t = $1;
965                 }
966         | member_init_list ',' member_init
967                 {
968                   if ($3)
969                     {
970                       $$.new_type_flag = 1;
971                       TREE_CHAIN ($3) = $1.t;
972                       $$.t = $3;
973                     }
974                   else
975                     $$ = $1;
976                 }
977         | member_init_list error
978         ;
979
980 member_init:
981           '(' nonnull_exprlist ')'
982                 {
983                   if (current_class_name)
984                     pedwarn ("anachronistic old style base class initializer");
985                   $$ = expand_member_init (current_class_ref, NULL_TREE, $2);
986                 }
987         | LEFT_RIGHT
988                 {
989                   if (current_class_name)
990                     pedwarn ("anachronistic old style base class initializer");
991                   $$ = expand_member_init (current_class_ref,
992                                            NULL_TREE,
993                                            void_type_node);
994                 }
995         | notype_identifier '(' nonnull_exprlist ')'
996                 { $$ = expand_member_init (current_class_ref, $1, $3); }
997         | notype_identifier LEFT_RIGHT
998                 { $$ = expand_member_init (current_class_ref, $1,
999                                            void_type_node); }
1000         | nonnested_type '(' nonnull_exprlist ')'
1001                 { $$ = expand_member_init (current_class_ref, $1, $3); }
1002         | nonnested_type LEFT_RIGHT
1003                 { $$ = expand_member_init (current_class_ref, $1,
1004                                            void_type_node); }
1005         | typename_sub '(' nonnull_exprlist ')'
1006                 { $$ = expand_member_init (current_class_ref, $1, $3); }
1007         | typename_sub LEFT_RIGHT
1008                 { $$ = expand_member_init (current_class_ref, $1,
1009                                            void_type_node); }
1010         | error
1011                 { $$ = NULL_TREE; }
1012         ;
1013
1014 identifier:
1015           IDENTIFIER
1016         | tTYPENAME
1017         | SELFNAME
1018         | PTYPENAME
1019         | NSNAME
1020         ;
1021
1022 notype_identifier:
1023           IDENTIFIER
1024         | PTYPENAME
1025         | NSNAME  %prec EMPTY
1026         ;
1027
1028 identifier_defn:
1029           IDENTIFIER_DEFN
1030         | TYPENAME_DEFN
1031         | PTYPENAME_DEFN
1032         ;
1033
1034 explicit_instantiation:
1035           TEMPLATE begin_explicit_instantiation typespec ';'
1036                 { do_type_instantiation ($3.t, NULL_TREE, 1);
1037                   yyungetc (';', 1); }
1038           end_explicit_instantiation
1039         | TEMPLATE begin_explicit_instantiation typed_declspecs declarator
1040                 { tree specs = strip_attrs ($3.t);
1041                   parse_decl_instantiation (specs, $4, NULL_TREE); }
1042           end_explicit_instantiation
1043         | TEMPLATE begin_explicit_instantiation notype_declarator
1044                 { parse_decl_instantiation (NULL_TREE, $3, NULL_TREE); }
1045           end_explicit_instantiation
1046         | TEMPLATE begin_explicit_instantiation constructor_declarator
1047                 { parse_decl_instantiation (NULL_TREE, $3, NULL_TREE); }
1048           end_explicit_instantiation
1049         | SCSPEC TEMPLATE begin_explicit_instantiation typespec ';'
1050                 { do_type_instantiation ($4.t, $1, 1);
1051                   yyungetc (';', 1); }
1052           end_explicit_instantiation
1053                 {}
1054         | SCSPEC TEMPLATE begin_explicit_instantiation typed_declspecs
1055           declarator
1056                 { tree specs = strip_attrs ($4.t);
1057                   parse_decl_instantiation (specs, $5, $1); }
1058           end_explicit_instantiation
1059                 {}
1060         | SCSPEC TEMPLATE begin_explicit_instantiation notype_declarator
1061                 { parse_decl_instantiation (NULL_TREE, $4, $1); }
1062           end_explicit_instantiation
1063                 {}
1064         | SCSPEC TEMPLATE begin_explicit_instantiation constructor_declarator
1065                 { parse_decl_instantiation (NULL_TREE, $4, $1); }
1066           end_explicit_instantiation
1067                 {}
1068         ;
1069
1070 begin_explicit_instantiation:
1071       { begin_explicit_instantiation(); }
1072         ;
1073
1074 end_explicit_instantiation:
1075       { end_explicit_instantiation(); }
1076         ;
1077
1078 /* The TYPENAME expansions are to deal with use of a template class name as
1079   a template within the class itself, where the template decl is hidden by
1080   a type decl.  Got all that?  */
1081
1082 template_type:
1083           PTYPENAME '<' template_arg_list_opt template_close_bracket
1084             finish_template_type_
1085                 { $$ = $5; }
1086         | tTYPENAME  '<' template_arg_list_opt template_close_bracket
1087             finish_template_type_
1088                 { $$ = $5; }
1089         | self_template_type
1090         ;
1091
1092 apparent_template_type:
1093           template_type
1094         | identifier '<' template_arg_list_opt '>'
1095             finish_template_type_
1096                 { $$ = $5; }
1097         ;
1098
1099 self_template_type:
1100           SELFNAME  '<' template_arg_list_opt template_close_bracket
1101             finish_template_type_
1102                 { $$ = $5; }
1103         ;
1104
1105 finish_template_type_:
1106                 {
1107                   if (yychar == YYEMPTY)
1108                     yychar = YYLEX;
1109
1110                   $$ = finish_template_type ($<ttype>-3, $<ttype>-1,
1111                                              yychar == SCOPE);
1112                 }
1113         ;
1114
1115 template_close_bracket:
1116           '>'
1117         | RSHIFT
1118                 {
1119                   /* Handle `Class<Class<Type>>' without space in the `>>' */
1120                   pedwarn ("`>>' should be `> >' in template class name");
1121                   yyungetc ('>', 1);
1122                 }
1123         ;
1124
1125 template_arg_list_opt:
1126          /* empty */
1127                  { $$ = NULL_TREE; }
1128        | template_arg_list
1129        ;
1130
1131 template_arg_list:
1132         template_arg
1133                 { $$ = build_tree_list (NULL_TREE, $$); }
1134         | template_arg_list ',' template_arg
1135                 { $$ = chainon ($$, build_tree_list (NULL_TREE, $3)); }
1136         ;
1137
1138 template_arg:
1139           type_id
1140                 { $$ = groktypename ($1.t); }
1141         | PTYPENAME
1142                 {
1143                   $$ = lastiddecl;
1144                   if (DECL_TEMPLATE_TEMPLATE_PARM_P ($$))
1145                     $$ = TREE_TYPE ($$);
1146                 }
1147         | global_scope PTYPENAME
1148                 {
1149                   $$ = lastiddecl;
1150                   if (DECL_TEMPLATE_TEMPLATE_PARM_P ($$))
1151                     $$ = TREE_TYPE ($$);
1152                 }
1153         | expr_no_comma_rangle
1154         | nested_name_specifier TEMPLATE identifier
1155                 {
1156                   if (!processing_template_decl)
1157                     {
1158                       error ("use of template qualifier outside template");
1159                       $$ = error_mark_node;
1160                     }
1161                   else
1162                     $$ = make_unbound_class_template ($1, $3, tf_error | tf_parsing);
1163                 }
1164         ;
1165
1166 unop:
1167           '-'
1168                 { $$ = NEGATE_EXPR; }
1169         | '+'
1170                 { $$ = CONVERT_EXPR; }
1171         | PLUSPLUS
1172                 { $$ = PREINCREMENT_EXPR; }
1173         | MINUSMINUS
1174                 { $$ = PREDECREMENT_EXPR; }
1175         | '!'
1176                 { $$ = TRUTH_NOT_EXPR; }
1177         ;
1178
1179 expr:
1180           nontrivial_exprlist
1181                 { $$ = build_x_compound_expr ($$); }
1182         | expr_no_commas
1183         ;
1184
1185 paren_expr_or_null:
1186         LEFT_RIGHT
1187                 { error ("ISO C++ forbids an empty condition for `%s'",
1188                          cond_stmt_keyword);
1189                   $$ = integer_zero_node; }
1190         | '(' expr ')'
1191                 { $$ = $2; }
1192         ;
1193
1194 paren_cond_or_null:
1195         LEFT_RIGHT
1196                 { error ("ISO C++ forbids an empty condition for `%s'",
1197                          cond_stmt_keyword);
1198                   $$ = integer_zero_node; }
1199         | '(' condition ')'
1200                 { $$ = $2; }
1201         ;
1202
1203 xcond:
1204           /* empty */
1205                 { $$ = NULL_TREE; }
1206         | condition
1207         | error
1208                 { $$ = NULL_TREE; }
1209         ;
1210
1211 condition:
1212           type_specifier_seq declarator maybeasm maybe_attribute '='
1213                 { {
1214                   tree d;
1215                   for (d = getdecls (); d; d = TREE_CHAIN (d))
1216                     if (TREE_CODE (d) == TYPE_DECL) {
1217                       tree s = TREE_TYPE (d);
1218                       if (TREE_CODE (s) == RECORD_TYPE)
1219                         error ("definition of class `%T' in condition", s);
1220                       else if (TREE_CODE (s) == ENUMERAL_TYPE)
1221                         error ("definition of enum `%T' in condition", s);
1222                     }
1223                   }
1224                   current_declspecs = $1.t;
1225                   $<ttype>$ = parse_decl ($<ttype>2, $4, 1);
1226                 }
1227           init
1228                 {
1229                   parse_end_decl ($<ttype>6, $7, $4);
1230                   $$ = convert_from_reference ($<ttype>6);
1231                   if (TREE_CODE (TREE_TYPE ($$)) == ARRAY_TYPE)
1232                     error ("definition of array `%#D' in condition", $$);
1233                 }
1234         | expr
1235         ;
1236
1237 compstmtend:
1238           '}'
1239         | maybe_label_decls stmts '}'
1240         | maybe_label_decls stmts error '}'
1241         | maybe_label_decls error '}'
1242         ;
1243
1244 nontrivial_exprlist:
1245           expr_no_commas ',' expr_no_commas
1246                 { $$ = tree_cons (NULL_TREE, $$,
1247                                   build_tree_list (NULL_TREE, $3)); }
1248         | expr_no_commas ',' error
1249                 { $$ = tree_cons (NULL_TREE, $$,
1250                                   build_tree_list (NULL_TREE, error_mark_node)); }
1251         | nontrivial_exprlist ',' expr_no_commas
1252                 { chainon ($$, build_tree_list (NULL_TREE, $3)); }
1253         | nontrivial_exprlist ',' error
1254                 { chainon ($$, build_tree_list (NULL_TREE, error_mark_node)); }
1255         ;
1256
1257 nonnull_exprlist:
1258           expr_no_commas
1259                 { $$ = build_tree_list (NULL_TREE, $$); }
1260         | nontrivial_exprlist
1261         ;
1262
1263 unary_expr:
1264           primary  %prec UNARY
1265                 { $$ = $1; }
1266         /* __extension__ turns off -pedantic for following primary.  */
1267         | extension cast_expr     %prec UNARY
1268                 { $$ = $2;
1269                   pedantic = $1; }
1270         | '*' cast_expr   %prec UNARY
1271                 { $$ = build_x_indirect_ref ($2, "unary *"); }
1272         | '&' cast_expr   %prec UNARY
1273                 { $$ = build_x_unary_op (ADDR_EXPR, $2); }
1274         | '~' cast_expr
1275                 { $$ = build_x_unary_op (BIT_NOT_EXPR, $2); }
1276         | unop cast_expr  %prec UNARY
1277                 { $$ = finish_unary_op_expr ($1, $2); }
1278         /* Refer to the address of a label as a pointer.  */
1279         | ANDAND identifier
1280                 { $$ = finish_label_address_expr ($2); }
1281         | SIZEOF unary_expr  %prec UNARY
1282                 { $$ = finish_sizeof ($2); }
1283         | SIZEOF '(' type_id ')'  %prec HYPERUNARY
1284                 { $$ = finish_sizeof (groktypename ($3.t));
1285                   check_for_new_type ("sizeof", $3); }
1286         | ALIGNOF unary_expr  %prec UNARY
1287                 { $$ = finish_alignof ($2); }
1288         | ALIGNOF '(' type_id ')'  %prec HYPERUNARY
1289                 { $$ = finish_alignof (groktypename ($3.t));
1290                   check_for_new_type ("alignof", $3); }
1291
1292         /* The %prec EMPTY's here are required by the = init initializer
1293            syntax extension; see below.  */
1294         | new new_type_id  %prec EMPTY
1295                 { $$ = build_new (NULL_TREE, $2.t, NULL_TREE, $1);
1296                   check_for_new_type ("new", $2); }
1297         | new new_type_id new_initializer
1298                 { $$ = build_new (NULL_TREE, $2.t, $3, $1);
1299                   check_for_new_type ("new", $2); }
1300         | new new_placement new_type_id  %prec EMPTY
1301                 { $$ = build_new ($2, $3.t, NULL_TREE, $1);
1302                   check_for_new_type ("new", $3); }
1303         | new new_placement new_type_id new_initializer
1304                 { $$ = build_new ($2, $3.t, $4, $1);
1305                   check_for_new_type ("new", $3); }
1306         | new '(' type_id ')'
1307             %prec EMPTY
1308                 { $$ = build_new (NULL_TREE, groktypename($3.t),
1309                                   NULL_TREE, $1);
1310                   check_for_new_type ("new", $3); }
1311         | new '(' type_id ')' new_initializer
1312                 { $$ = build_new (NULL_TREE, groktypename($3.t), $5, $1);
1313                   check_for_new_type ("new", $3); }
1314         | new new_placement '(' type_id ')' %prec EMPTY
1315                 { $$ = build_new ($2, groktypename($4.t), NULL_TREE, $1);
1316                   check_for_new_type ("new", $4); }
1317         | new new_placement '(' type_id ')' new_initializer
1318                 { $$ = build_new ($2, groktypename($4.t), $6, $1);
1319                   check_for_new_type ("new", $4); }
1320
1321         | delete cast_expr  %prec UNARY
1322                 { $$ = delete_sanity ($2, NULL_TREE, 0, $1); }
1323         | delete '[' ']' cast_expr  %prec UNARY
1324                 { $$ = delete_sanity ($4, NULL_TREE, 1, $1);
1325                   if (yychar == YYEMPTY)
1326                     yychar = YYLEX; }
1327         | delete '[' expr ']' cast_expr  %prec UNARY
1328                 { $$ = delete_sanity ($5, $3, 2, $1);
1329                   if (yychar == YYEMPTY)
1330                     yychar = YYLEX; }
1331         | REALPART cast_expr %prec UNARY
1332                 { $$ = build_x_unary_op (REALPART_EXPR, $2); }
1333         | IMAGPART cast_expr %prec UNARY
1334                 { $$ = build_x_unary_op (IMAGPART_EXPR, $2); }
1335         ;
1336
1337 new_placement:
1338           '(' nonnull_exprlist ')'
1339                 { $$ = $2; }
1340         | '{' nonnull_exprlist '}'
1341                 { pedwarn ("old style placement syntax, use () instead");
1342                   $$ = $2; }
1343         ;
1344
1345 new_initializer:
1346           '(' nonnull_exprlist ')'
1347                 { $$ = $2; }
1348         | LEFT_RIGHT
1349                 { $$ = void_zero_node; }
1350         | '(' typespec ')'
1351                 {
1352                   error ("`%T' is not a valid expression", $2.t);
1353                   $$ = error_mark_node;
1354                 }
1355         /* GNU extension so people can use initializer lists.  Note that
1356            this alters the meaning of `new int = 1', which was previously
1357            syntactically valid but semantically invalid.
1358            This feature is now deprecated and will be removed in a future
1359            release.  */
1360         | '=' init
1361                 {
1362                   if (pedantic)
1363                     pedwarn ("ISO C++ forbids initialization of new expression with `='");
1364                   cp_deprecated ("new initializer lists extension");
1365                   if (TREE_CODE ($2) != TREE_LIST
1366                       && TREE_CODE ($2) != CONSTRUCTOR)
1367                     $$ = build_tree_list (NULL_TREE, $2);
1368                   else
1369                     $$ = $2;
1370                 }
1371         ;
1372
1373 /* This is necessary to postpone reduction of `int ((int)(int)(int))'.  */
1374 regcast_or_absdcl:
1375           '(' type_id ')'  %prec EMPTY
1376                 { $2.t = finish_parmlist (build_tree_list (NULL_TREE, $2.t), 0);
1377                   $$ = make_call_declarator (NULL_TREE, $2.t, NULL_TREE, NULL_TREE);
1378                   check_for_new_type ("cast", $2); }
1379         | regcast_or_absdcl '(' type_id ')'  %prec EMPTY
1380                 { $3.t = finish_parmlist (build_tree_list (NULL_TREE, $3.t), 0);
1381                   $$ = make_call_declarator ($$, $3.t, NULL_TREE, NULL_TREE);
1382                   check_for_new_type ("cast", $3); }
1383         ;
1384
1385 cast_expr:
1386           unary_expr
1387         | regcast_or_absdcl unary_expr  %prec UNARY
1388                 { $$ = reparse_absdcl_as_casts ($$, $2); }
1389         | regcast_or_absdcl '{' initlist maybecomma '}'  %prec UNARY
1390                 {
1391                   tree init = build_nt (CONSTRUCTOR, NULL_TREE,
1392                                         nreverse ($3));
1393                   if (pedantic)
1394                     pedwarn ("ISO C++ forbids compound literals");
1395                   /* Indicate that this was a C99 compound literal.  */
1396                   TREE_HAS_CONSTRUCTOR (init) = 1;
1397
1398                   $$ = reparse_absdcl_as_casts ($$, init);
1399                 }
1400         ;
1401
1402 expr_no_commas:
1403           cast_expr
1404         /* Handle general members.  */
1405         | expr_no_commas POINTSAT_STAR expr_no_commas
1406                 { $$ = build_x_binary_op (MEMBER_REF, $$, $3); }
1407         | expr_no_commas DOT_STAR expr_no_commas
1408                 { $$ = build_m_component_ref ($$, $3); }
1409         | expr_no_commas '+' expr_no_commas
1410                 { $$ = build_x_binary_op ($2, $$, $3); }
1411         | expr_no_commas '-' expr_no_commas
1412                 { $$ = build_x_binary_op ($2, $$, $3); }
1413         | expr_no_commas '*' expr_no_commas
1414                 { $$ = build_x_binary_op ($2, $$, $3); }
1415         | expr_no_commas '/' expr_no_commas
1416                 { $$ = build_x_binary_op ($2, $$, $3); }
1417         | expr_no_commas '%' expr_no_commas
1418                 { $$ = build_x_binary_op ($2, $$, $3); }
1419         | expr_no_commas LSHIFT expr_no_commas
1420                 { $$ = build_x_binary_op ($2, $$, $3); }
1421         | expr_no_commas RSHIFT expr_no_commas
1422                 { $$ = build_x_binary_op ($2, $$, $3); }
1423         | expr_no_commas ARITHCOMPARE expr_no_commas
1424                 { $$ = build_x_binary_op ($2, $$, $3); }
1425         | expr_no_commas '<' expr_no_commas
1426                 { $$ = build_x_binary_op (LT_EXPR, $$, $3); }
1427         | expr_no_commas '>' expr_no_commas
1428                 { $$ = build_x_binary_op (GT_EXPR, $$, $3); }
1429         | expr_no_commas EQCOMPARE expr_no_commas
1430                 { $$ = build_x_binary_op ($2, $$, $3); }
1431         | expr_no_commas MIN_MAX expr_no_commas
1432                 { $$ = build_x_binary_op ($2, $$, $3); }
1433         | expr_no_commas '&' expr_no_commas
1434                 { $$ = build_x_binary_op ($2, $$, $3); }
1435         | expr_no_commas '|' expr_no_commas
1436                 { $$ = build_x_binary_op ($2, $$, $3); }
1437         | expr_no_commas '^' expr_no_commas
1438                 { $$ = build_x_binary_op ($2, $$, $3); }
1439         | expr_no_commas ANDAND expr_no_commas
1440                 { $$ = build_x_binary_op (TRUTH_ANDIF_EXPR, $$, $3); }
1441         | expr_no_commas OROR expr_no_commas
1442                 { $$ = build_x_binary_op (TRUTH_ORIF_EXPR, $$, $3); }
1443         | expr_no_commas '?' xexpr ':' expr_no_commas
1444                 { $$ = build_x_conditional_expr ($$, $3, $5); }
1445         | expr_no_commas '=' expr_no_commas
1446                 { $$ = build_x_modify_expr ($$, NOP_EXPR, $3);
1447                   if ($$ != error_mark_node)
1448                     C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); }
1449         | expr_no_commas ASSIGN expr_no_commas
1450                 { $$ = build_x_modify_expr ($$, $2, $3); }
1451         | THROW
1452                 { $$ = build_throw (NULL_TREE); }
1453         | THROW expr_no_commas
1454                 { $$ = build_throw ($2); }
1455         ;
1456
1457 expr_no_comma_rangle:
1458           cast_expr
1459         /* Handle general members.  */
1460         | expr_no_comma_rangle POINTSAT_STAR expr_no_comma_rangle
1461                 { $$ = build_x_binary_op (MEMBER_REF, $$, $3); }
1462         | expr_no_comma_rangle DOT_STAR expr_no_comma_rangle
1463                 { $$ = build_m_component_ref ($$, $3); }
1464         | expr_no_comma_rangle '+' expr_no_comma_rangle
1465                 { $$ = build_x_binary_op ($2, $$, $3); }
1466         | expr_no_comma_rangle '-' expr_no_comma_rangle
1467                 { $$ = build_x_binary_op ($2, $$, $3); }
1468         | expr_no_comma_rangle '*' expr_no_comma_rangle
1469                 { $$ = build_x_binary_op ($2, $$, $3); }
1470         | expr_no_comma_rangle '/' expr_no_comma_rangle
1471                 { $$ = build_x_binary_op ($2, $$, $3); }
1472         | expr_no_comma_rangle '%' expr_no_comma_rangle
1473                 { $$ = build_x_binary_op ($2, $$, $3); }
1474         | expr_no_comma_rangle LSHIFT expr_no_comma_rangle
1475                 { $$ = build_x_binary_op ($2, $$, $3); }
1476         | expr_no_comma_rangle RSHIFT expr_no_comma_rangle
1477                 { $$ = build_x_binary_op ($2, $$, $3); }
1478         | expr_no_comma_rangle ARITHCOMPARE expr_no_comma_rangle
1479                 { $$ = build_x_binary_op ($2, $$, $3); }
1480         | expr_no_comma_rangle '<' expr_no_comma_rangle
1481                 { $$ = build_x_binary_op (LT_EXPR, $$, $3); }
1482         | expr_no_comma_rangle EQCOMPARE expr_no_comma_rangle
1483                 { $$ = build_x_binary_op ($2, $$, $3); }
1484         | expr_no_comma_rangle MIN_MAX expr_no_comma_rangle
1485                 { $$ = build_x_binary_op ($2, $$, $3); }
1486         | expr_no_comma_rangle '&' expr_no_comma_rangle
1487                 { $$ = build_x_binary_op ($2, $$, $3); }
1488         | expr_no_comma_rangle '|' expr_no_comma_rangle
1489                 { $$ = build_x_binary_op ($2, $$, $3); }
1490         | expr_no_comma_rangle '^' expr_no_comma_rangle
1491                 { $$ = build_x_binary_op ($2, $$, $3); }
1492         | expr_no_comma_rangle ANDAND expr_no_comma_rangle
1493                 { $$ = build_x_binary_op (TRUTH_ANDIF_EXPR, $$, $3); }
1494         | expr_no_comma_rangle OROR expr_no_comma_rangle
1495                 { $$ = build_x_binary_op (TRUTH_ORIF_EXPR, $$, $3); }
1496         | expr_no_comma_rangle '?' xexpr ':' expr_no_comma_rangle
1497                 { $$ = build_x_conditional_expr ($$, $3, $5); }
1498         | expr_no_comma_rangle '=' expr_no_comma_rangle
1499                 { $$ = build_x_modify_expr ($$, NOP_EXPR, $3);
1500                   if ($$ != error_mark_node)
1501                     C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); }
1502         | expr_no_comma_rangle ASSIGN expr_no_comma_rangle
1503                 { $$ = build_x_modify_expr ($$, $2, $3); }
1504         | THROW
1505                 { $$ = build_throw (NULL_TREE); }
1506         | THROW expr_no_comma_rangle
1507                 { $$ = build_throw ($2); }
1508         ;
1509
1510 notype_unqualified_id:
1511           '~' see_typename identifier
1512                 { $$ = build_nt (BIT_NOT_EXPR, $3); }
1513         | '~' see_typename template_type
1514                 { $$ = build_nt (BIT_NOT_EXPR, $3); }
1515         | template_id
1516         | operator_name
1517         | IDENTIFIER
1518         | PTYPENAME
1519         | NSNAME  %prec EMPTY
1520         ;
1521
1522 do_id:
1523                 {
1524                   /* If lastiddecl is a TREE_LIST, it's a baselink, which
1525                      means that we're in an expression like S::f<int>, so
1526                      don't do_identifier; we only do that for unqualified
1527                      identifiers.  */
1528                   if (!lastiddecl || TREE_CODE (lastiddecl) != TREE_LIST)
1529                     $$ = do_identifier ($<ttype>-1, 1, NULL_TREE);
1530                   else
1531                     $$ = $<ttype>-1;
1532                 }
1533         ;
1534
1535 template_id:
1536           PFUNCNAME '<' do_id template_arg_list_opt template_close_bracket
1537                 { $$ = lookup_template_function ($3, $4); }
1538         | operator_name '<' do_id template_arg_list_opt template_close_bracket
1539                 { $$ = lookup_template_function ($3, $4); }
1540         ;
1541
1542 object_template_id:
1543         TEMPLATE identifier '<' template_arg_list_opt template_close_bracket
1544                 { $$ = lookup_template_function ($2, $4); }
1545         | TEMPLATE PFUNCNAME '<' template_arg_list_opt template_close_bracket
1546                 { $$ = lookup_template_function ($2, $4); }
1547         | TEMPLATE operator_name '<' template_arg_list_opt
1548           template_close_bracket
1549                 { $$ = lookup_template_function ($2, $4); }
1550         ;
1551
1552 unqualified_id:
1553           notype_unqualified_id
1554         | tTYPENAME
1555         | SELFNAME
1556         ;
1557
1558 expr_or_declarator_intern:
1559           expr_or_declarator
1560         | attributes expr_or_declarator
1561                 {
1562                   /* Provide support for '(' attributes '*' declarator ')'
1563                      etc */
1564                   $$ = tree_cons ($1, $2, NULL_TREE);
1565                 }
1566         ;
1567
1568 expr_or_declarator:
1569           notype_unqualified_id
1570         | '*' expr_or_declarator_intern  %prec UNARY
1571                 { $$ = build_nt (INDIRECT_REF, $2); }
1572         | '&' expr_or_declarator_intern  %prec UNARY
1573                 { $$ = build_nt (ADDR_EXPR, $2); }
1574         | '(' expr_or_declarator_intern ')'
1575                 { $$ = $2; }
1576         ;
1577
1578 notype_template_declarator:
1579           IDENTIFIER '<' template_arg_list_opt template_close_bracket
1580                 { $$ = lookup_template_function ($1, $3); }
1581         | NSNAME '<' template_arg_list template_close_bracket
1582                 { $$ = lookup_template_function ($1, $3); }
1583         ;
1584
1585 direct_notype_declarator:
1586           complex_direct_notype_declarator
1587         /* This precedence declaration is to prefer this reduce
1588            to the Koenig lookup shift in primary, below.  I hate yacc.  */
1589         | notype_unqualified_id %prec '('
1590         | notype_template_declarator
1591         | '(' expr_or_declarator_intern ')'
1592                 { $$ = finish_decl_parsing ($2); }
1593         ;
1594
1595 primary:
1596           notype_unqualified_id
1597                 {
1598                   if (TREE_CODE ($1) == BIT_NOT_EXPR)
1599                     $$ = build_x_unary_op (BIT_NOT_EXPR, TREE_OPERAND ($1, 0));
1600                   else
1601                     $$ = finish_id_expr ($1);
1602                 }
1603         | CONSTANT
1604         | boolean_literal
1605         | STRING
1606                 {
1607                   $$ = fix_string_type ($$);
1608                   /* fix_string_type doesn't set up TYPE_MAIN_VARIANT of
1609                      a const array the way we want, so fix it.  */
1610                   if (flag_const_strings)
1611                     TREE_TYPE ($$) = build_cplus_array_type
1612                       (TREE_TYPE (TREE_TYPE ($$)),
1613                        TYPE_DOMAIN (TREE_TYPE ($$)));
1614                 }
1615         | VAR_FUNC_NAME
1616                { $$ = finish_fname ($1); }
1617         | '(' expr ')'
1618                 { $$ = finish_parenthesized_expr ($2); }
1619         | '(' expr_or_declarator_intern ')'
1620                 { $2 = reparse_decl_as_expr (NULL_TREE, $2);
1621                   $$ = finish_parenthesized_expr ($2); }
1622         | '(' error ')'
1623                 { $$ = error_mark_node; }
1624         | '('
1625                 { if (!at_function_scope_p ())
1626                     {
1627                       error ("braced-group within expression allowed only inside a function");
1628                       YYERROR;
1629                     }
1630                   if (pedantic)
1631                     pedwarn ("ISO C++ forbids braced-groups within expressions");
1632                   $<ttype>$ = begin_stmt_expr ();
1633                 }
1634           compstmt_or_stmtexpr ')'
1635                { $$ = finish_stmt_expr ($<ttype>2); }
1636         /* Koenig lookup support
1637            We could store lastiddecl in $1 to avoid another lookup,
1638            but that would result in many additional reduce/reduce conflicts. */
1639         | notype_unqualified_id '(' nonnull_exprlist ')'
1640                { $$ = finish_call_expr ($1, $3, 1); }
1641         | notype_unqualified_id LEFT_RIGHT
1642                { $$ = finish_call_expr ($1, NULL_TREE, 1); }
1643         | primary '(' nonnull_exprlist ')'
1644                { $$ = finish_call_expr ($1, $3, 0); }
1645         | primary LEFT_RIGHT
1646                { $$ = finish_call_expr ($1, NULL_TREE, 0); }
1647         | VA_ARG '(' expr_no_commas ',' type_id ')'
1648                 { $$ = build_x_va_arg ($3, groktypename ($5.t));
1649                   check_for_new_type ("__builtin_va_arg", $5); }
1650         | primary '[' expr ']'
1651                 { $$ = grok_array_decl ($$, $3); }
1652         | primary PLUSPLUS
1653                 { $$ = finish_increment_expr ($1, POSTINCREMENT_EXPR); }
1654         | primary MINUSMINUS
1655                 { $$ = finish_increment_expr ($1, POSTDECREMENT_EXPR); }
1656         /* C++ extensions */
1657         | THIS
1658                 { $$ = finish_this_expr (); }
1659         | CV_QUALIFIER '(' nonnull_exprlist ')'
1660                 {
1661                   /* This is a C cast in C++'s `functional' notation
1662                      using the "implicit int" extension so that:
1663                      `const (3)' is equivalent to `const int (3)'.  */
1664                   tree type;
1665
1666                   type = hash_tree_cons (NULL_TREE, $1, NULL_TREE);
1667                   type = groktypename (build_tree_list (type, NULL_TREE));
1668                   $$ = build_functional_cast (type, $3);
1669                 }
1670         | functional_cast
1671         | DYNAMIC_CAST '<' type_id '>' '(' expr ')'
1672                 { tree type = groktypename ($3.t);
1673                   check_for_new_type ("dynamic_cast", $3);
1674                   $$ = build_dynamic_cast (type, $6); }
1675         | STATIC_CAST '<' type_id '>' '(' expr ')'
1676                 { tree type = groktypename ($3.t);
1677                   check_for_new_type ("static_cast", $3);
1678                   $$ = build_static_cast (type, $6); }
1679         | REINTERPRET_CAST '<' type_id '>' '(' expr ')'
1680                 { tree type = groktypename ($3.t);
1681                   check_for_new_type ("reinterpret_cast", $3);
1682                   $$ = build_reinterpret_cast (type, $6); }
1683         | CONST_CAST '<' type_id '>' '(' expr ')'
1684                 { tree type = groktypename ($3.t);
1685                   check_for_new_type ("const_cast", $3);
1686                   $$ = build_const_cast (type, $6); }
1687         | TYPEID '(' expr ')'
1688                 { $$ = build_typeid ($3); }
1689         | TYPEID '(' type_id ')'
1690                 { tree type = groktypename ($3.t);
1691                   check_for_new_type ("typeid", $3);
1692                   $$ = get_typeid (type); }
1693         | global_scope IDENTIFIER
1694                 { $$ = parse_scoped_id ($2); }
1695         | global_scope template_id
1696                 { $$ = $2; }
1697         | global_scope operator_name
1698                 {
1699                   got_scope = NULL_TREE;
1700                   if (TREE_CODE ($2) == IDENTIFIER_NODE)
1701                     $$ = parse_scoped_id ($2);
1702                   else
1703                     $$ = $2;
1704                 }
1705         | overqualified_id  %prec HYPERUNARY
1706                 { $$ = build_offset_ref (OP0 ($$), OP1 ($$)); }
1707         | overqualified_id '(' nonnull_exprlist ')'
1708                 { $$ = finish_qualified_call_expr ($1, $3); }
1709         | overqualified_id LEFT_RIGHT
1710                 { $$ = finish_qualified_call_expr ($1, NULL_TREE); }
1711         | object object_template_id %prec UNARY
1712                 {
1713                   $$ = build_x_component_ref ($$, $2, NULL_TREE);
1714                 }
1715         | object object_template_id '(' nonnull_exprlist ')'
1716                 { $$ = finish_object_call_expr ($2, $1, $4); }
1717         | object object_template_id LEFT_RIGHT
1718                 { $$ = finish_object_call_expr ($2, $1, NULL_TREE); }
1719         | object unqualified_id  %prec UNARY
1720                 { $$ = build_x_component_ref ($$, $2, NULL_TREE); }
1721         | object overqualified_id  %prec UNARY
1722                 { if (processing_template_decl)
1723                     $$ = build_min_nt (COMPONENT_REF, $1, $2);
1724                   else
1725                     $$ = build_object_ref ($$, OP0 ($2), OP1 ($2)); }
1726         | object unqualified_id '(' nonnull_exprlist ')'
1727                 { $$ = finish_object_call_expr ($2, $1, $4); }
1728         | object unqualified_id LEFT_RIGHT
1729                 { $$ = finish_object_call_expr ($2, $1, NULL_TREE); }
1730         | object overqualified_id '(' nonnull_exprlist ')'
1731                 { $$ = finish_qualified_object_call_expr ($2, $1, $4); }
1732         | object overqualified_id LEFT_RIGHT
1733                 { $$ = finish_qualified_object_call_expr ($2, $1, NULL_TREE); }
1734         /* p->int::~int() is valid -- 12.4 */
1735         | object '~' TYPESPEC LEFT_RIGHT
1736                 { $$ = finish_pseudo_destructor_call_expr ($1, NULL_TREE, $3); }
1737         | object TYPESPEC SCOPE '~' TYPESPEC LEFT_RIGHT
1738                 { $$ = finish_pseudo_destructor_call_expr ($1, $2, $5); }
1739         | object error
1740                 {
1741                   $$ = error_mark_node;
1742                 }
1743         ;
1744
1745 /* Not needed for now.
1746
1747 primary_no_id:
1748           '(' expr ')'
1749                 { $$ = $2; }
1750         | '(' error ')'
1751                 { $$ = error_mark_node; }
1752         | '('
1753                 { if (current_function_decl == 0)
1754                     {
1755                       error ("braced-group within expression allowed only inside a function");
1756                       YYERROR;
1757                     }
1758                   $<ttype>$ = expand_start_stmt_expr (); }
1759           compstmt_or_stmtexpr ')'
1760                 { if (pedantic)
1761                     pedwarn ("ISO C++ forbids braced-groups within expressions");
1762                   $$ = expand_end_stmt_expr ($<ttype>2); }
1763         | primary_no_id '(' nonnull_exprlist ')'
1764                 { $$ = build_x_function_call ($$, $3, current_class_ref); }
1765         | primary_no_id LEFT_RIGHT
1766                 { $$ = build_x_function_call ($$, NULL_TREE, current_class_ref); }
1767         | primary_no_id '[' expr ']'
1768                 { goto do_array; }
1769         | primary_no_id PLUSPLUS
1770                 { $$ = build_x_unary_op (POSTINCREMENT_EXPR, $$); }
1771         | primary_no_id MINUSMINUS
1772                 { $$ = build_x_unary_op (POSTDECREMENT_EXPR, $$); }
1773         | SCOPE IDENTIFIER
1774                 { goto do_scoped_id; }
1775         | SCOPE operator_name
1776                 { if (TREE_CODE ($2) == IDENTIFIER_NODE)
1777                     goto do_scoped_id;
1778                   goto do_scoped_operator;
1779                 }
1780         ;
1781 */
1782
1783 new:
1784           NEW
1785                 { $$ = 0; }
1786         | global_scope NEW
1787                 { got_scope = NULL_TREE; $$ = 1; }
1788         ;
1789
1790 delete:
1791           DELETE
1792                 { $$ = 0; }
1793         | global_scope delete
1794                 { got_scope = NULL_TREE; $$ = 1; }
1795         ;
1796
1797 boolean_literal:
1798           CXX_TRUE
1799                 { $$ = boolean_true_node; }
1800         | CXX_FALSE
1801                 { $$ = boolean_false_node; }
1802         ;
1803
1804 nodecls:
1805           /* empty */
1806                 {
1807                   if (DECL_CONSTRUCTOR_P (current_function_decl))
1808                     finish_mem_initializers (NULL_TREE);
1809                 }
1810         ;
1811
1812 object:
1813           primary '.'
1814                 { got_object = TREE_TYPE ($$); }
1815         | primary POINTSAT
1816                 {
1817                   $$ = build_x_arrow ($$);
1818                   got_object = TREE_TYPE ($$);
1819                 }
1820         ;
1821
1822 decl:
1823           typespec initdecls ';'
1824                 {
1825                   if ($1.t && IS_AGGR_TYPE_CODE (TREE_CODE ($1.t)))
1826                     note_got_semicolon ($1.t);
1827                 }
1828         | typed_declspecs initdecls ';'
1829                 {
1830                   note_list_got_semicolon ($1.t);
1831                 }
1832         | declmods notype_initdecls ';'
1833                 {}
1834         | typed_declspecs ';'
1835                 {
1836                   shadow_tag ($1.t);
1837                   note_list_got_semicolon ($1.t);
1838                 }
1839         | declmods ';'
1840                 { warning ("empty declaration"); }
1841         | extension decl
1842                 { pedantic = $1; }
1843         ;
1844
1845 /* Any kind of declarator (thus, all declarators allowed
1846    after an explicit typespec).  */
1847
1848 declarator:
1849           after_type_declarator  %prec EMPTY
1850         | notype_declarator  %prec EMPTY
1851         ;
1852
1853 /* This is necessary to postpone reduction of `int()()()()'.  */
1854 fcast_or_absdcl:
1855           LEFT_RIGHT  %prec EMPTY
1856                 { $$ = make_call_declarator (NULL_TREE, empty_parms (),
1857                                              NULL_TREE, NULL_TREE); }
1858         | fcast_or_absdcl LEFT_RIGHT  %prec EMPTY
1859                 { $$ = make_call_declarator ($$, empty_parms (), NULL_TREE,
1860                                              NULL_TREE); }
1861         ;
1862
1863 /* ISO type-id (8.1) */
1864 type_id:
1865           typed_typespecs absdcl
1866                 { $$.t = build_tree_list ($1.t, $2);
1867                   $$.new_type_flag = $1.new_type_flag; }
1868         | nonempty_cv_qualifiers absdcl
1869                 { $$.t = build_tree_list ($1.t, $2);
1870                   $$.new_type_flag = $1.new_type_flag; }
1871         | typespec absdcl
1872                 { $$.t = build_tree_list (build_tree_list (NULL_TREE, $1.t),
1873                                           $2);
1874                   $$.new_type_flag = $1.new_type_flag; }
1875         | typed_typespecs  %prec EMPTY
1876                 { $$.t = build_tree_list ($1.t, NULL_TREE);
1877                   $$.new_type_flag = $1.new_type_flag;  }
1878         | nonempty_cv_qualifiers  %prec EMPTY
1879                 { $$.t = build_tree_list ($1.t, NULL_TREE);
1880                   $$.new_type_flag = $1.new_type_flag; }
1881         ;
1882
1883 /* Declspecs which contain at least one type specifier or typedef name.
1884    (Just `const' or `volatile' is not enough.)
1885    A typedef'd name following these is taken as a name to be declared.
1886    In the result, declspecs have a non-NULL TREE_VALUE, attributes do not.  */
1887
1888 typed_declspecs:
1889           typed_typespecs  %prec EMPTY
1890                 { $$.lookups = type_lookups; }
1891         | typed_declspecs1
1892                 { $$.lookups = type_lookups; }
1893         ;
1894
1895 typed_declspecs1:
1896           declmods typespec
1897                 { $$.t = tree_cons (NULL_TREE, $2.t, $1.t);
1898                   $$.new_type_flag = $2.new_type_flag; }
1899         | typespec reserved_declspecs  %prec HYPERUNARY
1900                 { $$.t = tree_cons (NULL_TREE, $1.t, $2);
1901                   $$.new_type_flag = $1.new_type_flag; }
1902         | typespec reserved_typespecquals reserved_declspecs
1903                 { $$.t = tree_cons (NULL_TREE, $1.t, chainon ($2, $3));
1904                   $$.new_type_flag = $1.new_type_flag; }
1905         | declmods typespec reserved_declspecs
1906                 { $$.t = tree_cons (NULL_TREE, $2.t, chainon ($3, $1.t));
1907                   $$.new_type_flag = $2.new_type_flag; }
1908         | declmods typespec reserved_typespecquals
1909                 { $$.t = tree_cons (NULL_TREE, $2.t, chainon ($3, $1.t));
1910                   $$.new_type_flag = $2.new_type_flag; }
1911         | declmods typespec reserved_typespecquals reserved_declspecs
1912                 { $$.t = tree_cons (NULL_TREE, $2.t,
1913                                     chainon ($3, chainon ($4, $1.t)));
1914                   $$.new_type_flag = $2.new_type_flag; }
1915         ;
1916
1917 reserved_declspecs:
1918           SCSPEC
1919                 { if (extra_warnings)
1920                     warning ("`%s' is not at beginning of declaration",
1921                              IDENTIFIER_POINTER ($$));
1922                   $$ = build_tree_list (NULL_TREE, $$); }
1923         | reserved_declspecs typespecqual_reserved
1924                 { $$ = tree_cons (NULL_TREE, $2.t, $$); }
1925         | reserved_declspecs SCSPEC
1926                 { if (extra_warnings)
1927                     warning ("`%s' is not at beginning of declaration",
1928                              IDENTIFIER_POINTER ($2));
1929                   $$ = tree_cons (NULL_TREE, $2, $$); }
1930         ;
1931
1932 /* List of just storage classes and type modifiers.
1933    A declaration can start with just this, but then it cannot be used
1934    to redeclare a typedef-name.
1935    In the result, declspecs have a non-NULL TREE_VALUE, attributes do not.  */
1936
1937 /* We use hash_tree_cons for lists of typeless declspecs so that they end
1938    up on a persistent obstack.  Otherwise, they could appear at the
1939    beginning of something like
1940
1941       static const struct { int foo () { } } b;
1942
1943    and would be discarded after we finish compiling foo.  We don't need to
1944    worry once we see a type.  */
1945
1946 declmods:
1947           nonempty_cv_qualifiers  %prec EMPTY
1948                 { $$.lookups = NULL_TREE; TREE_STATIC ($$.t) = 1; }
1949         | SCSPEC
1950                 {
1951                   $$.t = hash_tree_cons (NULL_TREE, $1, NULL_TREE);
1952                   $$.new_type_flag = 0; $$.lookups = NULL_TREE;
1953                 }
1954         | declmods CV_QUALIFIER
1955                 {
1956                   $$.t = hash_tree_cons (NULL_TREE, $2, $1.t);
1957                   TREE_STATIC ($$.t) = 1;
1958                 }
1959         | declmods SCSPEC
1960                 {
1961                   if (extra_warnings && TREE_STATIC ($$.t))
1962                     warning ("`%s' is not at beginning of declaration",
1963                              IDENTIFIER_POINTER ($2));
1964                   $$.t = hash_tree_cons (NULL_TREE, $2, $1.t);
1965                   TREE_STATIC ($$.t) = TREE_STATIC ($1.t);
1966                 }
1967         | declmods attributes
1968                 { $$.t = hash_tree_cons ($2, NULL_TREE, $1.t); }
1969         ;
1970
1971 /* Used instead of declspecs where storage classes are not allowed
1972    (that is, for typenames and structure components).
1973
1974    C++ can takes storage classes for structure components.
1975    Don't accept a typedef-name if anything but a modifier precedes it.  */
1976
1977 typed_typespecs:
1978           typespec  %prec EMPTY
1979                 { $$.t = build_tree_list (NULL_TREE, $1.t);
1980                   $$.new_type_flag = $1.new_type_flag; }
1981         | nonempty_cv_qualifiers typespec
1982                 { $$.t = tree_cons (NULL_TREE, $2.t, $1.t);
1983                   $$.new_type_flag = $2.new_type_flag; }
1984         | typespec reserved_typespecquals
1985                 { $$.t = tree_cons (NULL_TREE, $1.t, $2);
1986                   $$.new_type_flag = $1.new_type_flag; }
1987         | nonempty_cv_qualifiers typespec reserved_typespecquals
1988                 { $$.t = tree_cons (NULL_TREE, $2.t, chainon ($3, $1.t));
1989                   $$.new_type_flag = $2.new_type_flag; }
1990         ;
1991
1992 reserved_typespecquals:
1993           typespecqual_reserved
1994                 { $$ = build_tree_list (NULL_TREE, $1.t); }
1995         | reserved_typespecquals typespecqual_reserved
1996                 { $$ = tree_cons (NULL_TREE, $2.t, $1); }
1997         | reserved_typespecquals attributes
1998                 { $$ = tree_cons ($2, NULL_TREE, $1); }
1999         | attributes %prec EMPTY
2000                 { $$ = tree_cons ($1, NULL_TREE, NULL_TREE); }
2001         ;
2002
2003 /* A typespec (but not a type qualifier).
2004    Once we have seen one of these in a declaration,
2005    if a typedef name appears then it is being redeclared.  */
2006
2007 typespec:
2008           structsp
2009                 { $$.lookups = NULL_TREE; }
2010         | TYPESPEC  %prec EMPTY
2011                 { $$.t = $1; $$.new_type_flag = 0; $$.lookups = NULL_TREE; }
2012         | complete_type_name
2013                 { $$.t = $1; $$.new_type_flag = 0; $$.lookups = NULL_TREE; }
2014         | TYPEOF '(' expr ')'
2015                 { $$.t = finish_typeof ($3);
2016                   $$.new_type_flag = 0; $$.lookups = NULL_TREE; }
2017         | TYPEOF '(' type_id ')'
2018                 { $$.t = groktypename ($3.t);
2019                   $$.new_type_flag = 0; $$.lookups = NULL_TREE; }
2020         | SIGOF '(' expr ')'
2021                 { tree type = TREE_TYPE ($3);
2022
2023                   $$.new_type_flag = 0; $$.lookups = NULL_TREE;
2024                   if (IS_AGGR_TYPE (type))
2025                     {
2026                       sorry ("sigof type specifier");
2027                       $$.t = type;
2028                     }
2029                   else
2030                     {
2031                       error ("`sigof' applied to non-aggregate expression");
2032                       $$.t = error_mark_node;
2033                     }
2034                 }
2035         | SIGOF '(' type_id ')'
2036                 { tree type = groktypename ($3.t);
2037
2038                   $$.new_type_flag = 0; $$.lookups = NULL_TREE;
2039                   if (IS_AGGR_TYPE (type))
2040                     {
2041                       sorry ("sigof type specifier");
2042                       $$.t = type;
2043                     }
2044                   else
2045                     {
2046                       error("`sigof' applied to non-aggregate type");
2047                       $$.t = error_mark_node;
2048                     }
2049                 }
2050         ;
2051
2052 /* A typespec that is a reserved word, or a type qualifier.  */
2053
2054 typespecqual_reserved:
2055           TYPESPEC
2056                 { $$.t = $1; $$.new_type_flag = 0; }
2057         | CV_QUALIFIER
2058                 { $$.t = $1; $$.new_type_flag = 0; }
2059         | structsp
2060         ;
2061
2062 initdecls:
2063           initdcl0
2064         | initdecls ',' initdcl
2065             { check_multiple_declarators (); }
2066         ;
2067
2068 notype_initdecls:
2069           notype_initdcl0
2070         | notype_initdecls ',' initdcl
2071             { check_multiple_declarators (); }
2072         ;
2073
2074 nomods_initdecls:
2075           nomods_initdcl0
2076         | nomods_initdecls ',' initdcl
2077             { check_multiple_declarators (); }
2078         ;
2079
2080 maybeasm:
2081           /* empty */
2082                 { $$ = NULL_TREE; }
2083         | asm_keyword '(' STRING ')'
2084                 { $$ = $3; }
2085         ;
2086
2087 initdcl:
2088           declarator maybeasm maybe_attribute '='
2089                 { $<ttype>$ = parse_decl ($<ttype>1, $3, 1); }
2090           init
2091 /* Note how the declaration of the variable is in effect while its init is parsed! */
2092                 { parse_end_decl ($<ttype>5, $6, $2); }
2093         | declarator maybeasm maybe_attribute
2094                 {
2095                   $<ttype>$ = parse_decl ($<ttype>1, $3, 0);
2096                   parse_end_decl ($<ttype>$, NULL_TREE, $2);
2097                 }
2098         ;
2099
2100         /* This rule assumes a certain configuration of the parser stack.
2101            In particular, $0, the element directly before the beginning of
2102            this rule on the stack, must be a maybeasm.  $-1 must be a
2103            declarator or notype_declarator.  And $-2 must be some declmods
2104            or declspecs.  We can't move the maybeasm into this rule because
2105            we need that reduce so we prefer fn.def1 when appropriate.  */
2106 initdcl0_innards:
2107           maybe_attribute '='
2108                 { $<ttype>$ = parse_decl0 ($<ttype>-1, $<ftype>-2.t,
2109                                            $<ftype>-2.lookups, $1, 1); }
2110           /* Note how the declaration of the variable is in effect
2111              while its init is parsed! */
2112           init
2113                 { parse_end_decl ($<ttype>3, $4, $<ttype>0); }
2114         | maybe_attribute
2115                 { tree d = parse_decl0 ($<ttype>-1, $<ftype>-2.t,
2116                                         $<ftype>-2.lookups, $1, 0);
2117                   parse_end_decl (d, NULL_TREE, $<ttype>0); }
2118         ;
2119
2120 initdcl0:
2121           declarator maybeasm initdcl0_innards
2122                 {}
2123         ;
2124
2125 notype_initdcl0:
2126           notype_declarator maybeasm initdcl0_innards
2127                 {}
2128         ;
2129
2130 nomods_initdcl0:
2131           notype_declarator maybeasm
2132             { /* Set things up as initdcl0_innards expects.  */
2133               $<ttype>$ = $2;
2134               $2 = $1;
2135               $<ftype>1.t = NULL_TREE;
2136               $<ftype>1.lookups = NULL_TREE; }
2137           initdcl0_innards
2138             {}
2139         | constructor_declarator maybeasm maybe_attribute
2140                 { tree d = parse_decl0 ($1, NULL_TREE, NULL_TREE, $3, 0);
2141                   parse_end_decl (d, NULL_TREE, $2); }
2142         ;
2143
2144 /* the * rules are dummies to accept the Apollo extended syntax
2145    so that the header files compile.  */
2146 maybe_attribute:
2147           /* empty */
2148                 { $$ = NULL_TREE; }
2149         | attributes
2150                 { $$ = $1; }
2151         ;
2152
2153 attributes:
2154       attribute
2155                 { $$ = $1; }
2156         | attributes attribute
2157                 { $$ = chainon ($1, $2); }
2158         ;
2159
2160 attribute:
2161       ATTRIBUTE '(' '(' attribute_list ')' ')'
2162                 { $$ = $4; }
2163         ;
2164
2165 attribute_list:
2166       attrib
2167                 { $$ = $1; }
2168         | attribute_list ',' attrib
2169                 { $$ = chainon ($1, $3); }
2170         ;
2171
2172 attrib:
2173           /* empty */
2174                 { $$ = NULL_TREE; }
2175         | any_word
2176                 { $$ = build_tree_list ($1, NULL_TREE); }
2177         | any_word '(' IDENTIFIER ')'
2178                 { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
2179         | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
2180                 { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
2181         | any_word '(' nonnull_exprlist ')'
2182                 { $$ = build_tree_list ($1, $3); }
2183         ;
2184
2185 /* This still leaves out most reserved keywords,
2186    shouldn't we include them?  */
2187
2188 any_word:
2189           identifier
2190         | SCSPEC
2191         | TYPESPEC
2192         | CV_QUALIFIER
2193         ;
2194
2195 /* A nonempty list of identifiers, including typenames.  */
2196 identifiers_or_typenames:
2197           identifier
2198                 { $$ = build_tree_list (NULL_TREE, $1); }
2199         | identifiers_or_typenames ',' identifier
2200                 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2201         ;
2202
2203 maybe_init:
2204           /* empty */  %prec EMPTY
2205                 { $$ = NULL_TREE; }
2206         | '=' init
2207                 { $$ = $2; }
2208         ;
2209
2210 /* If we are processing a template, we don't want to expand this
2211    initializer yet.  */
2212
2213 init:
2214           expr_no_commas  %prec '='
2215         | '{' '}'
2216                 { $$ = build_nt (CONSTRUCTOR, NULL_TREE, NULL_TREE);
2217                   TREE_HAS_CONSTRUCTOR ($$) = 1; }
2218         | '{' initlist '}'
2219                 { $$ = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($2));
2220                   TREE_HAS_CONSTRUCTOR ($$) = 1; }
2221         | '{' initlist ',' '}'
2222                 { $$ = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($2));
2223                   TREE_HAS_CONSTRUCTOR ($$) = 1; }
2224         | error
2225                 { $$ = NULL_TREE; }
2226         ;
2227
2228 /* This chain is built in reverse order,
2229    and put in forward order where initlist is used.  */
2230 initlist:
2231           init
2232                 { $$ = build_tree_list (NULL_TREE, $$); }
2233         | initlist ',' init
2234                 { $$ = tree_cons (NULL_TREE, $3, $$); }
2235         /* These are for labeled elements.  */
2236         | '[' expr_no_commas ']' init
2237                 { $$ = build_tree_list ($2, $4); }
2238         | identifier ':' init
2239                 { $$ = build_tree_list ($$, $3); }
2240         | initlist ',' identifier ':' init
2241                 { $$ = tree_cons ($3, $5, $$); }
2242         ;
2243
2244 pending_inline:
2245           PRE_PARSED_FUNCTION_DECL maybe_return_init function_body
2246                 {
2247                   expand_body (finish_function (2));
2248                   process_next_inline ($1);
2249                 }
2250         | PRE_PARSED_FUNCTION_DECL maybe_return_init function_try_block
2251                 {
2252                   expand_body (finish_function (2));
2253                   process_next_inline ($1);
2254                 }
2255         | PRE_PARSED_FUNCTION_DECL maybe_return_init error
2256                 {
2257                   finish_function (2);
2258                   process_next_inline ($1); }
2259         ;
2260
2261 pending_inlines:
2262         /* empty */
2263         | pending_inlines pending_inline eat_saved_input
2264         ;
2265
2266 /* A regurgitated default argument.  The value of DEFARG_MARKER will be
2267    the TREE_LIST node for the parameter in question.  */
2268 defarg_again:
2269         DEFARG_MARKER expr_no_commas END_OF_SAVED_INPUT
2270                 { replace_defarg ($1, $2); }
2271         | DEFARG_MARKER error END_OF_SAVED_INPUT
2272                 { replace_defarg ($1, error_mark_node); }
2273         ;
2274
2275 pending_defargs:
2276           /* empty */ %prec EMPTY
2277         | pending_defargs defarg_again
2278                 { do_pending_defargs (); }
2279         | pending_defargs error
2280                 { do_pending_defargs (); }
2281         ;
2282
2283 structsp:
2284           ENUM identifier '{'
2285                 { $<ttype>$ = current_enum_type;
2286                   current_enum_type = start_enum ($2); }
2287           enumlist_opt '}'
2288                 { $$.t = current_enum_type;
2289                   finish_enum (current_enum_type);
2290                   $$.new_type_flag = 1;
2291                   current_enum_type = $<ttype>4;
2292                   check_for_missing_semicolon ($$.t); }
2293         | ENUM '{'
2294                 { $<ttype>$ = current_enum_type;
2295                   current_enum_type = start_enum (make_anon_name ()); }
2296           enumlist_opt '}'
2297                 { $$.t = current_enum_type;
2298                   finish_enum (current_enum_type);
2299                   $$.new_type_flag = 1;
2300                   current_enum_type = $<ttype>3;
2301                   check_for_missing_semicolon ($$.t); }
2302         | ENUM identifier
2303                 { $$.t = parse_xref_tag (enum_type_node, $2, 1);
2304                   $$.new_type_flag = 0; }
2305         | ENUM complex_type_name
2306                 { $$.t = parse_xref_tag (enum_type_node, $2, 1);
2307                   $$.new_type_flag = 0; }
2308         | TYPENAME_KEYWORD typename_sub
2309                 { $$.t = $2;
2310                   $$.new_type_flag = 0;
2311                   if (!processing_template_decl)
2312                     pedwarn ("using `typename' outside of template"); }
2313         /* C++ extensions, merged with C to avoid shift/reduce conflicts */
2314         | class_head_defn maybe_base_class_list '{'
2315                 {
2316                   if ($2 && $1.t != error_mark_node)
2317                     {
2318                       tree type = TREE_TYPE ($1.t);
2319
2320                       if (TREE_CODE (type) == TYPENAME_TYPE)
2321                         /* In a definition of a member class template,
2322                            we will get here with an implicit typename,
2323                            a TYPENAME_TYPE with a type. */
2324                         type = TREE_TYPE (type);
2325                       maybe_process_partial_specialization (type);
2326                       xref_basetypes (type, $2);
2327                     }
2328                   $1.t = begin_class_definition (TREE_TYPE ($1.t));
2329                   check_class_key (current_aggr, $1.t);
2330                   current_aggr = NULL_TREE; }
2331           opt.component_decl_list '}' maybe_attribute
2332                 {
2333                   int semi;
2334                   tree t;
2335
2336                   if (yychar == YYEMPTY)
2337                     yychar = YYLEX;
2338                   semi = yychar == ';';
2339
2340                   t = finish_class_definition ($1.t, $7, semi, $1.new_type_flag);
2341                   $<ttype>$ = t;
2342
2343                   /* restore current_aggr */
2344                   current_aggr = TREE_CODE (t) != RECORD_TYPE
2345                                  ? union_type_node
2346                                  : CLASSTYPE_DECLARED_CLASS (t)
2347                                  ? class_type_node : record_type_node;
2348                 }
2349           pending_defargs
2350                 {
2351                   done_pending_defargs ();
2352                   begin_inline_definitions ();
2353                 }
2354           pending_inlines
2355                 {
2356                   $$.t = $<ttype>8;
2357                   $$.new_type_flag = 1;
2358                 }
2359         | class_head_decl
2360                 {
2361                   $$.t = TREE_TYPE ($1.t);
2362                   $$.new_type_flag = $1.new_type_flag;
2363                   check_class_key (current_aggr, $$.t);
2364                 }
2365         ;
2366
2367 maybecomma:
2368           /* empty */
2369         | ','
2370         ;
2371
2372 maybecomma_warn:
2373           /* empty */
2374         | ','
2375                 { if (pedantic && !in_system_header)
2376                     pedwarn ("comma at end of enumerator list"); }
2377         ;
2378
2379 aggr:
2380           AGGR
2381         | aggr SCSPEC
2382                 { error ("storage class specifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); }
2383         | aggr TYPESPEC
2384                 { error ("type specifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); }
2385         | aggr CV_QUALIFIER
2386                 { error ("type qualifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); }
2387         | aggr AGGR
2388                 { error ("no body nor ';' separates two class, struct or union declarations"); }
2389         | aggr attributes
2390                 { $$ = build_tree_list ($2, $1); }
2391         ;
2392
2393 class_head:
2394           aggr identifier
2395                 {
2396                   current_aggr = $1;
2397                   $$ = build_tree_list (NULL_TREE, $2);
2398                 }
2399         | aggr nested_name_specifier identifier
2400                 {
2401                   current_aggr = $1;
2402                   $$ = build_tree_list ($2, $3);
2403                 }
2404         | aggr global_scope nested_name_specifier identifier
2405                 {
2406                   current_aggr = $1;
2407                   $$ = build_tree_list ($3, $4);
2408                 }
2409         | aggr global_scope identifier
2410                 {
2411                   current_aggr = $1;
2412                   $$ = build_tree_list (global_namespace, $3);
2413                 }
2414         ;
2415
2416 class_head_apparent_template:
2417           aggr apparent_template_type
2418                 {
2419                   current_aggr = $1;
2420                   $$ = $2;
2421                 }
2422         | aggr nested_name_specifier apparent_template_type
2423                 {
2424                   current_aggr = $1;
2425                   $$ = $3;
2426                 }
2427         | aggr global_scope nested_name_specifier apparent_template_type
2428                 {
2429                   current_aggr = $1;
2430                   $$ = $4;
2431                 }
2432         ;
2433
2434 class_head_decl:
2435           class_head %prec EMPTY
2436                 {
2437                   $$.t = parse_handle_class_head (current_aggr,
2438                                                   TREE_PURPOSE ($1), 
2439                                                   TREE_VALUE ($1),
2440                                                   0, &$$.new_type_flag);
2441                 }
2442         | aggr identifier_defn %prec EMPTY
2443                 {
2444                   current_aggr = $1;
2445                   $$.t = TYPE_MAIN_DECL (parse_xref_tag (current_aggr, $2, 0));
2446                   $$.new_type_flag = 1;
2447                 }
2448         | class_head_apparent_template %prec EMPTY
2449                 {
2450                   $$.t = $1;
2451                   $$.new_type_flag = 0;
2452                 }
2453         ;
2454
2455 class_head_defn:
2456           class_head '{'
2457                 {
2458                   yyungetc ('{', 1);
2459                   $$.t = parse_handle_class_head (current_aggr,
2460                                                   TREE_PURPOSE ($1), 
2461                                                   TREE_VALUE ($1),
2462                                                   1, 
2463                                                   &$$.new_type_flag);
2464                 }
2465         | class_head ':'
2466                 {
2467                   yyungetc (':', 1);
2468                   $$.t = parse_handle_class_head (current_aggr,
2469                                                   TREE_PURPOSE ($1), 
2470                                                   TREE_VALUE ($1),
2471                                                   1, &$$.new_type_flag);
2472                 }
2473         | class_head_apparent_template '{'
2474                 {
2475                   yyungetc ('{', 1);
2476                   $$.t = $1;
2477                   $$.new_type_flag = 0;
2478                   if (TREE_CODE (TREE_TYPE ($1)) == RECORD_TYPE)
2479                     /* We might be specializing a template with a different
2480                        class-key.  */
2481                     CLASSTYPE_DECLARED_CLASS (TREE_TYPE ($1))
2482                       = (current_aggr == class_type_node);
2483                 }
2484         | class_head_apparent_template ':'
2485                 {
2486                   yyungetc (':', 1);
2487                   $$.t = $1;
2488                   $$.new_type_flag = 0;
2489                   if (TREE_CODE (TREE_TYPE ($1)) == RECORD_TYPE)
2490                     /* We might be specializing a template with a different
2491                        class-key.  */
2492                     CLASSTYPE_DECLARED_CLASS (TREE_TYPE ($1))
2493                       = (current_aggr == class_type_node);
2494                 }
2495         | aggr identifier_defn '{'
2496                 {
2497                   yyungetc ('{', 1);
2498                   current_aggr = $1;
2499                   $$.t = parse_handle_class_head (current_aggr,
2500                                                   NULL_TREE, $2,
2501                                                   1, &$$.new_type_flag);
2502                 }
2503         | aggr identifier_defn ':'
2504                 {
2505                   yyungetc (':', 1);
2506                   current_aggr = $1;
2507                   $$.t = parse_handle_class_head (current_aggr,
2508                                                   NULL_TREE, $2,
2509                                                   1, &$$.new_type_flag);
2510                 }
2511         | aggr '{'
2512                 {
2513                   current_aggr = $1;
2514                   $$.t = TYPE_MAIN_DECL (parse_xref_tag ($1, 
2515                                                          make_anon_name (), 
2516                                                          0));
2517                   $$.new_type_flag = 0;
2518                   yyungetc ('{', 1);
2519                 }
2520         ;
2521
2522 maybe_base_class_list:
2523           /* empty */
2524                 { $$ = NULL_TREE; }
2525         | ':' see_typename
2526                 { error ("no bases given following `:'");
2527                   $$ = NULL_TREE; }
2528         | ':' see_typename base_class_list
2529                 { $$ = $3; }
2530         ;
2531
2532 base_class_list:
2533           base_class
2534         | base_class_list ',' see_typename base_class
2535                 { $$ = chainon ($$, $4); }
2536         ;
2537
2538 base_class:
2539           base_class_1
2540                 { $$ = finish_base_specifier (access_default_node, $1); }
2541         | base_class_access_list see_typename base_class_1
2542                 { $$ = finish_base_specifier ($1, $3); }
2543         ;
2544
2545 base_class_1:
2546           typename_sub
2547                 { if (!TYPE_P ($$))
2548                     $$ = error_mark_node; }
2549         | nonnested_type
2550                 { $$ = TREE_TYPE ($$); }
2551         ;
2552
2553 base_class_access_list:
2554           VISSPEC see_typename
2555         | SCSPEC see_typename
2556                 { if ($1 != ridpointers[(int)RID_VIRTUAL])
2557                     error ("`%D' access", $1);
2558                   $$ = access_default_virtual_node; }
2559         | base_class_access_list VISSPEC see_typename
2560                 {
2561                   if ($1 != access_default_virtual_node)
2562                     error ("multiple access specifiers");
2563                   else if ($2 == access_public_node)
2564                     $$ = access_public_virtual_node;
2565                   else if ($2 == access_protected_node)
2566                     $$ = access_protected_virtual_node;
2567                   else /* $2 == access_private_node */
2568                     $$ = access_private_virtual_node;
2569                 }
2570         | base_class_access_list SCSPEC see_typename
2571                 { if ($2 != ridpointers[(int)RID_VIRTUAL])
2572                     error ("`%D' access", $2);
2573                   else if ($$ == access_public_node)
2574                     $$ = access_public_virtual_node;
2575                   else if ($$ == access_protected_node)
2576                     $$ = access_protected_virtual_node;
2577                   else if ($$ == access_private_node)
2578                     $$ = access_private_virtual_node;
2579                   else
2580                     error ("multiple `virtual' specifiers");
2581                 }
2582         ;
2583
2584 opt.component_decl_list:
2585         | component_decl_list
2586         | opt.component_decl_list access_specifier component_decl_list
2587         | opt.component_decl_list access_specifier
2588         ;
2589
2590 access_specifier:
2591           VISSPEC ':'
2592                 {
2593                   current_access_specifier = $1;
2594                 }
2595         ;
2596
2597 /* Note: we no longer warn about the semicolon after a component_decl_list.
2598    ARM $9.2 says that the semicolon is optional, and therefore allowed.  */
2599 component_decl_list:
2600           component_decl
2601                 {
2602                   finish_member_declaration ($1);
2603                   current_aggr = NULL_TREE;
2604                   reset_type_access_control ();
2605                 }
2606         | component_decl_list component_decl
2607                 {
2608                   finish_member_declaration ($2);
2609                   current_aggr = NULL_TREE;
2610                   reset_type_access_control ();
2611                 }
2612         ;
2613
2614 component_decl:
2615           component_decl_1 ';'
2616         | component_decl_1 '}'
2617                 { error ("missing ';' before right brace");
2618                   yyungetc ('}', 0); }
2619         /* C++: handle constructors, destructors and inline functions */
2620         /* note that INLINE is like a TYPESPEC */
2621         | fn_def2 ':' /* base_init compstmt */
2622                 { $$ = finish_method ($$); }
2623         | fn_def2 TRY /* base_init compstmt */
2624                 { $$ = finish_method ($$); }
2625         | fn_def2 RETURN_KEYWORD /* base_init compstmt */
2626                 { $$ = finish_method ($$); }
2627         | fn_def2 '{' /* nodecls compstmt */
2628                 { $$ = finish_method ($$); }
2629         | ';'
2630                 { $$ = NULL_TREE; }
2631         | extension component_decl
2632                 { $$ = $2;
2633                   pedantic = $1; }
2634         | template_header component_decl
2635                 {
2636                   if ($2)
2637                     $$ = finish_member_template_decl ($2);
2638                   else
2639                     /* The component was already processed.  */
2640                     $$ = NULL_TREE;
2641
2642                   finish_template_decl ($1);
2643                 }
2644         | template_header typed_declspecs ';'
2645                 {
2646                   $$ = finish_member_class_template ($2.t);
2647                   finish_template_decl ($1);
2648                 }
2649         | bad_decl
2650                 { $$ = NULL_TREE; }
2651         ;
2652
2653 component_decl_1:
2654         /* Do not add a "typed_declspecs declarator" rule here for
2655            speed; we need to call grok_x_components for enums, so the
2656            speedup would be insignificant.  */
2657           typed_declspecs components
2658                 {
2659                   /* Most of the productions for component_decl only
2660                      allow the creation of one new member, so we call
2661                      finish_member_declaration in component_decl_list.
2662                      For this rule and the next, however, there can be
2663                      more than one member, e.g.:
2664
2665                        int i, j;
2666
2667                      and we need the first member to be fully
2668                      registered before the second is processed.
2669                      Therefore, the rules for components take care of
2670                      this processing.  To avoid registering the
2671                      components more than once, we send NULL_TREE up
2672                      here; that lets finish_member_declaration know
2673                      that there is nothing to do.  */
2674                   if (!$2)
2675                     grok_x_components ($1.t);
2676                   $$ = NULL_TREE;
2677                 }
2678         | declmods notype_components
2679                 {
2680                   if (!$2)
2681                     grok_x_components ($1.t);
2682                   $$ = NULL_TREE;
2683                 }
2684         | notype_declarator maybeasm maybe_attribute maybe_init
2685                 { $$ = grokfield ($$, NULL_TREE, $4, $2, $3); }
2686         | constructor_declarator maybeasm maybe_attribute maybe_init
2687                 { $$ = grokfield ($$, NULL_TREE, $4, $2, $3); }
2688         | ':' expr_no_commas
2689                 { $$ = grokbitfield (NULL_TREE, NULL_TREE, $2); }
2690         | error
2691                 { $$ = NULL_TREE; }
2692
2693         /* These rules introduce a reduce/reduce conflict; in
2694                 typedef int foo, bar;
2695                 class A {
2696                   foo (bar);
2697                 };
2698            should "A::foo" be declared as a function or "A::bar" as a data
2699            member? In other words, is "bar" an after_type_declarator or a
2700            parmlist? */
2701         | declmods component_constructor_declarator maybeasm maybe_attribute maybe_init
2702                 { tree specs, attrs;
2703                   split_specs_attrs ($1.t, &specs, &attrs);
2704                   $$ = grokfield ($2, specs, $5, $3,
2705                                   chainon ($4, attrs)); }
2706         | component_constructor_declarator maybeasm maybe_attribute maybe_init
2707                 { $$ = grokfield ($$, NULL_TREE, $4, $2, $3); }
2708         | using_decl
2709                 { $$ = do_class_using_decl ($1); }
2710         ;
2711
2712 /* The case of exactly one component is handled directly by component_decl.  */
2713 /* ??? Huh? ^^^ */
2714 components:
2715           /* empty: possibly anonymous */
2716                 { $$ = 0; }
2717         | component_declarator0
2718                 {
2719                   if (PROCESSING_REAL_TEMPLATE_DECL_P ())
2720                     $1 = finish_member_template_decl ($1);
2721                   finish_member_declaration ($1);
2722                   $$ = 1;
2723                 }
2724         | components ',' component_declarator
2725                 {
2726                   check_multiple_declarators ();
2727                   if (PROCESSING_REAL_TEMPLATE_DECL_P ())
2728                     $3 = finish_member_template_decl ($3);
2729                   finish_member_declaration ($3);
2730                   $$ = 2;
2731                 }
2732         ;
2733
2734 notype_components:
2735           /* empty: possibly anonymous */
2736                 { $$ = 0; }
2737         | notype_component_declarator0
2738                 {
2739                   if (PROCESSING_REAL_TEMPLATE_DECL_P ())
2740                     $1 = finish_member_template_decl ($1);
2741                   finish_member_declaration ($1);
2742                   $$ = 1;
2743                 }
2744         | notype_components ',' notype_component_declarator
2745                 {
2746                   check_multiple_declarators ();
2747                   if (PROCESSING_REAL_TEMPLATE_DECL_P ())
2748                     $3 = finish_member_template_decl ($3);
2749                   finish_member_declaration ($3);
2750                   $$ = 2;
2751                 }
2752         ;
2753
2754 component_declarator0:
2755           after_type_component_declarator0
2756         | notype_component_declarator0
2757         ;
2758
2759 component_declarator:
2760           after_type_component_declarator
2761         | notype_component_declarator
2762         ;
2763
2764 after_type_component_declarator0:
2765           after_type_declarator maybeasm maybe_attribute maybe_init
2766                 { $$ = parse_field0 ($1, $<ftype>0.t, $<ftype>0.lookups,
2767                                      $3, $2, $4); }
2768         | tTYPENAME ':' expr_no_commas maybe_attribute
2769                 { $$ = parse_bitfield0 ($1, $<ftype>0.t, $<ftype>0.lookups,
2770                                         $4, $3); }
2771         ;
2772
2773 notype_component_declarator0:
2774           notype_declarator maybeasm maybe_attribute maybe_init
2775                 { $$ = parse_field0 ($1, $<ftype>0.t, $<ftype>0.lookups,
2776                                      $3, $2, $4); }
2777         | constructor_declarator maybeasm maybe_attribute maybe_init
2778                 { $$ = parse_field0 ($1, $<ftype>0.t, $<ftype>0.lookups,
2779                                      $3, $2, $4); }
2780         | IDENTIFIER ':' expr_no_commas maybe_attribute
2781                 { $$ = parse_bitfield0 ($1, $<ftype>0.t, $<ftype>0.lookups,
2782                                         $4, $3); }
2783         | ':' expr_no_commas maybe_attribute
2784                 { $$ = parse_bitfield0 (NULL_TREE, $<ftype>0.t,
2785                                         $<ftype>0.lookups, $3, $2); }
2786         ;
2787
2788 after_type_component_declarator:
2789           after_type_declarator maybeasm maybe_attribute maybe_init
2790                 { $$ = parse_field ($1, $3, $2, $4); }
2791         | tTYPENAME ':' expr_no_commas maybe_attribute
2792                 { $$ = parse_bitfield ($1, $4, $3); }
2793         ;
2794
2795 notype_component_declarator:
2796           notype_declarator maybeasm maybe_attribute maybe_init
2797                 { $$ = parse_field ($1, $3, $2, $4); }
2798         | IDENTIFIER ':' expr_no_commas maybe_attribute
2799                 { $$ = parse_bitfield ($1, $4, $3); }
2800         | ':' expr_no_commas maybe_attribute
2801                 { $$ = parse_bitfield (NULL_TREE, $3, $2); }
2802         ;
2803
2804 enumlist_opt:
2805           enumlist maybecomma_warn
2806         | maybecomma_warn
2807         ;
2808
2809 /* We chain the enumerators in reverse order.
2810    Because of the way enums are built, the order is
2811    insignificant.  Take advantage of this fact.  */
2812
2813 enumlist:
2814           enumerator
2815         | enumlist ',' enumerator
2816         ;
2817
2818 enumerator:
2819           identifier
2820                 { build_enumerator ($1, NULL_TREE, current_enum_type); }
2821         | identifier '=' expr_no_commas
2822                 { build_enumerator ($1, $3, current_enum_type); }
2823         ;
2824
2825 /* ISO new-type-id (5.3.4) */
2826 new_type_id:
2827           type_specifier_seq new_declarator
2828                 { $$.t = build_tree_list ($1.t, $2);
2829                   $$.new_type_flag = $1.new_type_flag; }
2830         | type_specifier_seq  %prec EMPTY
2831                 { $$.t = build_tree_list ($1.t, NULL_TREE);
2832                   $$.new_type_flag = $1.new_type_flag; }
2833         /* GNU extension to allow arrays of arbitrary types with
2834            non-constant dimension.  */
2835         | '(' type_id ')' '[' expr ']'
2836                 {
2837                   if (pedantic)
2838                     pedwarn ("ISO C++ forbids array dimensions with parenthesized type in new");
2839                   $$.t = build_nt (ARRAY_REF, TREE_VALUE ($2.t), $5);
2840                   $$.t = build_tree_list (TREE_PURPOSE ($2.t), $$.t);
2841                   $$.new_type_flag = $2.new_type_flag;
2842                 }
2843         ;
2844
2845 cv_qualifiers:
2846           /* empty */  %prec EMPTY
2847                 { $$ = NULL_TREE; }
2848         | cv_qualifiers CV_QUALIFIER
2849                 { $$ = tree_cons (NULL_TREE, $2, $$); }
2850         ;
2851
2852 nonempty_cv_qualifiers:
2853           CV_QUALIFIER
2854                 { $$.t = hash_tree_cons (NULL_TREE, $1, NULL_TREE);
2855                   $$.new_type_flag = 0; }
2856         | nonempty_cv_qualifiers CV_QUALIFIER
2857                 { $$.t = hash_tree_cons (NULL_TREE, $2, $1.t);
2858                   $$.new_type_flag = $1.new_type_flag; }
2859         | attributes %prec EMPTY
2860                 { $$.t = hash_tree_cons ($1, NULL_TREE, NULL_TREE);
2861                   $$.new_type_flag = 0; }
2862         | nonempty_cv_qualifiers attributes %prec EMPTY
2863                 { $$.t = hash_tree_cons ($2, NULL_TREE, $1.t);
2864                   $$.new_type_flag = $1.new_type_flag; }
2865         ;
2866
2867 /* These rules must follow the rules for function declarations
2868    and component declarations.  That way, longer rules are preferred.  */
2869
2870 /* An expression which will not live on the momentary obstack.  */
2871 maybe_parmlist:
2872           '(' nonnull_exprlist ')'
2873                 { $$ = $2; }
2874         | '(' parmlist ')'
2875                 { $$ = $2; }
2876         | LEFT_RIGHT
2877                 { $$ = empty_parms (); }
2878         | '(' error ')'
2879                 { $$ = NULL_TREE; }
2880         ;
2881
2882 /* A declarator that is allowed only after an explicit typespec.  */
2883
2884 after_type_declarator_intern:
2885           after_type_declarator
2886         | attributes after_type_declarator
2887                 {
2888                   /* Provide support for '(' attributes '*' declarator ')'
2889                      etc */
2890                   $$ = tree_cons ($1, $2, NULL_TREE);
2891                 }
2892         ;
2893
2894 /* may all be followed by prec '.' */
2895 after_type_declarator:
2896           '*' nonempty_cv_qualifiers after_type_declarator_intern  %prec UNARY
2897                 { $$ = make_pointer_declarator ($2.t, $3); }
2898         | '&' nonempty_cv_qualifiers after_type_declarator_intern  %prec UNARY
2899                 { $$ = make_reference_declarator ($2.t, $3); }
2900         | '*' after_type_declarator_intern  %prec UNARY
2901                 { $$ = make_pointer_declarator (NULL_TREE, $2); }
2902         | '&' after_type_declarator_intern  %prec UNARY
2903                 { $$ = make_reference_declarator (NULL_TREE, $2); }
2904         | ptr_to_mem cv_qualifiers after_type_declarator_intern
2905                 { tree arg = make_pointer_declarator ($2, $3);
2906                   $$ = build_nt (SCOPE_REF, $1, arg);
2907                 }
2908         | direct_after_type_declarator
2909         ;
2910
2911 direct_after_type_declarator:
2912           direct_after_type_declarator maybe_parmlist cv_qualifiers exception_specification_opt  %prec '.'
2913                 { $$ = make_call_declarator ($$, $2, $3, $4); }
2914         | direct_after_type_declarator '[' expr ']'
2915                 { $$ = build_nt (ARRAY_REF, $$, $3); }
2916         | direct_after_type_declarator '[' ']'
2917                 { $$ = build_nt (ARRAY_REF, $$, NULL_TREE); }
2918         | '(' after_type_declarator_intern ')'
2919                 { $$ = $2; }
2920         | nested_name_specifier type_name  %prec EMPTY
2921                 { push_nested_class ($1, 3);
2922                   $$ = build_nt (SCOPE_REF, $$, $2);
2923                   TREE_COMPLEXITY ($$) = current_class_depth; }
2924         | type_name  %prec EMPTY
2925         ;
2926
2927 nonnested_type:
2928           type_name  %prec EMPTY
2929                 {
2930                   if (TREE_CODE ($1) == IDENTIFIER_NODE)
2931                     {
2932                       $$ = lookup_name ($1, 1);
2933                       maybe_note_name_used_in_class ($1, $$);
2934                     }
2935                   else
2936                     $$ = $1;
2937                 }
2938         | global_scope type_name
2939                 {
2940                   if (TREE_CODE ($2) == IDENTIFIER_NODE)
2941                     $$ = IDENTIFIER_GLOBAL_VALUE ($2);
2942                   else
2943                     $$ = $2;
2944                   got_scope = NULL_TREE;
2945                 }
2946         ;
2947
2948 complete_type_name:
2949           nonnested_type
2950         | nested_type
2951         | global_scope nested_type
2952                 { $$ = $2; }
2953         ;
2954
2955 nested_type:
2956           nested_name_specifier type_name  %prec EMPTY
2957                 { $$ = get_type_decl ($2); }
2958         ;
2959
2960 /* A declarator allowed whether or not there has been
2961    an explicit typespec.  These cannot redeclare a typedef-name.  */
2962
2963 notype_declarator_intern:
2964           notype_declarator
2965         | attributes notype_declarator
2966                 {
2967                   /* Provide support for '(' attributes '*' declarator ')'
2968                      etc */
2969                   $$ = tree_cons ($1, $2, NULL_TREE);
2970                 }
2971         ;
2972
2973 notype_declarator:
2974           '*' nonempty_cv_qualifiers notype_declarator_intern  %prec UNARY
2975                 { $$ = make_pointer_declarator ($2.t, $3); }
2976         | '&' nonempty_cv_qualifiers notype_declarator_intern  %prec UNARY
2977                 { $$ = make_reference_declarator ($2.t, $3); }
2978         | '*' notype_declarator_intern  %prec UNARY
2979                 { $$ = make_pointer_declarator (NULL_TREE, $2); }
2980         | '&' notype_declarator_intern  %prec UNARY
2981                 { $$ = make_reference_declarator (NULL_TREE, $2); }
2982         | ptr_to_mem cv_qualifiers notype_declarator_intern
2983                 { tree arg = make_pointer_declarator ($2, $3);
2984                   $$ = build_nt (SCOPE_REF, $1, arg);
2985                 }
2986         | direct_notype_declarator
2987         ;
2988
2989 complex_notype_declarator:
2990           '*' nonempty_cv_qualifiers notype_declarator_intern  %prec UNARY
2991                 { $$ = make_pointer_declarator ($2.t, $3); }
2992         | '&' nonempty_cv_qualifiers notype_declarator_intern  %prec UNARY
2993                 { $$ = make_reference_declarator ($2.t, $3); }
2994         | '*' complex_notype_declarator  %prec UNARY
2995                 { $$ = make_pointer_declarator (NULL_TREE, $2); }
2996         | '&' complex_notype_declarator  %prec UNARY
2997                 { $$ = make_reference_declarator (NULL_TREE, $2); }
2998         | ptr_to_mem cv_qualifiers notype_declarator_intern
2999                 { tree arg = make_pointer_declarator ($2, $3);
3000                   $$ = build_nt (SCOPE_REF, $1, arg);
3001                 }
3002         | complex_direct_notype_declarator
3003         ;
3004
3005 complex_direct_notype_declarator:
3006           direct_notype_declarator maybe_parmlist cv_qualifiers exception_specification_opt  %prec '.'
3007                 { $$ = make_call_declarator ($$, $2, $3, $4); }
3008         | '(' complex_notype_declarator ')'
3009                 { $$ = $2; }
3010         | direct_notype_declarator '[' expr ']'
3011                 { $$ = build_nt (ARRAY_REF, $$, $3); }
3012         | direct_notype_declarator '[' ']'
3013                 { $$ = build_nt (ARRAY_REF, $$, NULL_TREE); }
3014         | notype_qualified_id
3015                 { enter_scope_of ($1); }
3016         | global_scope notype_qualified_id
3017                 { enter_scope_of ($2); $$ = $2;}
3018         | global_scope notype_unqualified_id
3019                 { $$ = build_nt (SCOPE_REF, global_namespace, $2);
3020                   enter_scope_of ($$);
3021                 }
3022         | nested_name_specifier notype_template_declarator
3023                 { got_scope = NULL_TREE;
3024                   $$ = build_nt (SCOPE_REF, $1, $2);
3025                   enter_scope_of ($$);
3026                 }
3027         ;
3028
3029 qualified_id:
3030           nested_name_specifier unqualified_id
3031                 { got_scope = NULL_TREE;
3032                   $$ = build_nt (SCOPE_REF, $$, $2); }
3033         | nested_name_specifier object_template_id
3034                 { got_scope = NULL_TREE;
3035                   $$ = build_nt (SCOPE_REF, $1, $2); }
3036         ;
3037
3038 notype_qualified_id:
3039           nested_name_specifier notype_unqualified_id
3040                 { got_scope = NULL_TREE;
3041                   $$ = build_nt (SCOPE_REF, $$, $2); }
3042         | nested_name_specifier object_template_id
3043                 { got_scope = NULL_TREE;
3044                   $$ = build_nt (SCOPE_REF, $1, $2); }
3045         ;
3046
3047 overqualified_id:
3048           notype_qualified_id
3049         | global_scope notype_qualified_id
3050                 { $$ = $2; }
3051         ;
3052
3053 functional_cast:
3054           typespec '(' nonnull_exprlist ')'
3055                 { $$ = build_functional_cast ($1.t, $3); }
3056         | typespec '(' expr_or_declarator_intern ')'
3057                 { $$ = reparse_decl_as_expr ($1.t, $3); }
3058         | typespec fcast_or_absdcl  %prec EMPTY
3059                 { $$ = reparse_absdcl_as_expr ($1.t, $2); }
3060         ;
3061
3062 type_name:
3063           tTYPENAME
3064         | SELFNAME
3065         | template_type  %prec EMPTY
3066         ;
3067
3068 nested_name_specifier:
3069           nested_name_specifier_1
3070         | nested_name_specifier nested_name_specifier_1
3071                 { $$ = $2; }
3072         | nested_name_specifier TEMPLATE explicit_template_type SCOPE
3073                 { got_scope = $$
3074                     = make_typename_type ($1, $3, tf_error | tf_parsing); }
3075         /* Error handling per Core 125.  */
3076         | nested_name_specifier IDENTIFIER SCOPE
3077                 { got_scope = $$
3078                     = make_typename_type ($1, $2, tf_error | tf_parsing); }
3079         | nested_name_specifier PTYPENAME SCOPE
3080                 { got_scope = $$
3081                     = make_typename_type ($1, $2, tf_error | tf_parsing); }
3082         ;
3083
3084 /* Why the @#$%^& do type_name and notype_identifier need to be expanded
3085    inline here?!?  (jason) */
3086 nested_name_specifier_1:
3087           tTYPENAME SCOPE
3088                 {
3089                   if (TREE_CODE ($1) == IDENTIFIER_NODE)
3090                     {
3091                       $$ = lastiddecl;
3092                       maybe_note_name_used_in_class ($1, $$);
3093                     }
3094                   got_scope = $$ =
3095                     complete_type (TYPE_MAIN_VARIANT (TREE_TYPE ($$)));
3096                 }
3097         | SELFNAME SCOPE
3098                 {
3099                   if (TREE_CODE ($1) == IDENTIFIER_NODE)
3100                     $$ = lastiddecl;
3101                   got_scope = $$ = TREE_TYPE ($$);
3102                 }
3103         | NSNAME SCOPE
3104                 {
3105                   if (TREE_CODE ($$) == IDENTIFIER_NODE)
3106                     $$ = lastiddecl;
3107                   got_scope = $$;
3108                 }
3109         | template_type SCOPE
3110                 { got_scope = $$ = complete_type (TREE_TYPE ($1)); }
3111         ;
3112
3113 typename_sub:
3114           typename_sub0
3115         | global_scope typename_sub0
3116                 { $$ = $2; }
3117         ;
3118
3119 typename_sub0:
3120           typename_sub1 identifier %prec EMPTY
3121                 {
3122                   if (TYPE_P ($1))
3123                     $$ = make_typename_type ($1, $2, tf_error | tf_parsing);
3124                   else if (TREE_CODE ($2) == IDENTIFIER_NODE)
3125                     error ("`%T' is not a class or namespace", $2);
3126                   else
3127                     {
3128                       $$ = $2;
3129                       if (TREE_CODE ($$) == TYPE_DECL)
3130                         $$ = TREE_TYPE ($$);
3131                     }
3132                 }
3133         | typename_sub1 template_type %prec EMPTY
3134                 { $$ = TREE_TYPE ($2); }
3135         | typename_sub1 explicit_template_type %prec EMPTY
3136                 { $$ = make_typename_type ($1, $2, tf_error | tf_parsing); }
3137         | typename_sub1 TEMPLATE explicit_template_type %prec EMPTY
3138                 { $$ = make_typename_type ($1, $3, tf_error | tf_parsing); }
3139         ;
3140
3141 typename_sub1:
3142           typename_sub2
3143                 {
3144                   if (TREE_CODE ($1) == IDENTIFIER_NODE)
3145                     error ("`%T' is not a class or namespace", $1);
3146                   else if (TREE_CODE ($1) == TYPE_DECL)
3147                     $$ = TREE_TYPE ($1);
3148                 }
3149         | typename_sub1 typename_sub2
3150                 {
3151                   if (TYPE_P ($1))
3152                     $$ = make_typename_type ($1, $2, tf_error | tf_parsing);
3153                   else if (TREE_CODE ($2) == IDENTIFIER_NODE)
3154                     error ("`%T' is not a class or namespace", $2);
3155                   else
3156                     {
3157                       $$ = $2;
3158                       if (TREE_CODE ($$) == TYPE_DECL)
3159                         $$ = TREE_TYPE ($$);
3160                     }
3161                 }
3162         | typename_sub1 explicit_template_type SCOPE
3163                 { got_scope = $$
3164                     = make_typename_type ($1, $2, tf_error | tf_parsing); }
3165         | typename_sub1 TEMPLATE explicit_template_type SCOPE
3166                 { got_scope = $$
3167                     = make_typename_type ($1, $3, tf_error | tf_parsing); }
3168         ;
3169
3170 /* This needs to return a TYPE_DECL for simple names so that we don't
3171    forget what name was used.  */
3172 typename_sub2:
3173           tTYPENAME SCOPE
3174                 {
3175                   if (TREE_CODE ($1) != TYPE_DECL)
3176                     $$ = lastiddecl;
3177
3178                   /* Retrieve the type for the identifier, which might involve
3179                      some computation. */
3180                   got_scope = complete_type (TREE_TYPE ($$));
3181
3182                   if ($$ == error_mark_node)
3183                     error ("`%T' is not a class or namespace", $1);
3184                 }
3185         | SELFNAME SCOPE
3186                 {
3187                   if (TREE_CODE ($1) != TYPE_DECL)
3188                     $$ = lastiddecl;
3189                   got_scope = complete_type (TREE_TYPE ($$));
3190                 }
3191         | template_type SCOPE
3192                 { got_scope = $$ = complete_type (TREE_TYPE ($$)); }
3193         | PTYPENAME SCOPE
3194         | IDENTIFIER SCOPE
3195         | NSNAME SCOPE
3196                 {
3197                   if (TREE_CODE ($$) == IDENTIFIER_NODE)
3198                     $$ = lastiddecl;
3199                   got_scope = $$;
3200                 }
3201         ;
3202
3203 explicit_template_type:
3204           identifier '<' template_arg_list_opt template_close_bracket
3205                 { $$ = build_min_nt (TEMPLATE_ID_EXPR, $1, $3); }
3206         ;
3207
3208 complex_type_name:
3209           global_scope type_name
3210                 {
3211                   if (TREE_CODE ($2) == IDENTIFIER_NODE)
3212                     $$ = IDENTIFIER_GLOBAL_VALUE ($2);
3213                   else
3214                     $$ = $2;
3215                   got_scope = NULL_TREE;
3216                 }
3217         | nested_type
3218         | global_scope nested_type
3219                 { $$ = $2; }
3220         ;
3221
3222 ptr_to_mem:
3223           nested_name_specifier '*'
3224                 { got_scope = NULL_TREE; }
3225         | global_scope nested_name_specifier '*'
3226                 { $$ = $2; got_scope = NULL_TREE; }
3227         ;
3228
3229 /* All uses of explicit global scope must go through this nonterminal so
3230    that got_scope will be set before yylex is called to get the next token.  */
3231 global_scope:
3232           SCOPE
3233                 { got_scope = void_type_node; }
3234         ;
3235
3236 /* ISO new-declarator (5.3.4) */
3237 new_declarator:
3238           '*' cv_qualifiers new_declarator
3239                 { $$ = make_pointer_declarator ($2, $3); }
3240         | '*' cv_qualifiers  %prec EMPTY
3241                 { $$ = make_pointer_declarator ($2, NULL_TREE); }
3242         | '&' cv_qualifiers new_declarator  %prec EMPTY
3243                 { $$ = make_reference_declarator ($2, $3); }
3244         | '&' cv_qualifiers  %prec EMPTY
3245                 { $$ = make_reference_declarator ($2, NULL_TREE); }
3246         | ptr_to_mem cv_qualifiers  %prec EMPTY
3247                 { tree arg = make_pointer_declarator ($2, NULL_TREE);
3248                   $$ = build_nt (SCOPE_REF, $1, arg);
3249                 }
3250         | ptr_to_mem cv_qualifiers new_declarator
3251                 { tree arg = make_pointer_declarator ($2, $3);
3252                   $$ = build_nt (SCOPE_REF, $1, arg);
3253                 }
3254         | direct_new_declarator  %prec EMPTY
3255         ;
3256
3257 /* ISO direct-new-declarator (5.3.4) */
3258 direct_new_declarator:
3259           '[' expr ']'
3260                 { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); }
3261         | direct_new_declarator '[' expr ']'
3262                 { $$ = build_nt (ARRAY_REF, $$, $3); }
3263         ;
3264
3265 absdcl_intern:
3266           absdcl
3267         | attributes absdcl
3268                 {
3269                   /* Provide support for '(' attributes '*' declarator ')'
3270                      etc */
3271                   $$ = tree_cons ($1, $2, NULL_TREE);
3272                 }
3273         ;
3274
3275 /* ISO abstract-declarator (8.1) */
3276 absdcl:
3277           '*' nonempty_cv_qualifiers absdcl_intern
3278                 { $$ = make_pointer_declarator ($2.t, $3); }
3279         | '*' absdcl_intern
3280                 { $$ = make_pointer_declarator (NULL_TREE, $2); }
3281         | '*' nonempty_cv_qualifiers  %prec EMPTY
3282                 { $$ = make_pointer_declarator ($2.t, NULL_TREE); }
3283         | '*'  %prec EMPTY
3284                 { $$ = make_pointer_declarator (NULL_TREE, NULL_TREE); }
3285         | '&' nonempty_cv_qualifiers absdcl_intern
3286                 { $$ = make_reference_declarator ($2.t, $3); }
3287         | '&' absdcl_intern
3288                 { $$ = make_reference_declarator (NULL_TREE, $2); }
3289         | '&' nonempty_cv_qualifiers  %prec EMPTY
3290                 { $$ = make_reference_declarator ($2.t, NULL_TREE); }
3291         | '&'  %prec EMPTY
3292                 { $$ = make_reference_declarator (NULL_TREE, NULL_TREE); }
3293         | ptr_to_mem cv_qualifiers  %prec EMPTY
3294                 { tree arg = make_pointer_declarator ($2, NULL_TREE);
3295                   $$ = build_nt (SCOPE_REF, $1, arg);
3296                 }
3297         | ptr_to_mem cv_qualifiers absdcl_intern
3298                 { tree arg = make_pointer_declarator ($2, $3);
3299                   $$ = build_nt (SCOPE_REF, $1, arg);
3300                 }
3301         | direct_abstract_declarator  %prec EMPTY
3302         ;
3303
3304 /* ISO direct-abstract-declarator (8.1) */
3305 direct_abstract_declarator:
3306           '(' absdcl_intern ')'
3307                 { $$ = $2; }
3308           /* `(typedef)1' is `int'.  */
3309         | direct_abstract_declarator '(' parmlist ')' cv_qualifiers exception_specification_opt  %prec '.'
3310                 { $$ = make_call_declarator ($$, $3, $5, $6); }
3311         | direct_abstract_declarator LEFT_RIGHT cv_qualifiers exception_specification_opt  %prec '.'
3312                 { $$ = make_call_declarator ($$, empty_parms (), $3, $4); }
3313         | direct_abstract_declarator '[' expr ']'  %prec '.'
3314                 { $$ = build_nt (ARRAY_REF, $$, $3); }
3315         | direct_abstract_declarator '[' ']'  %prec '.'
3316                 { $$ = build_nt (ARRAY_REF, $$, NULL_TREE); }
3317         | '(' complex_parmlist ')' cv_qualifiers exception_specification_opt  %prec '.'
3318                 { $$ = make_call_declarator (NULL_TREE, $2, $4, $5); }
3319         | regcast_or_absdcl cv_qualifiers exception_specification_opt  %prec '.'
3320                 { set_quals_and_spec ($$, $2, $3); }
3321         | fcast_or_absdcl cv_qualifiers exception_specification_opt  %prec '.'
3322                 { set_quals_and_spec ($$, $2, $3); }
3323         | '[' expr ']'  %prec '.'
3324                 { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); }
3325         | '[' ']'  %prec '.'
3326                 { $$ = build_nt (ARRAY_REF, NULL_TREE, NULL_TREE); }
3327         ;
3328
3329 /* For C++, decls and stmts can be intermixed, so we don't need to
3330    have a special rule that won't start parsing the stmt section
3331    until we have a stmt that parses without errors.  */
3332
3333 stmts:
3334           stmt
3335         | errstmt
3336         | stmts stmt
3337         | stmts errstmt
3338         ;
3339
3340 errstmt:
3341           error ';'
3342         ;
3343
3344 /* Read zero or more forward-declarations for labels
3345    that nested functions can jump to.  */
3346 maybe_label_decls:
3347           /* empty */
3348         | label_decls
3349                 { if (pedantic)
3350                     pedwarn ("ISO C++ forbids label declarations"); }
3351         ;
3352
3353 label_decls:
3354           label_decl
3355         | label_decls label_decl
3356         ;
3357
3358 label_decl:
3359           LABEL identifiers_or_typenames ';'
3360                 {
3361                   while ($2)
3362                     {
3363                       finish_label_decl (TREE_VALUE ($2));
3364                       $2 = TREE_CHAIN ($2);
3365                     }
3366                 }
3367         ;
3368
3369 compstmt_or_stmtexpr:
3370           save_lineno '{'
3371                 { $<ttype>$ = begin_compound_stmt (0); }
3372           compstmtend
3373                 { STMT_LINENO ($<ttype>3) = $1;
3374                   finish_compound_stmt (0, $<ttype>3); }
3375         ;
3376
3377 compstmt:
3378           compstmt_or_stmtexpr
3379                 { last_expr_type = NULL_TREE; }
3380         ;
3381
3382 simple_if:
3383           IF
3384                 { $<ttype>$ = begin_if_stmt ();
3385                   cond_stmt_keyword = "if"; }
3386             paren_cond_or_null
3387                 { finish_if_stmt_cond ($3, $<ttype>2); }
3388             implicitly_scoped_stmt
3389                 { $$ = $<ttype>2;
3390                   finish_then_clause ($<ttype>2); }
3391         ;
3392
3393 implicitly_scoped_stmt:
3394           compstmt
3395         |
3396                 { $<ttype>$ = begin_compound_stmt (0); }
3397           save_lineno simple_stmt
3398                 { STMT_LINENO ($<ttype>1) = $2;
3399                   if ($3) STMT_LINENO ($3) = $2;
3400                   finish_compound_stmt (0, $<ttype>1); }
3401         ;
3402
3403 stmt:
3404           compstmt
3405         | save_lineno simple_stmt
3406                 { if ($2) STMT_LINENO ($2) = $1; }
3407         ;
3408
3409 simple_stmt:
3410           decl
3411                 { finish_stmt ();
3412                   $$ = NULL_TREE; }
3413         | expr ';'
3414                 { $$ = finish_expr_stmt ($1); }
3415         | simple_if ELSE
3416                 { begin_else_clause (); }
3417           implicitly_scoped_stmt
3418                 {
3419                   $$ = $1;
3420                   finish_else_clause ($1);
3421                   finish_if_stmt ();
3422                 }
3423         | simple_if  %prec IF
3424                 { $$ = $1;
3425                   finish_if_stmt (); }
3426         | WHILE
3427                 {
3428                   $<ttype>$ = begin_while_stmt ();
3429                   cond_stmt_keyword = "while";
3430                 }
3431           paren_cond_or_null
3432                 { finish_while_stmt_cond ($3, $<ttype>2); }
3433           implicitly_scoped_stmt
3434                 { $$ = $<ttype>2;
3435                   finish_while_stmt ($<ttype>2); }
3436         | DO
3437                 { $<ttype>$ = begin_do_stmt (); }
3438           implicitly_scoped_stmt WHILE
3439                 {
3440                   finish_do_body ($<ttype>2);
3441                   cond_stmt_keyword = "do";
3442                 }
3443           paren_expr_or_null ';'
3444                 { $$ = $<ttype>2;
3445                   finish_do_stmt ($6, $<ttype>2); }
3446         | FOR
3447                 { $<ttype>$ = begin_for_stmt (); }
3448           '(' for.init.statement
3449                 { finish_for_init_stmt ($<ttype>2); }
3450           xcond ';'
3451                 { finish_for_cond ($6, $<ttype>2); }
3452           xexpr ')'
3453                 { finish_for_expr ($9, $<ttype>2); }
3454           implicitly_scoped_stmt
3455                 { $$ = $<ttype>2;
3456                   finish_for_stmt ($<ttype>2); }
3457         | SWITCH
3458                 { $<ttype>$ = begin_switch_stmt (); }
3459             '(' condition ')'
3460                 { finish_switch_cond ($4, $<ttype>2); }
3461           implicitly_scoped_stmt
3462                 { $$ = $<ttype>2;
3463                   finish_switch_stmt ($<ttype>2); }
3464         | CASE expr_no_commas ':'
3465                 { $<ttype>$ = finish_case_label ($2, NULL_TREE); }
3466           stmt
3467                 { $$ = $<ttype>4; }
3468         | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
3469                 { $<ttype>$ = finish_case_label ($2, $4); }
3470           stmt
3471                 { $$ = $<ttype>6; }
3472         | DEFAULT ':'
3473                 { $<ttype>$ = finish_case_label (NULL_TREE, NULL_TREE); }
3474           stmt
3475                 { $$ = $<ttype>3; }
3476         | BREAK ';'
3477                 { $$ = finish_break_stmt (); }
3478         | CONTINUE ';'
3479                 { $$ = finish_continue_stmt (); }
3480         | RETURN_KEYWORD ';'
3481                 { $$ = finish_return_stmt (NULL_TREE); }
3482         | RETURN_KEYWORD expr ';'
3483                 { $$ = finish_return_stmt ($2); }
3484         | asm_keyword maybe_cv_qualifier '(' STRING ')' ';'
3485                 { $$ = finish_asm_stmt ($2, $4, NULL_TREE, NULL_TREE,
3486                                         NULL_TREE);
3487                   ASM_INPUT_P ($$) = 1; }
3488         /* This is the case with just output operands.  */
3489         | asm_keyword maybe_cv_qualifier '(' STRING ':' asm_operands ')' ';'
3490                 { $$ = finish_asm_stmt ($2, $4, $6, NULL_TREE, NULL_TREE); }
3491         /* This is the case with input operands as well.  */
3492         | asm_keyword maybe_cv_qualifier '(' STRING ':' asm_operands ':'
3493           asm_operands ')' ';'
3494                 { $$ = finish_asm_stmt ($2, $4, $6, $8, NULL_TREE); }
3495         | asm_keyword maybe_cv_qualifier '(' STRING SCOPE asm_operands ')' ';'
3496                 { $$ = finish_asm_stmt ($2, $4, NULL_TREE, $6, NULL_TREE); }
3497         /* This is the case with clobbered registers as well.  */
3498         | asm_keyword maybe_cv_qualifier '(' STRING ':' asm_operands ':'
3499           asm_operands ':' asm_clobbers ')' ';'
3500                 { $$ = finish_asm_stmt ($2, $4, $6, $8, $10); }
3501         | asm_keyword maybe_cv_qualifier '(' STRING SCOPE asm_operands ':'
3502           asm_clobbers ')' ';'
3503                 { $$ = finish_asm_stmt ($2, $4, NULL_TREE, $6, $8); }
3504         | asm_keyword maybe_cv_qualifier '(' STRING ':' asm_operands SCOPE
3505           asm_clobbers ')' ';'
3506                 { $$ = finish_asm_stmt ($2, $4, $6, NULL_TREE, $8); }
3507         | GOTO '*' expr ';'
3508                 {
3509                   if (pedantic)
3510                     pedwarn ("ISO C++ forbids computed gotos");
3511                   $$ = finish_goto_stmt ($3);
3512                 }
3513         | GOTO identifier ';'
3514                 { $$ = finish_goto_stmt ($2); }
3515         | label_colon stmt
3516                 { $$ = NULL_TREE; }
3517         | label_colon '}'
3518                 { error ("label must be followed by statement");
3519                   yyungetc ('}', 0);
3520                   $$ = NULL_TREE; }
3521         | ';'
3522                 { finish_stmt ();
3523                   $$ = NULL_TREE; }
3524         | try_block
3525                 { $$ = NULL_TREE; }
3526         | using_directive
3527                 { $$ = NULL_TREE; }
3528         | namespace_using_decl
3529                 { do_local_using_decl ($1);
3530                   $$ = NULL_TREE; }
3531         | namespace_alias
3532                 { $$ = NULL_TREE; }
3533         ;
3534
3535 function_try_block:
3536           TRY
3537                 { $<ttype>$ = begin_function_try_block (); }
3538           function_body
3539                 { finish_function_try_block ($<ttype>2); }
3540           handler_seq
3541                 { finish_function_handler_sequence ($<ttype>2); }
3542         ;
3543
3544 try_block:
3545           TRY
3546                 { $<ttype>$ = begin_try_block (); }
3547           compstmt
3548                 { finish_try_block ($<ttype>2); }
3549           handler_seq
3550                 { finish_handler_sequence ($<ttype>2); }
3551         ;
3552
3553 handler_seq:
3554           handler
3555         | handler_seq handler
3556         | /* empty */
3557                 { /* Generate a fake handler block to avoid later aborts. */
3558                   tree fake_handler = begin_handler ();
3559                   finish_handler_parms (NULL_TREE, fake_handler);
3560                   finish_handler (fake_handler);
3561                   $<ttype>$ = fake_handler;
3562
3563                   error ("must have at least one catch per try block");
3564                 }
3565         ;
3566
3567 handler:
3568           CATCH
3569                 { $<ttype>$ = begin_handler (); }
3570           handler_args
3571                 { finish_handler_parms ($3, $<ttype>2); }
3572           compstmt
3573                 { finish_handler ($<ttype>2); }
3574         ;
3575
3576 type_specifier_seq:
3577           typed_typespecs  %prec EMPTY
3578         | nonempty_cv_qualifiers  %prec EMPTY
3579         ;
3580
3581 handler_args:
3582           '(' ELLIPSIS ')'
3583                 { $$ = NULL_TREE; }
3584         /* This doesn't allow reference parameters, the below does.
3585         | '(' type_specifier_seq absdcl ')'
3586                 { check_for_new_type ("inside exception declarations", $2);
3587                   expand_start_catch_block ($2.t, $3); }
3588         | '(' type_specifier_seq ')'
3589                 { check_for_new_type ("inside exception declarations", $2);
3590                   expand_start_catch_block ($2.t, NULL_TREE); }
3591         | '(' type_specifier_seq notype_declarator ')'
3592                 { check_for_new_type ("inside exception declarations", $2);
3593                   expand_start_catch_block ($2.t, $3); }
3594         | '(' typed_typespecs after_type_declarator ')'
3595                 { check_for_new_type ("inside exception declarations", $2);
3596                   expand_start_catch_block ($2.t, $3); }
3597         This allows reference parameters...  */
3598         | '(' parm ')'
3599                 {
3600                   check_for_new_type ("inside exception declarations", $2);
3601                   $$ = start_handler_parms (TREE_PURPOSE ($2.t),
3602                                             TREE_VALUE ($2.t));
3603                 }
3604         ;
3605
3606 label_colon:
3607           IDENTIFIER ':'
3608                 { finish_label_stmt ($1); }
3609         | PTYPENAME ':'
3610                 { finish_label_stmt ($1); }
3611         | tTYPENAME ':'
3612                 { finish_label_stmt ($1); }
3613         | SELFNAME ':'
3614                 { finish_label_stmt ($1); }
3615         ;
3616
3617 for.init.statement:
3618           xexpr ';'
3619                 { finish_expr_stmt ($1); }
3620         | decl
3621         | '{' compstmtend
3622                 { if (pedantic)
3623                     pedwarn ("ISO C++ forbids compound statements inside for initializations");
3624                 }
3625         ;
3626
3627 /* Either a type-qualifier or nothing.  First thing in an `asm' statement.  */
3628
3629 maybe_cv_qualifier:
3630           /* empty */
3631                 { $$ = NULL_TREE; }
3632         | CV_QUALIFIER
3633         ;
3634
3635 xexpr:
3636           /* empty */
3637                 { $$ = NULL_TREE; }
3638         | expr
3639         | error
3640                 { $$ = NULL_TREE; }
3641         ;
3642
3643 /* These are the operands other than the first string and colon
3644    in  asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x))  */
3645 asm_operands:
3646           /* empty */
3647                 { $$ = NULL_TREE; }
3648         | nonnull_asm_operands
3649         ;
3650
3651 nonnull_asm_operands:
3652           asm_operand
3653         | nonnull_asm_operands ',' asm_operand
3654                 { $$ = chainon ($$, $3); }
3655         ;
3656
3657 asm_operand:
3658           STRING '(' expr ')'
3659                 { $$ = build_tree_list (build_tree_list (NULL_TREE, $1), $3); }
3660         | '[' identifier ']' STRING '(' expr ')'
3661                 { $2 = build_string (IDENTIFIER_LENGTH ($2),
3662                                      IDENTIFIER_POINTER ($2));
3663                   $$ = build_tree_list (build_tree_list ($2, $4), $6); }
3664         ;
3665
3666 asm_clobbers:
3667           STRING
3668                 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);}
3669         | asm_clobbers ',' STRING
3670                 { $$ = tree_cons (NULL_TREE, $3, $1); }
3671         ;
3672
3673 /* This is what appears inside the parens in a function declarator.
3674    Its value is represented in the format that grokdeclarator expects.
3675
3676    In C++, declaring a function with no parameters
3677    means that that function takes *no* parameters.  */
3678
3679 parmlist:
3680           /* empty */
3681                 {
3682                   $$ = empty_parms();
3683                 }
3684         | complex_parmlist
3685         | type_id
3686                 { $$ = finish_parmlist (build_tree_list (NULL_TREE, $1.t), 0);
3687                   check_for_new_type ("inside parameter list", $1); }
3688         ;
3689
3690 /* This nonterminal does not include the common sequence '(' type_id ')',
3691    as it is ambiguous and must be disambiguated elsewhere.  */
3692 complex_parmlist:
3693           parms
3694                 { $$ = finish_parmlist ($$, 0); }
3695         | parms_comma ELLIPSIS
3696                 { $$ = finish_parmlist ($1, 1); }
3697         /* C++ allows an ellipsis without a separating ',' */
3698         | parms ELLIPSIS
3699                 { $$ = finish_parmlist ($1, 1); }
3700         | type_id ELLIPSIS
3701                 { $$ = finish_parmlist (build_tree_list (NULL_TREE,
3702                                                          $1.t), 1); }
3703         | ELLIPSIS
3704                 { $$ = finish_parmlist (NULL_TREE, 1); }
3705         | parms ':'
3706                 {
3707                   /* This helps us recover from really nasty
3708                      parse errors, for example, a missing right
3709                      parenthesis.  */
3710                   yyerror ("possibly missing ')'");
3711                   $$ = finish_parmlist ($1, 0);
3712                   yyungetc (':', 0);
3713                   yychar = ')';
3714                 }
3715         | type_id ':'
3716                 {
3717                   /* This helps us recover from really nasty
3718                      parse errors, for example, a missing right
3719                      parenthesis.  */
3720                   yyerror ("possibly missing ')'");
3721                   $$ = finish_parmlist (build_tree_list (NULL_TREE,
3722                                                          $1.t), 0);
3723                   yyungetc (':', 0);
3724                   yychar = ')';
3725                 }
3726         ;
3727
3728 /* A default argument to a */
3729 defarg:
3730           '='
3731                 { maybe_snarf_defarg (); }
3732           defarg1
3733                 { $$ = $3; }
3734         ;
3735
3736 defarg1:
3737           DEFARG
3738         | init
3739         ;
3740
3741 /* A nonempty list of parameter declarations or type names.  */
3742 parms:
3743           named_parm
3744                 { check_for_new_type ("in a parameter list", $1);
3745                   $$ = build_tree_list (NULL_TREE, $1.t); }
3746         | parm defarg
3747                 { check_for_new_type ("in a parameter list", $1);
3748                   $$ = build_tree_list ($2, $1.t); }
3749         | parms_comma full_parm
3750                 { check_for_new_type ("in a parameter list", $2);
3751                   $$ = chainon ($$, $2.t); }
3752         | parms_comma bad_parm
3753                 { $$ = chainon ($$, build_tree_list (NULL_TREE, $2)); }
3754         | parms_comma bad_parm '=' init
3755                 { $$ = chainon ($$, build_tree_list ($4, $2)); }
3756         ;
3757
3758 parms_comma:
3759           parms ','
3760         | type_id ','
3761                 { check_for_new_type ("in a parameter list", $1);
3762                   $$ = build_tree_list (NULL_TREE, $1.t); }
3763         ;
3764
3765 /* A single parameter declaration or parameter type name,
3766    as found in a parmlist.  */
3767 named_parm:
3768         /* Here we expand typed_declspecs inline to avoid mis-parsing of
3769            TYPESPEC IDENTIFIER.  */
3770           typed_declspecs1 declarator
3771                 { $$.new_type_flag = $1.new_type_flag;
3772                   $$.t = build_tree_list ($1.t, $2); }
3773         | typed_typespecs declarator
3774                 { $$.t = build_tree_list ($1.t, $2);
3775                   $$.new_type_flag = $1.new_type_flag; }
3776         | typespec declarator
3777                 { $$.t = build_tree_list (build_tree_list (NULL_TREE, $1.t),
3778                                           $2);
3779                   $$.new_type_flag = $1.new_type_flag; }
3780         | typed_declspecs1 absdcl
3781                 { $$.t = build_tree_list ($1.t, $2);
3782                   $$.new_type_flag = $1.new_type_flag; }
3783         | typed_declspecs1  %prec EMPTY
3784                 { $$.t = build_tree_list ($1.t, NULL_TREE);
3785                   $$.new_type_flag = $1.new_type_flag; }
3786         | declmods notype_declarator
3787                 { $$.t = build_tree_list ($1.t, $2);
3788                   $$.new_type_flag = 0; }
3789         ;
3790
3791 full_parm:
3792           parm
3793                 { $$.t = build_tree_list (NULL_TREE, $1.t);
3794                   $$.new_type_flag = $1.new_type_flag;  }
3795         | parm defarg
3796                 { $$.t = build_tree_list ($2, $1.t);
3797                   $$.new_type_flag = $1.new_type_flag;  }
3798         ;
3799
3800 parm:
3801           named_parm
3802         | type_id
3803         ;
3804
3805 see_typename:
3806           /* empty */  %prec EMPTY
3807                 { see_typename (); }
3808         ;
3809
3810 bad_parm:
3811           /* empty */ %prec EMPTY
3812                 {
3813                   error ("type specifier omitted for parameter");
3814                   $$ = build_tree_list (integer_type_node, NULL_TREE);
3815                 }
3816         | notype_declarator
3817                 {
3818                   if (TREE_CODE ($$) == SCOPE_REF)
3819                     {
3820                       if (TREE_CODE (TREE_OPERAND ($$, 0)) == TEMPLATE_TYPE_PARM
3821                           || TREE_CODE (TREE_OPERAND ($$, 0)) == BOUND_TEMPLATE_TEMPLATE_PARM)
3822                         error ("`%E' is not a type, use `typename %E' to make it one", $$);
3823                       else
3824                         error ("no type `%D' in `%T'", TREE_OPERAND ($$, 1), TREE_OPERAND ($$, 0));
3825                     }
3826                   else
3827                     error ("type specifier omitted for parameter `%E'", $$);
3828                   $$ = build_tree_list (integer_type_node, $$);
3829                 }
3830         ;
3831
3832 bad_decl:
3833           IDENTIFIER template_arg_list_ignore IDENTIFIER arg_list_ignore ';'
3834                 {
3835                   error("'%D' is used as a type, but is not defined as a type.", $1);
3836                   $3 = error_mark_node;
3837                 }
3838         ;
3839
3840 template_arg_list_ignore:
3841           '<' template_arg_list_opt template_close_bracket
3842                 { }
3843         | /* empty */
3844         ;
3845
3846 arg_list_ignore:
3847           '(' nonnull_exprlist ')'
3848                 { }
3849         | /* empty */
3850         ;
3851
3852 exception_specification_opt:
3853           /* empty */  %prec EMPTY
3854                 { $$ = NULL_TREE; }
3855         | THROW '(' ansi_raise_identifiers  ')'  %prec EMPTY
3856                 { $$ = $3; }
3857         | THROW LEFT_RIGHT  %prec EMPTY
3858                 { $$ = empty_except_spec; }
3859         ;
3860
3861 ansi_raise_identifier:
3862           type_id
3863                 {
3864                   check_for_new_type ("exception specifier", $1);
3865                   $$ = groktypename ($1.t);
3866                 }
3867           | error
3868                 { $$ = error_mark_node; }
3869         ;
3870
3871 ansi_raise_identifiers:
3872           ansi_raise_identifier
3873                 { $$ = add_exception_specifier (NULL_TREE, $1, 1); }
3874         | ansi_raise_identifiers ',' ansi_raise_identifier
3875                 { $$ = add_exception_specifier ($1, $3, 1); }
3876         ;
3877
3878 conversion_declarator:
3879           /* empty */  %prec EMPTY
3880                 { $$ = NULL_TREE; }
3881         | '*' cv_qualifiers conversion_declarator
3882                 { $$ = make_pointer_declarator ($2, $3); }
3883         | '&' cv_qualifiers conversion_declarator
3884                 { $$ = make_reference_declarator ($2, $3); }
3885         | ptr_to_mem cv_qualifiers conversion_declarator
3886                 { tree arg = make_pointer_declarator ($2, $3);
3887                   $$ = build_nt (SCOPE_REF, $1, arg);
3888                 }
3889         ;
3890
3891 operator:
3892         OPERATOR
3893         {
3894           saved_scopes = tree_cons (got_scope, got_object, saved_scopes);
3895           TREE_LANG_FLAG_0 (saved_scopes) = looking_for_typename;
3896           /* We look for conversion-type-id's in both the class and current
3897              scopes, just as for ID in 'ptr->ID::'.  */
3898           looking_for_typename = 1;
3899           got_object = got_scope;
3900           got_scope = NULL_TREE;
3901         }
3902         ;
3903
3904 unoperator:
3905         { got_scope = TREE_PURPOSE (saved_scopes);
3906           got_object = TREE_VALUE (saved_scopes);
3907           looking_for_typename = TREE_LANG_FLAG_0 (saved_scopes);
3908           saved_scopes = TREE_CHAIN (saved_scopes);
3909         }
3910         ;
3911
3912 operator_name:
3913           operator '*' unoperator
3914                 { $$ = frob_opname (ansi_opname (MULT_EXPR)); }
3915         | operator '/' unoperator
3916                 { $$ = frob_opname (ansi_opname (TRUNC_DIV_EXPR)); }
3917         | operator '%' unoperator
3918                 { $$ = frob_opname (ansi_opname (TRUNC_MOD_EXPR)); }
3919         | operator '+' unoperator
3920                 { $$ = frob_opname (ansi_opname (PLUS_EXPR)); }
3921         | operator '-' unoperator
3922                 { $$ = frob_opname (ansi_opname (MINUS_EXPR)); }
3923         | operator '&' unoperator
3924                 { $$ = frob_opname (ansi_opname (BIT_AND_EXPR)); }
3925         | operator '|' unoperator
3926                 { $$ = frob_opname (ansi_opname (BIT_IOR_EXPR)); }
3927         | operator '^' unoperator
3928                 { $$ = frob_opname (ansi_opname (BIT_XOR_EXPR)); }
3929         | operator '~' unoperator
3930                 { $$ = frob_opname (ansi_opname (BIT_NOT_EXPR)); }
3931         | operator ',' unoperator
3932                 { $$ = frob_opname (ansi_opname (COMPOUND_EXPR)); }
3933         | operator ARITHCOMPARE unoperator
3934                 { $$ = frob_opname (ansi_opname ($2)); }
3935         | operator '<' unoperator
3936                 { $$ = frob_opname (ansi_opname (LT_EXPR)); }
3937         | operator '>' unoperator
3938                 { $$ = frob_opname (ansi_opname (GT_EXPR)); }
3939         | operator EQCOMPARE unoperator
3940                 { $$ = frob_opname (ansi_opname ($2)); }
3941         | operator ASSIGN unoperator
3942                 { $$ = frob_opname (ansi_assopname ($2)); }
3943         | operator '=' unoperator
3944                 { $$ = frob_opname (ansi_assopname (NOP_EXPR)); }
3945         | operator LSHIFT unoperator
3946                 { $$ = frob_opname (ansi_opname ($2)); }
3947         | operator RSHIFT unoperator
3948                 { $$ = frob_opname (ansi_opname ($2)); }
3949         | operator PLUSPLUS unoperator
3950                 { $$ = frob_opname (ansi_opname (POSTINCREMENT_EXPR)); }
3951         | operator MINUSMINUS unoperator
3952                 { $$ = frob_opname (ansi_opname (PREDECREMENT_EXPR)); }
3953         | operator ANDAND unoperator
3954                 { $$ = frob_opname (ansi_opname (TRUTH_ANDIF_EXPR)); }
3955         | operator OROR unoperator
3956                 { $$ = frob_opname (ansi_opname (TRUTH_ORIF_EXPR)); }
3957         | operator '!' unoperator
3958                 { $$ = frob_opname (ansi_opname (TRUTH_NOT_EXPR)); }
3959         | operator '?' ':' unoperator
3960                 { $$ = frob_opname (ansi_opname (COND_EXPR)); }
3961         | operator MIN_MAX unoperator
3962                 { $$ = frob_opname (ansi_opname ($2)); }
3963         | operator POINTSAT  unoperator %prec EMPTY
3964                 { $$ = frob_opname (ansi_opname (COMPONENT_REF)); }
3965         | operator POINTSAT_STAR  unoperator %prec EMPTY
3966                 { $$ = frob_opname (ansi_opname (MEMBER_REF)); }
3967         | operator LEFT_RIGHT unoperator
3968                 { $$ = frob_opname (ansi_opname (CALL_EXPR)); }
3969         | operator '[' ']' unoperator
3970                 { $$ = frob_opname (ansi_opname (ARRAY_REF)); }
3971         | operator NEW  unoperator %prec EMPTY
3972                 { $$ = frob_opname (ansi_opname (NEW_EXPR)); }
3973         | operator DELETE  unoperator %prec EMPTY
3974                 { $$ = frob_opname (ansi_opname (DELETE_EXPR)); }
3975         | operator NEW '[' ']' unoperator
3976                 { $$ = frob_opname (ansi_opname (VEC_NEW_EXPR)); }
3977         | operator DELETE '[' ']' unoperator
3978                 { $$ = frob_opname (ansi_opname (VEC_DELETE_EXPR)); }
3979         | operator type_specifier_seq conversion_declarator unoperator
3980                 { $$ = frob_opname (grokoptypename ($2.t, $3)); }
3981         | operator error unoperator
3982                 { $$ = frob_opname (ansi_opname (ERROR_MARK)); }
3983         ;
3984
3985 /* The forced readahead in here is because we might be at the end of a
3986    line, and lineno won't be bumped until yylex absorbs the first token
3987    on the next line.  */
3988 save_lineno:
3989                 { if (yychar == YYEMPTY)
3990                     yychar = YYLEX;
3991                   $$ = lineno; }
3992         ;
3993 %%
3994
3995 #ifdef SPEW_DEBUG
3996 const char *
3997 debug_yytranslate (value)
3998     int value;
3999 {
4000   return yytname[YYTRANSLATE (value)];
4001 }
4002 #endif
4003
4004 /* Free malloced parser stacks if necessary.  */
4005
4006 void
4007 free_parser_stacks ()
4008 {
4009   if (malloced_yyss)
4010     {
4011       free (malloced_yyss);
4012       free (malloced_yyvs);
4013     }
4014 }
4015
4016 /* Return the value corresponding to TOKEN in the global scope.  */
4017
4018 static tree
4019 parse_scoped_id (token)
4020      tree token;
4021 {
4022   tree id;
4023
4024   id = make_node (CPLUS_BINDING);
4025   if (!qualified_lookup_using_namespace (token, global_namespace, id, 0))
4026     id = NULL_TREE;
4027   else
4028     id = BINDING_VALUE (id);
4029   if (yychar == YYEMPTY)
4030     yychar = yylex();
4031
4032   return do_scoped_id (token, id);
4033 }
4034
4035 /* AGGR may be either a type node (like class_type_node) or a
4036    TREE_LIST whose TREE_PURPOSE is a list of attributes and whose
4037    TREE_VALUE is a type node.  Set *TAG_KIND and *ATTRIBUTES to
4038    represent the information encoded.  */
4039
4040 static void
4041 parse_split_aggr (tree aggr, enum tag_types *tag_kind, tree *attributes)
4042 {
4043   if (TREE_CODE (aggr) == TREE_LIST) 
4044     {
4045       *attributes = TREE_PURPOSE (aggr);
4046       aggr = TREE_VALUE (aggr);
4047     }
4048   else
4049     *attributes = NULL_TREE;
4050   *tag_kind = (enum tag_types) tree_low_cst (aggr, 1);
4051 }
4052
4053 /* Like xref_tag, except that the AGGR may be either a type node (like
4054    class_type_node) or a TREE_LIST whose TREE_PURPOSE is a list of
4055    attributes and whose TREE_VALUE is a type node.  */
4056
4057 static tree
4058 parse_xref_tag (tree aggr, tree name, int globalize)
4059 {
4060   tree attributes;
4061   enum tag_types tag_kind;
4062   parse_split_aggr (aggr, &tag_kind, &attributes);
4063   return xref_tag (tag_kind, name, attributes, globalize);
4064 }
4065
4066 /* Like handle_class_head, but AGGR may be as for parse_xref_tag.  */
4067
4068 static tree
4069 parse_handle_class_head (tree aggr, tree scope, tree id, 
4070                          int defn_p, int *new_type_p)
4071 {
4072   tree attributes;
4073   enum tag_types tag_kind;
4074   parse_split_aggr (aggr, &tag_kind, &attributes);
4075   return handle_class_head (tag_kind, scope, id, attributes, 
4076                             defn_p, new_type_p);
4077 }
4078
4079 /* Like do_decl_instantiation, but the declarator has not yet been
4080    parsed.  */
4081
4082 static void
4083 parse_decl_instantiation (tree declspecs, tree declarator, tree storage)
4084 {
4085   tree decl = grokdeclarator (declarator, declspecs, NORMAL, 0, NULL);
4086   do_decl_instantiation (decl, storage);
4087 }
4088
4089 /* Like begin_function_definition, but SPECS_ATTRS is a combined list
4090    containing both a decl-specifier-seq and attributes.  */
4091
4092 static int
4093 parse_begin_function_definition (tree specs_attrs, tree declarator)
4094 {
4095   tree specs;
4096   tree attrs;
4097   
4098   split_specs_attrs (specs_attrs, &specs, &attrs);
4099   return begin_function_definition (specs, attrs, declarator);
4100 }
4101
4102 #include "gt-cp-parse.h"