OSDN Git Service

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