OSDN Git Service

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