OSDN Git Service

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