OSDN Git Service

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