OSDN Git Service

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