OSDN Git Service

Remove CYGNUS LOCAL tags.
[pf3gnuchains/gcc-fork.git] / gcc / c-parse.in
1 /* YACC parser for C syntax and for Objective C.  -*-c-*-
2    Copyright (C) 1987, 88, 89, 92-5, 1996 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING.  If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.  */
20
21 /* This file defines the grammar of C and that of Objective C.
22    ifobjc ... end ifobjc  conditionals contain code for Objective C only.
23    ifc ... end ifc  conditionals contain code for C only.
24    Sed commands in Makefile.in are used to convert this file into
25    c-parse.y and into objc-parse.y.  */
26
27 /* To whomever it may concern: I have heard that such a thing was once
28    written by AT&T, but I have never seen it.  */
29
30 ifobjc
31 %expect 52
32 end ifobjc
33 ifc
34 %expect 34
35
36 /* These are the 23 conflicts you should get in parse.output;
37    the state numbers may vary if minor changes in the grammar are made.
38
39 State 42 contains 1 shift/reduce conflict.  (Two ways to parse ATTRIBUTE.)
40 State 44 contains 1 shift/reduce conflict.  (Two ways to recover from error.)
41 State 103 contains 1 shift/reduce conflict.  (Two ways to recover from error.)
42 State 110 contains 1 shift/reduce conflict.  (Two ways to parse ATTRIBUTE.)
43 State 111 contains 1 shift/reduce conflict.  (Two ways to recover from error.)
44 State 115 contains 1 shift/reduce conflict.  (Two ways to recover from error.)
45 State 132 contains 1 shift/reduce conflict.  (See comment at component_decl.)
46 State 180 contains 1 shift/reduce conflict.  (Two ways to parse ATTRIBUTE.)
47 State 194 contains 2 shift/reduce conflict.  (Four ways to parse this.)
48 State 202 contains 1 shift/reduce conflict.  (Two ways to recover from error.)
49 State 214 contains 1 shift/reduce conflict.  (Two ways to recover from error.)
50 State 220 contains 1 shift/reduce conflict.  (Two ways to recover from error.)
51 State 304 contains 2 shift/reduce conflicts.  (Four ways to parse this.)
52 State 335 contains 2 shift/reduce conflicts.  (Four ways to parse this.)
53 State 347 contains 1 shift/reduce conflict.  (Two ways to parse ATTRIBUTES.)
54 State 352 contains 1 shift/reduce conflict.  (Two ways to parse ATTRIBUTES.)
55 State 383 contains 2 shift/reduce conflicts.  (Four ways to parse this.)
56 State 434 contains 2 shift/reduce conflicts.  (Four ways to parse this.)  */
57
58 end ifc
59
60 %{
61 #include <stdio.h>
62 #include <errno.h>
63 #include <setjmp.h>
64
65 #include "config.h"
66 #include "tree.h"
67 #include "input.h"
68 #include "c-lex.h"
69 #include "c-tree.h"
70 #include "flags.h"
71
72 #ifdef MULTIBYTE_CHARS
73 #include <stdlib.h>
74 #include <locale.h>
75 #endif
76
77 ifobjc
78 #include "objc-act.h"
79 end ifobjc
80
81 /* Since parsers are distinct for each language, put the language string
82    definition here.  */
83 ifobjc
84 char *language_string = "GNU Obj-C";
85 end ifobjc
86 ifc
87 char *language_string = "GNU C";
88 end ifc
89
90 #ifndef errno
91 extern int errno;
92 #endif
93
94 void yyerror ();
95
96 /* Like YYERROR but do call yyerror.  */
97 #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
98
99 /* Cause the `yydebug' variable to be defined.  */
100 #define YYDEBUG 1
101 %}
102
103 %start program
104
105 %union {long itype; tree ttype; enum tree_code code;
106         char *filename; int lineno; int ends_in_label; }
107
108 /* All identifiers that are not reserved words
109    and are not declared typedefs in the current block */
110 %token IDENTIFIER
111
112 /* All identifiers that are declared typedefs in the current block.
113    In some contexts, they are treated just like IDENTIFIER,
114    but they can also serve as typespecs in declarations.  */
115 %token TYPENAME
116
117 /* Reserved words that specify storage class.
118    yylval contains an IDENTIFIER_NODE which indicates which one.  */
119 %token SCSPEC
120
121 /* Reserved words that specify type.
122    yylval contains an IDENTIFIER_NODE which indicates which one.  */
123 %token TYPESPEC
124
125 /* Reserved words that qualify type: "const" or "volatile".
126    yylval contains an IDENTIFIER_NODE which indicates which one.  */
127 %token TYPE_QUAL
128
129 /* Character or numeric constants.
130    yylval is the node for the constant.  */
131 %token CONSTANT
132
133 /* String constants in raw form.
134    yylval is a STRING_CST node.  */
135 %token STRING
136
137 /* "...", used for functions with variable arglists.  */
138 %token ELLIPSIS
139
140 /* the reserved words */
141 /* SCO include files test "ASM", so use something else. */
142 %token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
143 %token BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF
144 %token ATTRIBUTE EXTENSION LABEL
145 %token REALPART IMAGPART
146
147 /* Add precedence rules to solve dangling else s/r conflict */
148 %nonassoc IF
149 %nonassoc ELSE
150
151 /* Define the operator tokens and their precedences.
152    The value is an integer because, if used, it is the tree code
153    to use in the expression made from the operator.  */
154
155 %right <code> ASSIGN '='
156 %right <code> '?' ':'
157 %left <code> OROR
158 %left <code> ANDAND
159 %left <code> '|'
160 %left <code> '^'
161 %left <code> '&'
162 %left <code> EQCOMPARE
163 %left <code> ARITHCOMPARE
164 %left <code> LSHIFT RSHIFT
165 %left <code> '+' '-'
166 %left <code> '*' '/' '%'
167 %right <code> UNARY PLUSPLUS MINUSMINUS
168 %left HYPERUNARY
169 %left <code> POINTSAT '.' '(' '['
170
171 /* The Objective-C keywords.  These are included in C and in
172    Objective C, so that the token codes are the same in both.  */
173 %token INTERFACE IMPLEMENTATION END SELECTOR DEFS ENCODE
174 %token CLASSNAME PUBLIC PRIVATE PROTECTED PROTOCOL OBJECTNAME CLASS ALIAS
175
176 /* Objective-C string constants in raw form.
177    yylval is an OBJC_STRING_CST node.  */
178 %token OBJC_STRING
179
180
181 %type <code> unop
182
183 %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist
184 %type <ttype> expr_no_commas cast_expr unary_expr primary string STRING
185 %type <ttype> typed_declspecs reserved_declspecs
186 %type <ttype> typed_typespecs reserved_typespecquals
187 %type <ttype> declmods typespec typespecqual_reserved
188 %type <ttype> SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual
189 %type <ttype> initdecls notype_initdecls initdcl notype_initdcl
190 %type <ttype> init maybeasm
191 %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
192 %type <ttype> maybe_attribute attributes attribute attribute_list attrib
193 %type <ttype> any_word
194
195 %type <ttype> compstmt
196
197 %type <ttype> declarator
198 %type <ttype> notype_declarator after_type_declarator
199 %type <ttype> parm_declarator
200
201 %type <ttype> structsp component_decl_list component_decl_list2
202 %type <ttype> component_decl components component_declarator
203 %type <ttype> enumlist enumerator
204 %type <ttype> typename absdcl absdcl1 type_quals
205 %type <ttype> xexpr parms parm identifiers
206
207 %type <ttype> parmlist parmlist_1 parmlist_2
208 %type <ttype> parmlist_or_identifiers parmlist_or_identifiers_1
209 %type <ttype> identifiers_or_typenames
210
211 %type <itype> setspecs
212
213 %type <ends_in_label> lineno_stmt_or_label lineno_stmt_or_labels stmt_or_label
214
215 %type <filename> save_filename
216 %type <lineno> save_lineno
217 \f
218 ifobjc
219 /* the Objective-C nonterminals */
220
221 %type <ttype> ivar_decl_list ivar_decls ivar_decl ivars ivar_declarator
222 %type <ttype> methoddecl unaryselector keywordselector selector
223 %type <ttype> keyworddecl receiver objcmessageexpr messageargs
224 %type <ttype> keywordexpr keywordarglist keywordarg
225 %type <ttype> myparms myparm optparmlist reservedwords objcselectorexpr
226 %type <ttype> selectorarg keywordnamelist keywordname objcencodeexpr
227 %type <ttype> objc_string non_empty_protocolrefs protocolrefs identifier_list objcprotocolexpr
228
229 %type <ttype> CLASSNAME OBJC_STRING OBJECTNAME
230 end ifobjc
231 \f
232 %{
233 /* Number of statements (loosely speaking) seen so far.  */
234 static int stmt_count;
235
236 /* Input file and line number of the end of the body of last simple_if;
237    used by the stmt-rule immediately after simple_if returns.  */
238 static char *if_stmt_file;
239 static int if_stmt_line;
240
241 /* List of types and structure classes of the current declaration.  */
242 static tree current_declspecs;
243 static tree prefix_attributes = NULL_TREE;
244
245 /* Stack of saved values of current_declspecs and prefix_attributes.  */
246 static tree declspec_stack;
247
248 /* 1 if we explained undeclared var errors.  */
249 static int undeclared_variable_notice;
250
251 ifobjc
252 /* Objective-C specific information */
253
254 tree objc_interface_context;
255 tree objc_implementation_context;
256 tree objc_method_context;
257 tree objc_ivar_chain;
258 tree objc_ivar_context;
259 enum tree_code objc_inherit_code;
260 int objc_receiver_context;
261 int objc_public_flag;
262
263 end ifobjc
264
265 /* Tell yyparse how to print a token's value, if yydebug is set.  */
266
267 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
268 extern void yyprint ();
269 %}
270 \f
271 %%
272 program: /* empty */
273                 { if (pedantic)
274                     pedwarn ("ANSI C forbids an empty source file");
275                   finish_file ();
276                 }
277         | extdefs
278                 {
279                   /* In case there were missing closebraces,
280                      get us back to the global binding level.  */
281                   while (! global_bindings_p ())
282                     poplevel (0, 0, 0);
283                   finish_file ();
284                 }
285         ;
286
287 /* the reason for the strange actions in this rule
288  is so that notype_initdecls when reached via datadef
289  can find a valid list of type and sc specs in $0. */
290
291 extdefs:
292         {$<ttype>$ = NULL_TREE; } extdef
293         | extdefs {$<ttype>$ = NULL_TREE; } extdef
294         ;
295
296 extdef:
297         fndef
298         | datadef
299 ifobjc
300         | objcdef
301 end ifobjc
302         | ASM_KEYWORD '(' expr ')' ';'
303                 { STRIP_NOPS ($3);
304                   if ((TREE_CODE ($3) == ADDR_EXPR
305                        && TREE_CODE (TREE_OPERAND ($3, 0)) == STRING_CST)
306                       || TREE_CODE ($3) == STRING_CST)
307                     assemble_asm ($3);
308                   else
309                     error ("argument of `asm' is not a constant string"); }
310         ;
311
312 datadef:
313           setspecs notype_initdecls ';'
314                 { if (pedantic)
315                     error ("ANSI C forbids data definition with no type or storage class");
316                   else if (!flag_traditional)
317                     warning ("data definition has no type or storage class"); 
318
319                   current_declspecs = TREE_VALUE (declspec_stack);
320                   prefix_attributes = TREE_PURPOSE (declspec_stack);
321                   declspec_stack = TREE_CHAIN (declspec_stack);
322                   resume_momentary ($1); }
323         | declmods setspecs notype_initdecls ';'
324                 { current_declspecs = TREE_VALUE (declspec_stack);
325                   prefix_attributes = TREE_PURPOSE (declspec_stack);
326                   declspec_stack = TREE_CHAIN (declspec_stack);
327                   resume_momentary ($2); }
328         | typed_declspecs setspecs initdecls ';'
329                 { current_declspecs = TREE_VALUE (declspec_stack);
330                   prefix_attributes = TREE_PURPOSE (declspec_stack);
331                   declspec_stack = TREE_CHAIN (declspec_stack);
332                   resume_momentary ($2);  }
333         | declmods ';'
334           { pedwarn ("empty declaration"); }
335         | typed_declspecs ';'
336           { shadow_tag ($1); }
337         | error ';'
338         | error '}'
339         | ';'
340                 { if (pedantic)
341                     pedwarn ("ANSI C does not allow extra `;' outside of a function"); }
342         ;
343 \f
344 fndef:
345           typed_declspecs setspecs declarator
346                 { if (! start_function ($1, $3, prefix_attributes,
347                                         NULL_TREE, 0))
348                     YYERROR1;
349                   reinit_parse_for_function (); }
350           xdecls
351                 { store_parm_decls (); }
352           compstmt_or_error
353                 { finish_function (0); 
354                   current_declspecs = TREE_VALUE (declspec_stack);
355                   prefix_attributes = TREE_PURPOSE (declspec_stack);
356                   declspec_stack = TREE_CHAIN (declspec_stack);
357                   resume_momentary ($2); }
358         | typed_declspecs setspecs declarator error
359                 { current_declspecs = TREE_VALUE (declspec_stack);
360                   prefix_attributes = TREE_PURPOSE (declspec_stack);
361                   declspec_stack = TREE_CHAIN (declspec_stack);
362                   resume_momentary ($2); }
363         | declmods setspecs notype_declarator
364                 { if (! start_function ($1, $3, prefix_attributes,
365                                         NULL_TREE, 0))
366                     YYERROR1;
367                   reinit_parse_for_function (); }
368           xdecls
369                 { store_parm_decls (); }
370           compstmt_or_error
371                 { finish_function (0); 
372                   current_declspecs = TREE_VALUE (declspec_stack);
373                   prefix_attributes = TREE_PURPOSE (declspec_stack);
374                   declspec_stack = TREE_CHAIN (declspec_stack);
375                   resume_momentary ($2); }
376         | declmods setspecs notype_declarator error
377                 { current_declspecs = TREE_VALUE (declspec_stack);
378                   prefix_attributes = TREE_PURPOSE (declspec_stack);
379                   declspec_stack = TREE_CHAIN (declspec_stack);
380                   resume_momentary ($2); }
381         | setspecs notype_declarator
382                 { if (! start_function (NULL_TREE, $2,
383                                         prefix_attributes, NULL_TREE, 0))
384                     YYERROR1;
385                   reinit_parse_for_function (); }
386           xdecls
387                 { store_parm_decls (); }
388           compstmt_or_error
389                 { finish_function (0); 
390                   current_declspecs = TREE_VALUE (declspec_stack);
391                   prefix_attributes = TREE_PURPOSE (declspec_stack);
392                   declspec_stack = TREE_CHAIN (declspec_stack);
393                   resume_momentary ($1); }
394         | setspecs notype_declarator error
395                 { current_declspecs = TREE_VALUE (declspec_stack);
396                   prefix_attributes = TREE_PURPOSE (declspec_stack);
397                   declspec_stack = TREE_CHAIN (declspec_stack);
398                   resume_momentary ($1); }
399         ;
400
401 identifier:
402         IDENTIFIER
403         | TYPENAME
404 ifobjc
405         | OBJECTNAME
406         | CLASSNAME
407 end ifobjc
408         ;
409
410 unop:     '&'
411                 { $$ = ADDR_EXPR; }
412         | '-'
413                 { $$ = NEGATE_EXPR; }
414         | '+'
415                 { $$ = CONVERT_EXPR; }
416         | PLUSPLUS
417                 { $$ = PREINCREMENT_EXPR; }
418         | MINUSMINUS
419                 { $$ = PREDECREMENT_EXPR; }
420         | '~'
421                 { $$ = BIT_NOT_EXPR; }
422         | '!'
423                 { $$ = TRUTH_NOT_EXPR; }
424         ;
425
426 expr:   nonnull_exprlist
427                 { $$ = build_compound_expr ($1); }
428         ;
429
430 exprlist:
431           /* empty */
432                 { $$ = NULL_TREE; }
433         | nonnull_exprlist
434         ;
435
436 nonnull_exprlist:
437         expr_no_commas
438                 { $$ = build_tree_list (NULL_TREE, $1); }
439         | nonnull_exprlist ',' expr_no_commas
440                 { chainon ($1, build_tree_list (NULL_TREE, $3)); }
441         ;
442
443 unary_expr:
444         primary
445         | '*' cast_expr   %prec UNARY
446                 { $$ = build_indirect_ref ($2, "unary *"); }
447         /* __extension__ turns off -pedantic for following primary.  */
448         | EXTENSION
449                 { $<itype>1 = pedantic;
450                   pedantic = 0; }
451           cast_expr       %prec UNARY
452                 { $$ = $3;
453                   pedantic = $<itype>1; }
454         | unop cast_expr  %prec UNARY
455                 { $$ = build_unary_op ($1, $2, 0);
456                   overflow_warning ($$); }
457         /* Refer to the address of a label as a pointer.  */
458         | ANDAND identifier
459                 { tree label = lookup_label ($2);
460                   if (pedantic)
461                     pedwarn ("ANSI C forbids `&&'");
462                   if (label == 0)
463                     $$ = null_pointer_node;
464                   else
465                     {
466                       TREE_USED (label) = 1;
467                       $$ = build1 (ADDR_EXPR, ptr_type_node, label);
468                       TREE_CONSTANT ($$) = 1;
469                     }
470                 }
471 /* This seems to be impossible on some machines, so let's turn it off.
472    You can use __builtin_next_arg to find the anonymous stack args.
473         | '&' ELLIPSIS
474                 { tree types = TYPE_ARG_TYPES (TREE_TYPE (current_function_decl));
475                   $$ = error_mark_node;
476                   if (TREE_VALUE (tree_last (types)) == void_type_node)
477                     error ("`&...' used in function with fixed number of arguments");
478                   else
479                     {
480                       if (pedantic)
481                         pedwarn ("ANSI C forbids `&...'");
482                       $$ = tree_last (DECL_ARGUMENTS (current_function_decl));
483                       $$ = build_unary_op (ADDR_EXPR, $$, 0);
484                     } }
485 */
486         | SIZEOF unary_expr  %prec UNARY
487                 { if (TREE_CODE ($2) == COMPONENT_REF
488                       && DECL_BIT_FIELD (TREE_OPERAND ($2, 1)))
489                     error ("`sizeof' applied to a bit-field");
490                   $$ = c_sizeof (TREE_TYPE ($2)); }
491         | SIZEOF '(' typename ')'  %prec HYPERUNARY
492                 { $$ = c_sizeof (groktypename ($3)); }
493         | ALIGNOF unary_expr  %prec UNARY
494                 { $$ = c_alignof_expr ($2); }
495         | ALIGNOF '(' typename ')'  %prec HYPERUNARY
496                 { $$ = c_alignof (groktypename ($3)); }
497         | REALPART cast_expr %prec UNARY
498                 { $$ = build_unary_op (REALPART_EXPR, $2, 0); }
499         | IMAGPART cast_expr %prec UNARY
500                 { $$ = build_unary_op (IMAGPART_EXPR, $2, 0); }
501         ;
502
503 cast_expr:
504         unary_expr
505         | '(' typename ')' cast_expr  %prec UNARY
506                 { tree type = groktypename ($2);
507                   $$ = build_c_cast (type, $4); }
508         | '(' typename ')' '{' 
509                 { start_init (NULL_TREE, NULL, 0);
510                   $2 = groktypename ($2);
511                   really_start_incremental_init ($2); }
512           initlist_maybe_comma '}'  %prec UNARY
513                 { char *name;
514                   tree result = pop_init_level (0);
515                   tree type = $2;
516                   finish_init ();
517
518                   if (pedantic)
519                     pedwarn ("ANSI C forbids constructor expressions");
520                   if (TYPE_NAME (type) != 0)
521                     {
522                       if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
523                         name = IDENTIFIER_POINTER (TYPE_NAME (type));
524                       else
525                         name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
526                     }
527                   else
528                     name = "";
529                   $$ = result;
530                   if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
531                     {
532                       int failure = complete_array_type (type, $$, 1);
533                       if (failure)
534                         abort ();
535                     }
536                 }
537         ;
538
539 expr_no_commas:
540           cast_expr
541         | expr_no_commas '+' expr_no_commas
542                 { $$ = parser_build_binary_op ($2, $1, $3); }
543         | expr_no_commas '-' expr_no_commas
544                 { $$ = parser_build_binary_op ($2, $1, $3); }
545         | expr_no_commas '*' expr_no_commas
546                 { $$ = parser_build_binary_op ($2, $1, $3); }
547         | expr_no_commas '/' expr_no_commas
548                 { $$ = parser_build_binary_op ($2, $1, $3); }
549         | expr_no_commas '%' expr_no_commas
550                 { $$ = parser_build_binary_op ($2, $1, $3); }
551         | expr_no_commas LSHIFT expr_no_commas
552                 { $$ = parser_build_binary_op ($2, $1, $3); }
553         | expr_no_commas RSHIFT expr_no_commas
554                 { $$ = parser_build_binary_op ($2, $1, $3); }
555         | expr_no_commas ARITHCOMPARE expr_no_commas
556                 { $$ = parser_build_binary_op ($2, $1, $3); }
557         | expr_no_commas EQCOMPARE expr_no_commas
558                 { $$ = parser_build_binary_op ($2, $1, $3); }
559         | expr_no_commas '&' expr_no_commas
560                 { $$ = parser_build_binary_op ($2, $1, $3); }
561         | expr_no_commas '|' expr_no_commas
562                 { $$ = parser_build_binary_op ($2, $1, $3); }
563         | expr_no_commas '^' expr_no_commas
564                 { $$ = parser_build_binary_op ($2, $1, $3); }
565         | expr_no_commas ANDAND expr_no_commas
566                 { $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $3); }
567         | expr_no_commas OROR expr_no_commas
568                 { $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $3); }
569         | expr_no_commas '?' xexpr ':' expr_no_commas
570                 { $$ = build_conditional_expr ($1, $3, $5); }
571         | expr_no_commas '=' expr_no_commas
572                 { $$ = build_modify_expr ($1, NOP_EXPR, $3);
573                   C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); }
574         | expr_no_commas ASSIGN expr_no_commas
575                 { $$ = build_modify_expr ($1, $2, $3);
576                   /* This inhibits warnings in truthvalue_conversion.  */
577                   C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK); }
578         ;
579
580 primary:
581         IDENTIFIER
582                 {
583                   $$ = lastiddecl;
584                   if (!$$ || $$ == error_mark_node)
585                     {
586                       if (yychar == YYEMPTY)
587                         yychar = YYLEX;
588                       if (yychar == '(')
589                         {
590 ifobjc
591                           tree decl;
592
593                           if (objc_receiver_context
594                               && ! (objc_receiver_context
595                                     && strcmp (IDENTIFIER_POINTER ($1), "super")))
596                             /* we have a message to super */
597                             $$ = get_super_receiver ();
598                           else if (objc_method_context
599                                    && (decl = is_ivar (objc_ivar_chain, $1)))
600                             {
601                               if (is_private (decl))
602                                 $$ = error_mark_node;
603                               else
604                                 $$ = build_ivar_reference ($1);
605                             }
606                           else
607 end ifobjc
608                             {
609                               /* Ordinary implicit function declaration.  */
610                               $$ = implicitly_declare ($1);
611                               assemble_external ($$);
612                               TREE_USED ($$) = 1;
613                             }
614                         }
615                       else if (current_function_decl == 0)
616                         {
617                           error ("`%s' undeclared here (not in a function)",
618                                  IDENTIFIER_POINTER ($1));
619                           $$ = error_mark_node;
620                         }
621                       else
622                         {
623 ifobjc
624                           tree decl;
625
626                           if (objc_receiver_context
627                               && ! strcmp (IDENTIFIER_POINTER ($1), "super"))
628                             /* we have a message to super */
629                             $$ = get_super_receiver ();
630                           else if (objc_method_context
631                                    && (decl = is_ivar (objc_ivar_chain, $1)))
632                             {
633                               if (is_private (decl))
634                                 $$ = error_mark_node;
635                               else
636                                 $$ = build_ivar_reference ($1);
637                             }
638                           else
639 end ifobjc
640                             {
641                               if (IDENTIFIER_GLOBAL_VALUE ($1) != error_mark_node
642                                   || IDENTIFIER_ERROR_LOCUS ($1) != current_function_decl)
643                                 {
644                                   error ("`%s' undeclared (first use this function)",
645                                          IDENTIFIER_POINTER ($1));
646
647                                   if (! undeclared_variable_notice)
648                                     {
649                                       error ("(Each undeclared identifier is reported only once");
650                                       error ("for each function it appears in.)");
651                                       undeclared_variable_notice = 1;
652                                     }
653                                 }
654                               $$ = error_mark_node;
655                               /* Prevent repeated error messages.  */
656                               IDENTIFIER_GLOBAL_VALUE ($1) = error_mark_node;
657                               IDENTIFIER_ERROR_LOCUS ($1) = current_function_decl;
658                             }
659                         }
660                     }
661                   else if (TREE_TYPE ($$) == error_mark_node)
662                     $$ = error_mark_node;
663                   else if (C_DECL_ANTICIPATED ($$))
664                     {
665                       /* The first time we see a build-in function used,
666                          if it has not been declared.  */
667                       C_DECL_ANTICIPATED ($$) = 0;
668                       if (yychar == YYEMPTY)
669                         yychar = YYLEX;
670                       if (yychar == '(')
671                         {
672                           /* Omit the implicit declaration we
673                              would ordinarily do, so we don't lose
674                              the actual built in type.
675                              But print a diagnostic for the mismatch.  */
676 ifobjc
677                           if (objc_method_context
678                               && is_ivar (objc_ivar_chain, $1))
679                             error ("Instance variable `%s' implicitly declared as function",
680                                    IDENTIFIER_POINTER (DECL_NAME ($$)));
681                           else
682 end ifobjc
683                             if (TREE_CODE ($$) != FUNCTION_DECL)
684                               error ("`%s' implicitly declared as function",
685                                      IDENTIFIER_POINTER (DECL_NAME ($$)));
686                           else if ((TYPE_MODE (TREE_TYPE (TREE_TYPE ($$)))
687                                     != TYPE_MODE (integer_type_node))
688                                    && (TREE_TYPE (TREE_TYPE ($$))
689                                        != void_type_node))
690                             pedwarn ("type mismatch in implicit declaration for built-in function `%s'",
691                                      IDENTIFIER_POINTER (DECL_NAME ($$)));
692                           /* If it really returns void, change that to int.  */
693                           if (TREE_TYPE (TREE_TYPE ($$)) == void_type_node)
694                             TREE_TYPE ($$)
695                               = build_function_type (integer_type_node,
696                                                      TYPE_ARG_TYPES (TREE_TYPE ($$)));
697                         }
698                       else
699                         pedwarn ("built-in function `%s' used without declaration",
700                                  IDENTIFIER_POINTER (DECL_NAME ($$)));
701
702                       /* Do what we would ordinarily do when a fn is used.  */
703                       assemble_external ($$);
704                       TREE_USED ($$) = 1;
705                     }
706                   else
707                     {
708                       assemble_external ($$);
709                       TREE_USED ($$) = 1;
710 ifobjc
711                       /* we have a definition - still check if iVariable */
712
713                       if (!objc_receiver_context
714                           || (objc_receiver_context
715                               && strcmp (IDENTIFIER_POINTER ($1), "super")))
716                         {
717                           tree decl;
718
719                           if (objc_method_context
720                               && (decl = is_ivar (objc_ivar_chain, $1)))
721                             {
722                               if (IDENTIFIER_LOCAL_VALUE ($1))
723                                 warning ("local declaration of `%s' hides instance variable",
724                                          IDENTIFIER_POINTER ($1));
725                               else
726                                 {
727                                   if (is_private (decl))
728                                     $$ = error_mark_node;
729                                   else
730                                     $$ = build_ivar_reference ($1);
731                                 }
732                             }
733                         }
734                       else /* we have a message to super */
735                         $$ = get_super_receiver ();
736 end ifobjc
737                     }
738
739                   if (TREE_CODE ($$) == CONST_DECL)
740                     {
741                       $$ = DECL_INITIAL ($$);
742                       /* This is to prevent an enum whose value is 0
743                          from being considered a null pointer constant.  */
744                       $$ = build1 (NOP_EXPR, TREE_TYPE ($$), $$);
745                       TREE_CONSTANT ($$) = 1;
746                     }
747                 }
748         | CONSTANT
749         | string
750                 { $$ = combine_strings ($1); }
751         | '(' expr ')'
752                 { char class = TREE_CODE_CLASS (TREE_CODE ($2));
753                   if (class == 'e' || class == '1'
754                       || class == '2' || class == '<')
755                     C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK);
756                   $$ = $2; }
757         | '(' error ')'
758                 { $$ = error_mark_node; }
759         | '('
760                 { if (current_function_decl == 0)
761                     {
762                       error ("braced-group within expression allowed only inside a function");
763                       YYERROR;
764                     }
765                   /* We must force a BLOCK for this level
766                      so that, if it is not expanded later,
767                      there is a way to turn off the entire subtree of blocks
768                      that are contained in it.  */
769                   keep_next_level ();
770                   push_iterator_stack ();
771                   push_label_level ();
772                   $<ttype>$ = expand_start_stmt_expr (); }
773           compstmt ')'
774                 { tree rtl_exp;
775                   if (pedantic)
776                     pedwarn ("ANSI C forbids braced-groups within expressions");
777                   pop_iterator_stack ();
778                   pop_label_level ();
779                   rtl_exp = expand_end_stmt_expr ($<ttype>2);
780                   /* The statements have side effects, so the group does.  */
781                   TREE_SIDE_EFFECTS (rtl_exp) = 1;
782
783                   if (TREE_CODE ($3) == BLOCK)
784                     {
785                       /* Make a BIND_EXPR for the BLOCK already made.  */
786                       $$ = build (BIND_EXPR, TREE_TYPE (rtl_exp),
787                                   NULL_TREE, rtl_exp, $3);
788                       /* Remove the block from the tree at this point.
789                          It gets put back at the proper place
790                          when the BIND_EXPR is expanded.  */
791                       delete_block ($3);
792                     }
793                   else
794                     $$ = $3;
795                 }
796         | primary '(' exprlist ')'   %prec '.'
797                 { $$ = build_function_call ($1, $3); }
798         | primary '[' expr ']'   %prec '.'
799                 { $$ = build_array_ref ($1, $3); }
800         | primary '.' identifier
801                 {
802 ifobjc
803                   if (doing_objc_thang)
804                     {
805                       if (is_public ($1, $3))
806                         $$ = build_component_ref ($1, $3);
807                       else
808                         $$ = error_mark_node;
809                     }
810                   else
811 end ifobjc
812                     $$ = build_component_ref ($1, $3);
813                 }
814         | primary POINTSAT identifier
815                 {
816                   tree expr = build_indirect_ref ($1, "->");
817
818 ifobjc
819                   if (doing_objc_thang)
820                     {
821                       if (is_public (expr, $3))
822                         $$ = build_component_ref (expr, $3);
823                       else
824                         $$ = error_mark_node;
825                     }
826                   else
827 end ifobjc
828                     $$ = build_component_ref (expr, $3);
829                 }
830         | primary PLUSPLUS
831                 { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
832         | primary MINUSMINUS
833                 { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
834 ifobjc
835         | objcmessageexpr
836                 { $$ = build_message_expr ($1); }
837         | objcselectorexpr
838                 { $$ = build_selector_expr ($1); }
839         | objcprotocolexpr
840                 { $$ = build_protocol_expr ($1); }
841         | objcencodeexpr
842                 { $$ = build_encode_expr ($1); }
843         | objc_string
844                 { $$ = build_objc_string_object ($1); }
845 end ifobjc
846         ;
847
848 /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it.  */
849 string:
850           STRING
851         | string STRING
852                 { $$ = chainon ($1, $2); }
853         ;
854
855 ifobjc
856 /* Produces an OBJC_STRING_CST with perhaps more OBJC_STRING_CSTs chained
857    onto it.  */
858 objc_string:
859           OBJC_STRING
860         | objc_string OBJC_STRING
861                 { $$ = chainon ($1, $2); }
862         ;
863 end ifobjc
864
865 xdecls:
866         /* empty */
867         | datadecls
868         | datadecls ELLIPSIS
869                 /* ... is used here to indicate a varargs function.  */
870                 { c_mark_varargs ();
871                   if (pedantic)
872                     pedwarn ("ANSI C does not permit use of `varargs.h'"); }
873         ;
874
875 /* The following are analogous to lineno_decl, decls and decl
876    except that they do not allow nested functions.
877    They are used for old-style parm decls.  */
878 lineno_datadecl:
879           save_filename save_lineno datadecl
880                 { }
881         ;
882
883 datadecls:
884         lineno_datadecl
885         | errstmt
886         | datadecls lineno_datadecl
887         | lineno_datadecl errstmt
888         ;
889
890 datadecl:
891         typed_declspecs setspecs initdecls ';'
892                 { current_declspecs = TREE_VALUE (declspec_stack);
893                   prefix_attributes = TREE_PURPOSE (declspec_stack);
894                   declspec_stack = TREE_CHAIN (declspec_stack);
895                   resume_momentary ($2); }
896         | declmods setspecs notype_initdecls ';'
897                 { current_declspecs = TREE_VALUE (declspec_stack);      
898                   prefix_attributes = TREE_PURPOSE (declspec_stack);
899                   declspec_stack = TREE_CHAIN (declspec_stack);
900                   resume_momentary ($2); }
901         | typed_declspecs ';'
902                 { shadow_tag_warned ($1, 1);
903                   pedwarn ("empty declaration"); }
904         | declmods ';'
905                 { pedwarn ("empty declaration"); }
906         ;
907
908 /* This combination which saves a lineno before a decl
909    is the normal thing to use, rather than decl itself.
910    This is to avoid shift/reduce conflicts in contexts
911    where statement labels are allowed.  */
912 lineno_decl:
913           save_filename save_lineno decl
914                 { }
915         ;
916
917 decls:
918         lineno_decl
919         | errstmt
920         | decls lineno_decl
921         | lineno_decl errstmt
922         ;
923
924 /* records the type and storage class specs to use for processing
925    the declarators that follow.
926    Maintains a stack of outer-level values of current_declspecs,
927    for the sake of parm declarations nested in function declarators.  */
928 setspecs: /* empty */
929                 { $$ = suspend_momentary ();
930                   pending_xref_error ();
931                   declspec_stack = tree_cons (prefix_attributes,
932                                               current_declspecs,
933                                               declspec_stack);
934                   current_declspecs = $<ttype>0; 
935                   prefix_attributes = NULL_TREE; }
936         ;
937
938 setattrs: /* empty */
939                 { prefix_attributes = chainon (prefix_attributes, $<ttype>0); }
940         ;
941
942 decl:
943         typed_declspecs setspecs initdecls ';'
944                 { current_declspecs = TREE_VALUE (declspec_stack);
945                   prefix_attributes = TREE_PURPOSE (declspec_stack);
946                   declspec_stack = TREE_CHAIN (declspec_stack);
947                   resume_momentary ($2); }
948         | declmods setspecs notype_initdecls ';'
949                 { current_declspecs = TREE_VALUE (declspec_stack);
950                   prefix_attributes = TREE_PURPOSE (declspec_stack);
951                   declspec_stack = TREE_CHAIN (declspec_stack);
952                   resume_momentary ($2); }
953         | typed_declspecs setspecs nested_function
954                 { current_declspecs = TREE_VALUE (declspec_stack);
955                   prefix_attributes = TREE_PURPOSE (declspec_stack);
956                   declspec_stack = TREE_CHAIN (declspec_stack);
957                   resume_momentary ($2); }
958         | declmods setspecs notype_nested_function
959                 { current_declspecs = TREE_VALUE (declspec_stack);
960                   prefix_attributes = TREE_PURPOSE (declspec_stack);
961                   declspec_stack = TREE_CHAIN (declspec_stack);
962                   resume_momentary ($2); }
963         | typed_declspecs ';'
964                 { shadow_tag ($1); }
965         | declmods ';'
966                 { pedwarn ("empty declaration"); }
967         ;
968
969 /* Declspecs which contain at least one type specifier or typedef name.
970    (Just `const' or `volatile' is not enough.)
971    A typedef'd name following these is taken as a name to be declared.  */
972
973 typed_declspecs:
974           typespec reserved_declspecs
975                 { $$ = tree_cons (NULL_TREE, $1, $2); }
976         | declmods typespec reserved_declspecs
977                 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
978         ;
979
980 reserved_declspecs:  /* empty */
981                 { $$ = NULL_TREE; }
982         | reserved_declspecs typespecqual_reserved
983                 { $$ = tree_cons (NULL_TREE, $2, $1); }
984         | reserved_declspecs SCSPEC
985                 { if (extra_warnings)
986                     warning ("`%s' is not at beginning of declaration",
987                              IDENTIFIER_POINTER ($2));
988                   $$ = tree_cons (NULL_TREE, $2, $1); }
989         ;
990
991 /* List of just storage classes and type modifiers.
992    A declaration can start with just this, but then it cannot be used
993    to redeclare a typedef-name.  */
994
995 declmods:
996           TYPE_QUAL
997                 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
998                   TREE_STATIC ($$) = 1; }
999         | SCSPEC
1000                 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1001         | declmods TYPE_QUAL
1002                 { $$ = tree_cons (NULL_TREE, $2, $1);
1003                   TREE_STATIC ($$) = 1; }
1004         | declmods SCSPEC
1005                 { if (extra_warnings && TREE_STATIC ($1))
1006                     warning ("`%s' is not at beginning of declaration",
1007                              IDENTIFIER_POINTER ($2));
1008                   $$ = tree_cons (NULL_TREE, $2, $1);
1009                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1010         ;
1011
1012
1013 /* Used instead of declspecs where storage classes are not allowed
1014    (that is, for typenames and structure components).
1015    Don't accept a typedef-name if anything but a modifier precedes it.  */
1016
1017 typed_typespecs:
1018           typespec reserved_typespecquals
1019                 { $$ = tree_cons (NULL_TREE, $1, $2); }
1020         | nonempty_type_quals typespec reserved_typespecquals
1021                 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
1022         ;
1023
1024 reserved_typespecquals:  /* empty */
1025                 { $$ = NULL_TREE; }
1026         | reserved_typespecquals typespecqual_reserved
1027                 { $$ = tree_cons (NULL_TREE, $2, $1); }
1028         ;
1029
1030 /* A typespec (but not a type qualifier).
1031    Once we have seen one of these in a declaration,
1032    if a typedef name appears then it is being redeclared.  */
1033
1034 typespec: TYPESPEC
1035         | structsp
1036         | TYPENAME
1037                 { /* For a typedef name, record the meaning, not the name.
1038                      In case of `foo foo, bar;'.  */
1039                   $$ = lookup_name ($1); }
1040 ifobjc
1041         | CLASSNAME protocolrefs
1042                 { $$ = get_static_reference ($1, $2); }
1043         | OBJECTNAME protocolrefs
1044                 { $$ = get_object_reference ($2); }
1045
1046 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>"
1047    - nisse@lysator.liu.se */
1048         | non_empty_protocolrefs
1049                 { $$ = get_object_reference ($1); }
1050 end ifobjc
1051         | TYPEOF '(' expr ')'
1052                 { $$ = TREE_TYPE ($3); }
1053         | TYPEOF '(' typename ')'
1054                 { $$ = groktypename ($3); }
1055         ;
1056
1057 /* A typespec that is a reserved word, or a type qualifier.  */
1058
1059 typespecqual_reserved: TYPESPEC
1060         | TYPE_QUAL
1061         | structsp
1062         ;
1063
1064 initdecls:
1065         initdcl
1066         | initdecls ',' initdcl
1067         ;
1068
1069 notype_initdecls:
1070         notype_initdcl
1071         | notype_initdecls ',' initdcl
1072         ;
1073
1074 maybeasm:
1075           /* empty */
1076                 { $$ = NULL_TREE; }
1077         | ASM_KEYWORD '(' string ')'
1078                 { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
1079                   $$ = $3;
1080                 }
1081         ;
1082
1083 initdcl:
1084           declarator maybeasm maybe_attribute '='
1085                 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1086                                           $3, prefix_attributes);
1087                   start_init ($<ttype>$, $2, global_bindings_p ()); }
1088           init
1089 /* Note how the declaration of the variable is in effect while its init is parsed! */
1090                 { finish_init ();
1091                   finish_decl ($<ttype>5, $6, $2); }
1092         | declarator maybeasm maybe_attribute
1093                 { tree d = start_decl ($1, current_declspecs, 0,
1094                                        $3, prefix_attributes);
1095                   finish_decl (d, NULL_TREE, $2); 
1096                 }
1097         ;
1098
1099 notype_initdcl:
1100           notype_declarator maybeasm maybe_attribute '='
1101                 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1102                                           $3, prefix_attributes);
1103                   start_init ($<ttype>$, $2, global_bindings_p ()); }
1104           init
1105 /* Note how the declaration of the variable is in effect while its init is parsed! */
1106                 { finish_init ();
1107                   decl_attributes ($<ttype>5, $3, prefix_attributes);
1108                   finish_decl ($<ttype>5, $6, $2); }
1109         | notype_declarator maybeasm maybe_attribute
1110                 { tree d = start_decl ($1, current_declspecs, 0,
1111                                        $3, prefix_attributes);
1112                   finish_decl (d, NULL_TREE, $2); }
1113         ;
1114 /* the * rules are dummies to accept the Apollo extended syntax
1115    so that the header files compile. */
1116 maybe_attribute:
1117       /* empty */
1118                 { $$ = NULL_TREE; }
1119         | attributes
1120                 { $$ = $1; }
1121         ;
1122  
1123 attributes:
1124       attribute
1125                 { $$ = $1; }
1126         | attributes attribute
1127                 { $$ = chainon ($1, $2); }
1128         ;
1129
1130 attribute:
1131       ATTRIBUTE '(' '(' attribute_list ')' ')'
1132                 { $$ = $4; }
1133         ;
1134
1135 attribute_list:
1136       attrib
1137                 { $$ = $1; }
1138         | attribute_list ',' attrib
1139                 { $$ = chainon ($1, $3); }
1140         ;
1141  
1142 attrib:
1143     /* empty */
1144                 { $$ = NULL_TREE; }
1145         | any_word
1146                 { $$ = build_tree_list ($1, NULL_TREE); }
1147         | any_word '(' IDENTIFIER ')'
1148                 { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
1149         | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
1150                 { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
1151         | any_word '(' exprlist ')'
1152                 { $$ = build_tree_list ($1, $3); }
1153         ;
1154
1155 /* This still leaves out most reserved keywords,
1156    shouldn't we include them?  */
1157
1158 any_word:
1159           identifier
1160         | SCSPEC
1161         | TYPESPEC
1162         | TYPE_QUAL
1163         ;
1164 \f
1165 /* Initializers.  `init' is the entry point.  */
1166
1167 init:
1168         expr_no_commas
1169         | '{'
1170                 { really_start_incremental_init (NULL_TREE);
1171                   /* Note that the call to clear_momentary
1172                      is in process_init_element.  */
1173                   push_momentary (); }
1174           initlist_maybe_comma '}'
1175                 { $$ = pop_init_level (0);
1176                   if ($$ == error_mark_node
1177                       && ! (yychar == STRING || yychar == CONSTANT))
1178                     pop_momentary ();
1179                   else
1180                     pop_momentary_nofree (); }
1181
1182         | error
1183                 { $$ = error_mark_node; }
1184         ;
1185
1186 /* `initlist_maybe_comma' is the guts of an initializer in braces.  */
1187 initlist_maybe_comma:
1188           /* empty */
1189                 { if (pedantic)
1190                     pedwarn ("ANSI C forbids empty initializer braces"); }
1191         | initlist1 maybecomma
1192         ;
1193
1194 initlist1:
1195           initelt
1196         | initlist1 ',' initelt
1197         ;
1198
1199 /* `initelt' is a single element of an initializer.
1200    It may use braces.  */
1201 initelt:
1202         expr_no_commas
1203                 { process_init_element ($1); }
1204         | '{' 
1205                 { push_init_level (0); }
1206           initlist_maybe_comma '}'
1207                 { process_init_element (pop_init_level (0)); }
1208         | error
1209         /* These are for labeled elements.  The syntax for an array element
1210            initializer conflicts with the syntax for an Objective-C message,
1211            so don't include these productions in the Objective-C grammar.  */
1212 ifc
1213         | '[' expr_no_commas ELLIPSIS expr_no_commas ']' '='
1214                 { set_init_index ($2, $4); }
1215           initelt
1216         | '[' expr_no_commas ']' '='
1217                 { set_init_index ($2, NULL_TREE); }
1218           initelt
1219         | '[' expr_no_commas ']'
1220                 { set_init_index ($2, NULL_TREE); }
1221           initelt
1222 end ifc
1223         | identifier ':'
1224                 { set_init_label ($1); }
1225           initelt
1226         | '.' identifier '='
1227                 { set_init_label ($2); }
1228           initelt
1229         ;
1230 \f
1231 nested_function:
1232           declarator
1233                 { push_c_function_context ();
1234                   if (! start_function (current_declspecs, $1,
1235                                         prefix_attributes, NULL_TREE, 1))
1236                     {
1237                       pop_c_function_context ();
1238                       YYERROR1;
1239                     }
1240                   reinit_parse_for_function (); }
1241            xdecls
1242                 { store_parm_decls (); }
1243 /* This used to use compstmt_or_error.
1244    That caused a bug with input `f(g) int g {}',
1245    where the use of YYERROR1 above caused an error
1246    which then was handled by compstmt_or_error.
1247    There followed a repeated execution of that same rule,
1248    which called YYERROR1 again, and so on.  */
1249           compstmt
1250                 { finish_function (1);
1251                   pop_c_function_context (); }
1252         ;
1253
1254 notype_nested_function:
1255           notype_declarator
1256                 { push_c_function_context ();
1257                   if (! start_function (current_declspecs, $1,
1258                                         prefix_attributes, NULL_TREE, 1))
1259                     {
1260                       pop_c_function_context ();
1261                       YYERROR1;
1262                     }
1263                   reinit_parse_for_function (); }
1264           xdecls
1265                 { store_parm_decls (); }
1266 /* This used to use compstmt_or_error.
1267    That caused a bug with input `f(g) int g {}',
1268    where the use of YYERROR1 above caused an error
1269    which then was handled by compstmt_or_error.
1270    There followed a repeated execution of that same rule,
1271    which called YYERROR1 again, and so on.  */
1272           compstmt
1273                 { finish_function (1);
1274                   pop_c_function_context (); }
1275         ;
1276
1277 /* Any kind of declarator (thus, all declarators allowed
1278    after an explicit typespec).  */
1279
1280 declarator:
1281           after_type_declarator
1282         | notype_declarator
1283         ;
1284
1285 /* A declarator that is allowed only after an explicit typespec.  */
1286
1287 after_type_declarator:
1288           '(' after_type_declarator ')'
1289                 { $$ = $2; }
1290         | after_type_declarator '(' parmlist_or_identifiers  %prec '.'
1291                 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1292 /*      | after_type_declarator '(' error ')'  %prec '.'
1293                 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1294                   poplevel (0, 0, 0); }  */
1295         | after_type_declarator '[' expr ']'  %prec '.'
1296                 { $$ = build_nt (ARRAY_REF, $1, $3); }
1297         | after_type_declarator '[' ']'  %prec '.'
1298                 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1299         | '*' type_quals after_type_declarator  %prec UNARY
1300                 { $$ = make_pointer_declarator ($2, $3); }
1301         | attributes setattrs after_type_declarator
1302                 { $$ = $3; }
1303         | TYPENAME
1304 ifobjc
1305         | OBJECTNAME
1306 end ifobjc
1307         ;
1308
1309 /* Kinds of declarator that can appear in a parameter list
1310    in addition to notype_declarator.  This is like after_type_declarator
1311    but does not allow a typedef name in parentheses as an identifier
1312    (because it would conflict with a function with that typedef as arg).  */
1313
1314 parm_declarator:
1315           parm_declarator '(' parmlist_or_identifiers  %prec '.'
1316                 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1317 /*      | parm_declarator '(' error ')'  %prec '.'
1318                 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1319                   poplevel (0, 0, 0); }  */
1320         | parm_declarator '[' expr ']'  %prec '.'
1321                 { $$ = build_nt (ARRAY_REF, $1, $3); }
1322         | parm_declarator '[' ']'  %prec '.'
1323                 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1324         | '*' type_quals parm_declarator  %prec UNARY
1325                 { $$ = make_pointer_declarator ($2, $3); }
1326         | attributes setattrs parm_declarator
1327                 { $$ = $3; }
1328         | TYPENAME
1329         ;
1330
1331 /* A declarator allowed whether or not there has been
1332    an explicit typespec.  These cannot redeclare a typedef-name.  */
1333
1334 notype_declarator:
1335           notype_declarator '(' parmlist_or_identifiers  %prec '.'
1336                 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1337 /*      | notype_declarator '(' error ')'  %prec '.'
1338                 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1339                   poplevel (0, 0, 0); }  */
1340         | '(' notype_declarator ')'
1341                 { $$ = $2; }
1342         | '*' type_quals notype_declarator  %prec UNARY
1343                 { $$ = make_pointer_declarator ($2, $3); }
1344         | notype_declarator '[' expr ']'  %prec '.'
1345                 { $$ = build_nt (ARRAY_REF, $1, $3); }
1346         | notype_declarator '[' ']'  %prec '.'
1347                 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1348         | attributes setattrs notype_declarator
1349                 { $$ = $3; }
1350         | IDENTIFIER
1351         ;
1352
1353 structsp:
1354           STRUCT identifier '{'
1355                 { $$ = start_struct (RECORD_TYPE, $2);
1356                   /* Start scope of tag before parsing components.  */
1357                 }
1358           component_decl_list '}' maybe_attribute 
1359                 { $$ = finish_struct ($<ttype>4, $5, $7); }
1360         | STRUCT '{' component_decl_list '}' maybe_attribute
1361                 { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
1362                                       $3, $5);
1363                 }
1364         | STRUCT identifier
1365                 { $$ = xref_tag (RECORD_TYPE, $2); }
1366         | UNION identifier '{'
1367                 { $$ = start_struct (UNION_TYPE, $2); }
1368           component_decl_list '}' maybe_attribute
1369                 { $$ = finish_struct ($<ttype>4, $5, $7); }
1370         | UNION '{' component_decl_list '}' maybe_attribute
1371                 { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
1372                                       $3, $5);
1373                 }
1374         | UNION identifier
1375                 { $$ = xref_tag (UNION_TYPE, $2); }
1376         | ENUM identifier '{'
1377                 { $<itype>3 = suspend_momentary ();
1378                   $$ = start_enum ($2); }
1379           enumlist maybecomma_warn '}' maybe_attribute
1380                 { $$ = finish_enum ($<ttype>4, nreverse ($5), $8);
1381                   resume_momentary ($<itype>3); }
1382         | ENUM '{'
1383                 { $<itype>2 = suspend_momentary ();
1384                   $$ = start_enum (NULL_TREE); }
1385           enumlist maybecomma_warn '}' maybe_attribute
1386                 { $$ = finish_enum ($<ttype>3, nreverse ($4), $7);
1387                   resume_momentary ($<itype>2); }
1388         | ENUM identifier
1389                 { $$ = xref_tag (ENUMERAL_TYPE, $2); }
1390         ;
1391
1392 maybecomma:
1393           /* empty */
1394         | ','
1395         ;
1396
1397 maybecomma_warn:
1398           /* empty */
1399         | ','
1400                 { if (pedantic) pedwarn ("comma at end of enumerator list"); }
1401         ;
1402
1403 component_decl_list:
1404           component_decl_list2
1405                 { $$ = $1; }
1406         | component_decl_list2 component_decl
1407                 { $$ = chainon ($1, $2);
1408                   pedwarn ("no semicolon at end of struct or union"); }
1409         ;
1410
1411 component_decl_list2:   /* empty */
1412                 { $$ = NULL_TREE; }
1413         | component_decl_list2 component_decl ';'
1414                 { $$ = chainon ($1, $2); }
1415         | component_decl_list2 ';'
1416                 { if (pedantic)
1417                     pedwarn ("extra semicolon in struct or union specified"); }
1418 ifobjc
1419         /* foo(sizeof(struct{ @defs(ClassName)})); */
1420         | DEFS '(' CLASSNAME ')'
1421                 {
1422                   tree interface = lookup_interface ($3);
1423
1424                   if (interface)
1425                     $$ = get_class_ivars (interface);
1426                   else
1427                     {
1428                       error ("Cannot find interface declaration for `%s'",
1429                              IDENTIFIER_POINTER ($3));
1430                       $$ = NULL_TREE;
1431                     }
1432                 }
1433 end ifobjc
1434         ;
1435
1436 /* There is a shift-reduce conflict here, because `components' may
1437    start with a `typename'.  It happens that shifting (the default resolution)
1438    does the right thing, because it treats the `typename' as part of
1439    a `typed_typespecs'.
1440
1441    It is possible that this same technique would allow the distinction
1442    between `notype_initdecls' and `initdecls' to be eliminated.
1443    But I am being cautious and not trying it.  */
1444
1445 component_decl:
1446           typed_typespecs setspecs components
1447                 { $$ = $3;
1448                   current_declspecs = TREE_VALUE (declspec_stack);
1449                   prefix_attributes = TREE_PURPOSE (declspec_stack);
1450                   declspec_stack = TREE_CHAIN (declspec_stack);
1451                   resume_momentary ($2); }
1452         | typed_typespecs
1453                 { if (pedantic)
1454                     pedwarn ("ANSI C forbids member declarations with no members");
1455                   shadow_tag($1);
1456                   $$ = NULL_TREE; }
1457         | nonempty_type_quals setspecs components
1458                 { $$ = $3;
1459                   current_declspecs = TREE_VALUE (declspec_stack);
1460                   prefix_attributes = TREE_PURPOSE (declspec_stack);
1461                   declspec_stack = TREE_CHAIN (declspec_stack);
1462                   resume_momentary ($2); }
1463         | nonempty_type_quals
1464                 { if (pedantic)
1465                     pedwarn ("ANSI C forbids member declarations with no members");
1466                   shadow_tag($1);
1467                   $$ = NULL_TREE; }
1468         | error
1469                 { $$ = NULL_TREE; }
1470         ;
1471
1472 components:
1473           component_declarator
1474         | components ',' component_declarator
1475                 { $$ = chainon ($1, $3); }
1476         ;
1477
1478 component_declarator:
1479           save_filename save_lineno declarator maybe_attribute
1480                 { $$ = grokfield ($1, $2, $3, current_declspecs, NULL_TREE);
1481                   decl_attributes ($$, $4, prefix_attributes); }
1482         | save_filename save_lineno
1483           declarator ':' expr_no_commas maybe_attribute
1484                 { $$ = grokfield ($1, $2, $3, current_declspecs, $5);
1485                   decl_attributes ($$, $6, prefix_attributes); }
1486         | save_filename save_lineno ':' expr_no_commas maybe_attribute
1487                 { $$ = grokfield ($1, $2, NULL_TREE, current_declspecs, $4);
1488                   decl_attributes ($$, $5, prefix_attributes); }
1489         ;
1490
1491 /* We chain the enumerators in reverse order.
1492    They are put in forward order where enumlist is used.
1493    (The order used to be significant, but no longer is so.
1494    However, we still maintain the order, just to be clean.)  */
1495
1496 enumlist:
1497           enumerator
1498         | enumlist ',' enumerator
1499                 { if ($1 == error_mark_node)
1500                     $$ = $1;
1501                   else
1502                     $$ = chainon ($3, $1); }
1503         | error
1504                 { $$ = error_mark_node; }
1505         ;
1506
1507
1508 enumerator:
1509           identifier
1510                 { $$ = build_enumerator ($1, NULL_TREE); }
1511         | identifier '=' expr_no_commas
1512                 { $$ = build_enumerator ($1, $3); }
1513         ;
1514
1515 typename:
1516         typed_typespecs absdcl
1517                 { $$ = build_tree_list ($1, $2); }
1518         | nonempty_type_quals absdcl
1519                 { $$ = build_tree_list ($1, $2); }
1520         ;
1521
1522 absdcl:   /* an absolute declarator */
1523         /* empty */
1524                 { $$ = NULL_TREE; }
1525         | absdcl1
1526         ;
1527
1528 nonempty_type_quals:
1529           TYPE_QUAL
1530                 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1531         | nonempty_type_quals TYPE_QUAL
1532                 { $$ = tree_cons (NULL_TREE, $2, $1); }
1533         ;
1534
1535 type_quals:
1536           /* empty */
1537                 { $$ = NULL_TREE; }
1538         | type_quals TYPE_QUAL
1539                 { $$ = tree_cons (NULL_TREE, $2, $1); }
1540         ;
1541
1542 absdcl1:  /* a nonempty absolute declarator */
1543           '(' absdcl1 ')'
1544                 { $$ = $2; }
1545           /* `(typedef)1' is `int'.  */
1546         | '*' type_quals absdcl1  %prec UNARY
1547                 { $$ = make_pointer_declarator ($2, $3); }
1548         | '*' type_quals  %prec UNARY
1549                 { $$ = make_pointer_declarator ($2, NULL_TREE); }
1550         | absdcl1 '(' parmlist  %prec '.'
1551                 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1552         | absdcl1 '[' expr ']'  %prec '.'
1553                 { $$ = build_nt (ARRAY_REF, $1, $3); }
1554         | absdcl1 '[' ']'  %prec '.'
1555                 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1556         | '(' parmlist  %prec '.'
1557                 { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
1558         | '[' expr ']'  %prec '.'
1559                 { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); }
1560         | '[' ']'  %prec '.'
1561                 { $$ = build_nt (ARRAY_REF, NULL_TREE, NULL_TREE); }
1562         | attributes setattrs absdcl1
1563                 { $$ = $3; }
1564         ;
1565
1566 /* at least one statement, the first of which parses without error.  */
1567 /* stmts is used only after decls, so an invalid first statement
1568    is actually regarded as an invalid decl and part of the decls.  */
1569
1570 stmts:
1571         lineno_stmt_or_labels
1572                 {
1573                   if (pedantic && $1)
1574                     pedwarn ("ANSI C forbids label at end of compound statement");
1575                 }
1576         ;
1577
1578 lineno_stmt_or_labels:
1579           lineno_stmt_or_label
1580         | lineno_stmt_or_labels lineno_stmt_or_label
1581                 { $$ = $2; }
1582         | lineno_stmt_or_labels errstmt
1583                 { $$ = 0; }
1584         ;
1585
1586 xstmts:
1587         /* empty */
1588         | stmts
1589         ;
1590
1591 errstmt:  error ';'
1592         ;
1593
1594 pushlevel:  /* empty */
1595                 { emit_line_note (input_filename, lineno);
1596                   pushlevel (0);
1597                   clear_last_expr ();
1598                   push_momentary ();
1599                   expand_start_bindings (0);
1600 ifobjc
1601                   if (objc_method_context)
1602                     add_objc_decls ();
1603 end ifobjc
1604                 }
1605         ;
1606
1607 /* Read zero or more forward-declarations for labels
1608    that nested functions can jump to.  */
1609 maybe_label_decls:
1610           /* empty */
1611         | label_decls
1612                 { if (pedantic)
1613                     pedwarn ("ANSI C forbids label declarations"); }
1614         ;
1615
1616 label_decls:
1617           label_decl
1618         | label_decls label_decl
1619         ;
1620
1621 label_decl:
1622           LABEL identifiers_or_typenames ';'
1623                 { tree link;
1624                   for (link = $2; link; link = TREE_CHAIN (link))
1625                     {
1626                       tree label = shadow_label (TREE_VALUE (link));
1627                       C_DECLARED_LABEL_FLAG (label) = 1;
1628                       declare_nonlocal_label (label);
1629                     }
1630                 }
1631         ;
1632
1633 /* This is the body of a function definition.
1634    It causes syntax errors to ignore to the next openbrace.  */
1635 compstmt_or_error:
1636           compstmt
1637                 {}
1638         | error compstmt
1639         ;
1640
1641 compstmt: '{' '}'
1642                 { $$ = convert (void_type_node, integer_zero_node); }
1643         | '{' pushlevel maybe_label_decls decls xstmts '}'
1644                 { emit_line_note (input_filename, lineno);
1645                   expand_end_bindings (getdecls (), 1, 0);
1646                   $$ = poplevel (1, 1, 0);
1647                   if (yychar == CONSTANT || yychar == STRING)
1648                     pop_momentary_nofree ();
1649                   else
1650                     pop_momentary (); }
1651         | '{' pushlevel maybe_label_decls error '}'
1652                 { emit_line_note (input_filename, lineno);
1653                   expand_end_bindings (getdecls (), kept_level_p (), 0);
1654                   $$ = poplevel (kept_level_p (), 0, 0);
1655                   if (yychar == CONSTANT || yychar == STRING)
1656                     pop_momentary_nofree ();
1657                   else
1658                     pop_momentary (); }
1659         | '{' pushlevel maybe_label_decls stmts '}'
1660                 { emit_line_note (input_filename, lineno);
1661                   expand_end_bindings (getdecls (), kept_level_p (), 0);
1662                   $$ = poplevel (kept_level_p (), 0, 0);
1663                   if (yychar == CONSTANT || yychar == STRING)
1664                     pop_momentary_nofree ();
1665                   else
1666                     pop_momentary (); }
1667         ;
1668
1669 /* Value is number of statements counted as of the closeparen.  */
1670 simple_if:
1671           if_prefix lineno_labeled_stmt
1672 /* Make sure expand_end_cond is run once
1673    for each call to expand_start_cond.
1674    Otherwise a crash is likely.  */
1675         | if_prefix error
1676         ;
1677
1678 if_prefix:
1679           IF '(' expr ')'
1680                 { emit_line_note ($<filename>-1, $<lineno>0);
1681                   expand_start_cond (truthvalue_conversion ($3), 0);
1682                   $<itype>$ = stmt_count;
1683                   if_stmt_file = $<filename>-1;
1684                   if_stmt_line = $<lineno>0;
1685                   position_after_white_space (); }
1686         ;
1687
1688 /* This is a subroutine of stmt.
1689    It is used twice, once for valid DO statements
1690    and once for catching errors in parsing the end test.  */
1691 do_stmt_start:
1692           DO
1693                 { stmt_count++;
1694                   emit_line_note ($<filename>-1, $<lineno>0);
1695                   /* See comment in `while' alternative, above.  */
1696                   emit_nop ();
1697                   expand_start_loop_continue_elsewhere (1);
1698                   position_after_white_space (); }
1699           lineno_labeled_stmt WHILE
1700                 { expand_loop_continue_here (); }
1701         ;
1702
1703 save_filename:
1704                 { $$ = input_filename; }
1705         ;
1706
1707 save_lineno:
1708                 { $$ = lineno; }
1709         ;
1710
1711 lineno_labeled_stmt:
1712           save_filename save_lineno stmt
1713                 { }
1714 /*      | save_filename save_lineno error
1715                 { }
1716 */
1717         | save_filename save_lineno label lineno_labeled_stmt
1718                 { }
1719         ;
1720
1721 lineno_stmt_or_label:
1722           save_filename save_lineno stmt_or_label
1723                 { $$ = $3; }
1724         ;
1725
1726 stmt_or_label:
1727           stmt
1728                 { $$ = 0; }
1729         | label
1730                 { $$ = 1; }
1731         ;
1732
1733 /* Parse a single real statement, not including any labels.  */
1734 stmt:
1735           compstmt
1736                 { stmt_count++; }
1737         | all_iter_stmt 
1738         | expr ';'
1739                 { stmt_count++;
1740                   emit_line_note ($<filename>-1, $<lineno>0);
1741 /* It appears that this should not be done--that a non-lvalue array
1742    shouldn't get an error if the value isn't used.
1743    Section 3.2.2.1 says that an array lvalue gets converted to a pointer
1744    if it appears as a top-level expression,
1745    but says nothing about non-lvalue arrays.  */
1746 #if 0
1747                   /* Call default_conversion to get an error
1748                      on referring to a register array if pedantic.  */
1749                   if (TREE_CODE (TREE_TYPE ($1)) == ARRAY_TYPE
1750                       || TREE_CODE (TREE_TYPE ($1)) == FUNCTION_TYPE)
1751                     $1 = default_conversion ($1);
1752 #endif
1753                   iterator_expand ($1);
1754                   clear_momentary (); }
1755         | simple_if ELSE
1756                 { expand_start_else ();
1757                   $<itype>1 = stmt_count;
1758                   position_after_white_space (); }
1759           lineno_labeled_stmt
1760                 { expand_end_cond ();
1761                   if (extra_warnings && stmt_count == $<itype>1)
1762                     warning ("empty body in an else-statement"); }
1763         | simple_if %prec IF
1764                 { expand_end_cond ();
1765                   /* This warning is here instead of in simple_if, because we
1766                      do not want a warning if an empty if is followed by an
1767                      else statement.  Increment stmt_count so we don't
1768                      give a second error if this is a nested `if'.  */
1769                   if (extra_warnings && stmt_count++ == $<itype>1)
1770                     warning_with_file_and_line (if_stmt_file, if_stmt_line,
1771                                                 "empty body in an if-statement"); }
1772 /* Make sure expand_end_cond is run once
1773    for each call to expand_start_cond.
1774    Otherwise a crash is likely.  */
1775         | simple_if ELSE error
1776                 { expand_end_cond (); }
1777         | WHILE
1778                 { stmt_count++;
1779                   emit_line_note ($<filename>-1, $<lineno>0);
1780                   /* The emit_nop used to come before emit_line_note,
1781                      but that made the nop seem like part of the preceding line.
1782                      And that was confusing when the preceding line was
1783                      inside of an if statement and was not really executed.
1784                      I think it ought to work to put the nop after the line number.
1785                      We will see.  --rms, July 15, 1991.  */
1786                   emit_nop (); }
1787           '(' expr ')'
1788                 { /* Don't start the loop till we have succeeded
1789                      in parsing the end test.  This is to make sure
1790                      that we end every loop we start.  */
1791                   expand_start_loop (1);
1792                   emit_line_note (input_filename, lineno);
1793                   expand_exit_loop_if_false (NULL_PTR,
1794                                              truthvalue_conversion ($4));
1795                   position_after_white_space (); }
1796           lineno_labeled_stmt
1797                 { expand_end_loop (); }
1798         | do_stmt_start
1799           '(' expr ')' ';'
1800                 { emit_line_note (input_filename, lineno);
1801                   expand_exit_loop_if_false (NULL_PTR,
1802                                              truthvalue_conversion ($3));
1803                   expand_end_loop ();
1804                   clear_momentary (); }
1805 /* This rule is needed to make sure we end every loop we start.  */
1806         | do_stmt_start error
1807                 { expand_end_loop ();
1808                   clear_momentary (); }
1809         | FOR
1810           '(' xexpr ';'
1811                 { stmt_count++;
1812                   emit_line_note ($<filename>-1, $<lineno>0);
1813                   /* See comment in `while' alternative, above.  */
1814                   emit_nop ();
1815                   if ($3) c_expand_expr_stmt ($3);
1816                   /* Next step is to call expand_start_loop_continue_elsewhere,
1817                      but wait till after we parse the entire for (...).
1818                      Otherwise, invalid input might cause us to call that
1819                      fn without calling expand_end_loop.  */
1820                 }
1821           xexpr ';'
1822                 /* Can't emit now; wait till after expand_start_loop...  */
1823                 { $<lineno>7 = lineno;
1824                   $<filename>$ = input_filename; }
1825           xexpr ')'
1826                 { 
1827                   /* Start the loop.  Doing this after parsing
1828                      all the expressions ensures we will end the loop.  */
1829                   expand_start_loop_continue_elsewhere (1);
1830                   /* Emit the end-test, with a line number.  */
1831                   emit_line_note ($<filename>8, $<lineno>7);
1832                   if ($6)
1833                     expand_exit_loop_if_false (NULL_PTR,
1834                                                truthvalue_conversion ($6));
1835                   /* Don't let the tree nodes for $9 be discarded by
1836                      clear_momentary during the parsing of the next stmt.  */
1837                   push_momentary ();
1838                   $<lineno>7 = lineno;
1839                   $<filename>8 = input_filename;
1840                   position_after_white_space (); }
1841           lineno_labeled_stmt
1842                 { /* Emit the increment expression, with a line number.  */
1843                   emit_line_note ($<filename>8, $<lineno>7);
1844                   expand_loop_continue_here ();
1845                   if ($9)
1846                     c_expand_expr_stmt ($9);
1847                   if (yychar == CONSTANT || yychar == STRING)
1848                     pop_momentary_nofree ();
1849                   else
1850                     pop_momentary ();
1851                   expand_end_loop (); }
1852         | SWITCH '(' expr ')'
1853                 { stmt_count++;
1854                   emit_line_note ($<filename>-1, $<lineno>0);
1855                   c_expand_start_case ($3);
1856                   /* Don't let the tree nodes for $3 be discarded by
1857                      clear_momentary during the parsing of the next stmt.  */
1858                   push_momentary ();
1859                   position_after_white_space (); }
1860           lineno_labeled_stmt
1861                 { expand_end_case ($3);
1862                   if (yychar == CONSTANT || yychar == STRING)
1863                     pop_momentary_nofree ();
1864                   else
1865                     pop_momentary (); }
1866         | BREAK ';'
1867                 { stmt_count++;
1868                   emit_line_note ($<filename>-1, $<lineno>0);
1869                   if ( ! expand_exit_something ())
1870                     error ("break statement not within loop or switch"); }
1871         | CONTINUE ';'
1872                 { stmt_count++;
1873                   emit_line_note ($<filename>-1, $<lineno>0);
1874                   if (! expand_continue_loop (NULL_PTR))
1875                     error ("continue statement not within a loop"); }
1876         | RETURN ';'
1877                 { stmt_count++;
1878                   emit_line_note ($<filename>-1, $<lineno>0);
1879                   c_expand_return (NULL_TREE); }
1880         | RETURN expr ';'
1881                 { stmt_count++;
1882                   emit_line_note ($<filename>-1, $<lineno>0);
1883                   c_expand_return ($2); }
1884         | ASM_KEYWORD maybe_type_qual '(' expr ')' ';'
1885                 { stmt_count++;
1886                   emit_line_note ($<filename>-1, $<lineno>0);
1887                   STRIP_NOPS ($4);
1888                   if ((TREE_CODE ($4) == ADDR_EXPR
1889                        && TREE_CODE (TREE_OPERAND ($4, 0)) == STRING_CST)
1890                       || TREE_CODE ($4) == STRING_CST)
1891                     expand_asm ($4);
1892                   else
1893                     error ("argument of `asm' is not a constant string"); }
1894         /* This is the case with just output operands.  */
1895         | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';'
1896                 { stmt_count++;
1897                   emit_line_note ($<filename>-1, $<lineno>0);
1898                   c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
1899                                          $2 == ridpointers[(int)RID_VOLATILE],
1900                                          input_filename, lineno); }
1901         /* This is the case with input operands as well.  */
1902         | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':' asm_operands ')' ';'
1903                 { stmt_count++;
1904                   emit_line_note ($<filename>-1, $<lineno>0);
1905                   c_expand_asm_operands ($4, $6, $8, NULL_TREE,
1906                                          $2 == ridpointers[(int)RID_VOLATILE],
1907                                          input_filename, lineno); }
1908         /* This is the case with clobbered registers as well.  */
1909         | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
1910           asm_operands ':' asm_clobbers ')' ';'
1911                 { stmt_count++;
1912                   emit_line_note ($<filename>-1, $<lineno>0);
1913                   c_expand_asm_operands ($4, $6, $8, $10,
1914                                          $2 == ridpointers[(int)RID_VOLATILE],
1915                                          input_filename, lineno); }
1916         | GOTO identifier ';'
1917                 { tree decl;
1918                   stmt_count++;
1919                   emit_line_note ($<filename>-1, $<lineno>0);
1920                   decl = lookup_label ($2);
1921                   if (decl != 0)
1922                     {
1923                       TREE_USED (decl) = 1;
1924                       expand_goto (decl);
1925                     }
1926                 }
1927         | GOTO '*' expr ';'
1928                 { if (pedantic)
1929                     pedwarn ("ANSI C forbids `goto *expr;'");
1930                   stmt_count++;
1931                   emit_line_note ($<filename>-1, $<lineno>0);
1932                   expand_computed_goto (convert (ptr_type_node, $3)); }
1933         | ';'
1934         ;
1935
1936 all_iter_stmt:
1937           all_iter_stmt_simple
1938 /*      | all_iter_stmt_with_decl */
1939         ;
1940
1941 all_iter_stmt_simple:
1942           FOR '(' primary ')' 
1943           {
1944             /* The value returned by this action is  */
1945             /*      1 if everything is OK */ 
1946             /*      0 in case of error or already bound iterator */
1947
1948             $<itype>$ = 0;
1949             if (TREE_CODE ($3) != VAR_DECL)
1950               error ("invalid `for (ITERATOR)' syntax");
1951             else if (! ITERATOR_P ($3))
1952               error ("`%s' is not an iterator",
1953                      IDENTIFIER_POINTER (DECL_NAME ($3)));
1954             else if (ITERATOR_BOUND_P ($3))
1955               error ("`for (%s)' inside expansion of same iterator",
1956                      IDENTIFIER_POINTER (DECL_NAME ($3)));
1957             else
1958               {
1959                 $<itype>$ = 1;
1960                 iterator_for_loop_start ($3);
1961               }
1962           }
1963           lineno_labeled_stmt
1964           {
1965             if ($<itype>5)
1966               iterator_for_loop_end ($3);
1967           }
1968
1969 /*  This really should allow any kind of declaration,
1970     for generality.  Fix it before turning it back on.
1971
1972 all_iter_stmt_with_decl:
1973           FOR '(' ITERATOR pushlevel setspecs iterator_spec ')' 
1974           {
1975 */          /* The value returned by this action is  */
1976             /*      1 if everything is OK */ 
1977             /*      0 in case of error or already bound iterator */
1978 /*
1979             iterator_for_loop_start ($6);
1980           }
1981           lineno_labeled_stmt
1982           {
1983             iterator_for_loop_end ($6);
1984             emit_line_note (input_filename, lineno);
1985             expand_end_bindings (getdecls (), 1, 0);
1986             $<ttype>$ = poplevel (1, 1, 0);
1987             if (yychar == CONSTANT || yychar == STRING)
1988               pop_momentary_nofree ();
1989             else
1990               pop_momentary ();     
1991           }
1992 */
1993
1994 /* Any kind of label, including jump labels and case labels.
1995    ANSI C accepts labels only before statements, but we allow them
1996    also at the end of a compound statement.  */
1997
1998 label:    CASE expr_no_commas ':'
1999                 { register tree value = check_case_value ($2);
2000                   register tree label
2001                     = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2002
2003                   stmt_count++;
2004
2005                   if (value != error_mark_node)
2006                     {
2007                       tree duplicate;
2008                       int success = pushcase (value, convert_and_check,
2009                                               label, &duplicate);
2010                       if (success == 1)
2011                         error ("case label not within a switch statement");
2012                       else if (success == 2)
2013                         {
2014                           error ("duplicate case value");
2015                           error_with_decl (duplicate, "this is the first entry for that value");
2016                         }
2017                       else if (success == 3)
2018                         warning ("case value out of range");
2019                       else if (success == 5)
2020                         error ("case label within scope of cleanup or variable array");
2021                     }
2022                   position_after_white_space (); }
2023         | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
2024                 { register tree value1 = check_case_value ($2);
2025                   register tree value2 = check_case_value ($4);
2026                   register tree label
2027                     = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2028
2029                   if (pedantic)
2030                     pedwarn ("ANSI C forbids case ranges");
2031                   stmt_count++;
2032
2033                   if (value1 != error_mark_node && value2 != error_mark_node)
2034                     {
2035                       tree duplicate;
2036                       int success = pushcase_range (value1, value2,
2037                                                     convert_and_check, label,
2038                                                     &duplicate);
2039                       if (success == 1)
2040                         error ("case label not within a switch statement");
2041                       else if (success == 2)
2042                         {
2043                           error ("duplicate case value");
2044                           error_with_decl (duplicate, "this is the first entry for that value");
2045                         }
2046                       else if (success == 3)
2047                         warning ("case value out of range");
2048                       else if (success == 4)
2049                         warning ("empty case range");
2050                       else if (success == 5)
2051                         error ("case label within scope of cleanup or variable array");
2052                     }
2053                   position_after_white_space (); }
2054         | DEFAULT ':'
2055                 {
2056                   tree duplicate;
2057                   register tree label
2058                     = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2059                   int success = pushcase (NULL_TREE, 0, label, &duplicate);
2060                   stmt_count++;
2061                   if (success == 1)
2062                     error ("default label not within a switch statement");
2063                   else if (success == 2)
2064                     {
2065                       error ("multiple default labels in one switch");
2066                       error_with_decl (duplicate, "this is the first default label");
2067                     }
2068                   position_after_white_space (); }
2069         | identifier ':'
2070                 { tree label = define_label (input_filename, lineno, $1);
2071                   stmt_count++;
2072                   emit_nop ();
2073                   if (label)
2074                     expand_label (label);
2075                   position_after_white_space (); }
2076         ;
2077
2078 /* Either a type-qualifier or nothing.  First thing in an `asm' statement.  */
2079
2080 maybe_type_qual:
2081         /* empty */
2082                 { emit_line_note (input_filename, lineno);
2083                   $$ = NULL_TREE; }
2084         | TYPE_QUAL
2085                 { emit_line_note (input_filename, lineno); }
2086         ;
2087
2088 xexpr:
2089         /* empty */
2090                 { $$ = NULL_TREE; }
2091         | expr
2092         ;
2093
2094 /* These are the operands other than the first string and colon
2095    in  asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x))  */
2096 asm_operands: /* empty */
2097                 { $$ = NULL_TREE; }
2098         | nonnull_asm_operands
2099         ;
2100
2101 nonnull_asm_operands:
2102           asm_operand
2103         | nonnull_asm_operands ',' asm_operand
2104                 { $$ = chainon ($1, $3); }
2105         ;
2106
2107 asm_operand:
2108           STRING '(' expr ')'
2109                 { $$ = build_tree_list ($1, $3); }
2110         ;
2111
2112 asm_clobbers:
2113           string
2114                 { $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE); }
2115         | asm_clobbers ',' string
2116                 { $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); }
2117         ;
2118 \f
2119 /* This is what appears inside the parens in a function declarator.
2120    Its value is a list of ..._TYPE nodes.  */
2121 parmlist:
2122                 { pushlevel (0);
2123                   clear_parm_order ();
2124                   declare_parm_level (0); }
2125           parmlist_1
2126                 { $$ = $2;
2127                   parmlist_tags_warning ();
2128                   poplevel (0, 0, 0); }
2129         ;
2130
2131 parmlist_1:
2132           parmlist_2 ')'
2133         | parms ';'
2134                 { tree parm;
2135                   if (pedantic)
2136                     pedwarn ("ANSI C forbids forward parameter declarations");
2137                   /* Mark the forward decls as such.  */
2138                   for (parm = getdecls (); parm; parm = TREE_CHAIN (parm))
2139                     TREE_ASM_WRITTEN (parm) = 1;
2140                   clear_parm_order (); }
2141           parmlist_1
2142                 { $$ = $4; }
2143         | error ')'
2144                 { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
2145         ;
2146
2147 /* This is what appears inside the parens in a function declarator.
2148    Is value is represented in the format that grokdeclarator expects.  */
2149 parmlist_2:  /* empty */
2150                 { $$ = get_parm_info (0); }
2151         | ELLIPSIS
2152                 { $$ = get_parm_info (0);
2153                   /* Gcc used to allow this as an extension.  However, it does
2154                      not work for all targets, and thus has been disabled.
2155                      Also, since func (...) and func () are indistinguishable,
2156                      it caused problems with the code in expand_builtin which
2157                      tries to verify that BUILT_IN_NEXT_ARG is being used
2158                      correctly.  */
2159                   error ("ANSI C requires a named argument before `...'");
2160                 }
2161         | parms
2162                 { $$ = get_parm_info (1); }
2163         | parms ',' ELLIPSIS
2164                 { $$ = get_parm_info (0); }
2165         ;
2166
2167 parms:
2168         parm
2169                 { push_parm_decl ($1); }
2170         | parms ',' parm
2171                 { push_parm_decl ($3); }
2172         ;
2173
2174 /* A single parameter declaration or parameter type name,
2175    as found in a parmlist.  */
2176 parm:
2177           typed_declspecs setspecs parm_declarator maybe_attribute
2178                 { $$ = build_tree_list (build_tree_list (current_declspecs,
2179                                                          $3),
2180                                         build_tree_list (prefix_attributes,
2181                                                          $4));
2182                   current_declspecs = TREE_VALUE (declspec_stack);
2183                   prefix_attributes = TREE_PURPOSE (declspec_stack);
2184                   declspec_stack = TREE_CHAIN (declspec_stack);
2185                   resume_momentary ($2); }
2186         | typed_declspecs setspecs notype_declarator maybe_attribute
2187                 { $$ = build_tree_list (build_tree_list (current_declspecs,
2188                                                          $3),
2189                                         build_tree_list (prefix_attributes,
2190                                                          $4)); 
2191                   current_declspecs = TREE_VALUE (declspec_stack);
2192                   prefix_attributes = TREE_PURPOSE (declspec_stack);
2193                   declspec_stack = TREE_CHAIN (declspec_stack);
2194                   resume_momentary ($2); }
2195         | typed_declspecs setspecs absdcl maybe_attribute
2196                 { $$ = build_tree_list (build_tree_list (current_declspecs,
2197                                                          $3),
2198                                         build_tree_list (prefix_attributes,
2199                                                          $4));
2200                   current_declspecs = TREE_VALUE (declspec_stack);
2201                   prefix_attributes = TREE_PURPOSE (declspec_stack);
2202                   declspec_stack = TREE_CHAIN (declspec_stack);
2203                   resume_momentary ($2); }
2204         | declmods setspecs notype_declarator maybe_attribute
2205                 { $$ = build_tree_list (build_tree_list (current_declspecs,
2206                                                          $3),
2207                                         build_tree_list (prefix_attributes,
2208                                                          $4));
2209                   current_declspecs = TREE_VALUE (declspec_stack);
2210                   prefix_attributes = TREE_PURPOSE (declspec_stack);
2211                   declspec_stack = TREE_CHAIN (declspec_stack);
2212                   resume_momentary ($2);  }
2213
2214         | declmods setspecs absdcl maybe_attribute
2215                 { $$ = build_tree_list (build_tree_list (current_declspecs,
2216                                                          $3),
2217                                         build_tree_list (prefix_attributes,
2218                                                          $4));
2219                   current_declspecs = TREE_VALUE (declspec_stack);
2220                   prefix_attributes = TREE_PURPOSE (declspec_stack);
2221                   declspec_stack = TREE_CHAIN (declspec_stack);
2222                   resume_momentary ($2);  }
2223         ;
2224
2225 /* This is used in a function definition
2226    where either a parmlist or an identifier list is ok.
2227    Its value is a list of ..._TYPE nodes or a list of identifiers.  */
2228 parmlist_or_identifiers:
2229                 { pushlevel (0);
2230                   clear_parm_order ();
2231                   declare_parm_level (1); }
2232           parmlist_or_identifiers_1
2233                 { $$ = $2;
2234                   parmlist_tags_warning ();
2235                   poplevel (0, 0, 0); }
2236         ;
2237
2238 parmlist_or_identifiers_1:
2239           parmlist_1
2240         | identifiers ')'
2241                 { tree t;
2242                   for (t = $1; t; t = TREE_CHAIN (t))
2243                     if (TREE_VALUE (t) == NULL_TREE)
2244                       error ("`...' in old-style identifier list");
2245                   $$ = tree_cons (NULL_TREE, NULL_TREE, $1); }
2246         ;
2247
2248 /* A nonempty list of identifiers.  */
2249 identifiers:
2250         IDENTIFIER
2251                 { $$ = build_tree_list (NULL_TREE, $1); }
2252         | identifiers ',' IDENTIFIER
2253                 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2254         ;
2255
2256 /* A nonempty list of identifiers, including typenames.  */
2257 identifiers_or_typenames:
2258         identifier
2259                 { $$ = build_tree_list (NULL_TREE, $1); }
2260         | identifiers_or_typenames ',' identifier
2261                 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2262         ;
2263 \f
2264 ifobjc
2265 /* Objective-C productions.  */
2266
2267 objcdef:
2268           classdef
2269         | classdecl
2270         | aliasdecl
2271         | protocoldef
2272         | methoddef
2273         | END
2274                 {
2275                   if (objc_implementation_context)
2276                     {
2277                       finish_class (objc_implementation_context);
2278                       objc_ivar_chain = NULL_TREE;
2279                       objc_implementation_context = NULL_TREE;
2280                     }
2281                   else
2282                     warning ("`@end' must appear in an implementation context");
2283                 }
2284         ;
2285
2286 /* A nonempty list of identifiers.  */
2287 identifier_list:
2288         identifier
2289                 { $$ = build_tree_list (NULL_TREE, $1); }
2290         | identifier_list ',' identifier
2291                 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2292         ;
2293
2294 classdecl:
2295           CLASS identifier_list ';'
2296                 {
2297                   objc_declare_class ($2);
2298                 }
2299
2300 aliasdecl:
2301           ALIAS identifier identifier ';'
2302                 {
2303                   objc_declare_alias ($2, $3);
2304                 }
2305
2306 classdef:
2307           INTERFACE identifier protocolrefs '{'
2308                 {
2309                   objc_interface_context = objc_ivar_context
2310                     = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2311                   objc_public_flag = 0;
2312                 }
2313           ivar_decl_list '}'
2314                 {
2315                   continue_class (objc_interface_context);
2316                 }
2317           methodprotolist
2318           END
2319                 {
2320                   finish_class (objc_interface_context);
2321                   objc_interface_context = NULL_TREE;
2322                 }
2323
2324         | INTERFACE identifier protocolrefs
2325                 {
2326                   objc_interface_context
2327                     = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2328                   continue_class (objc_interface_context);
2329                 }
2330           methodprotolist
2331           END
2332                 {
2333                   finish_class (objc_interface_context);
2334                   objc_interface_context = NULL_TREE;
2335                 }
2336
2337         | INTERFACE identifier ':' identifier protocolrefs '{'
2338                 {
2339                   objc_interface_context = objc_ivar_context
2340                     = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2341                   objc_public_flag = 0;
2342                 }
2343           ivar_decl_list '}'
2344                 {
2345                   continue_class (objc_interface_context);
2346                 }
2347           methodprotolist
2348           END
2349                 {
2350                   finish_class (objc_interface_context);
2351                   objc_interface_context = NULL_TREE;
2352                 }
2353
2354         | INTERFACE identifier ':' identifier protocolrefs
2355                 {
2356                   objc_interface_context
2357                     = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2358                   continue_class (objc_interface_context);
2359                 }
2360           methodprotolist
2361           END
2362                 {
2363                   finish_class (objc_interface_context);
2364                   objc_interface_context = NULL_TREE;
2365                 }
2366
2367         | IMPLEMENTATION identifier '{'
2368                 {
2369                   objc_implementation_context = objc_ivar_context
2370                     = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2371                   objc_public_flag = 0;
2372                 }
2373           ivar_decl_list '}'
2374                 {
2375                   objc_ivar_chain
2376                     = continue_class (objc_implementation_context);
2377                 }
2378
2379         | IMPLEMENTATION identifier
2380                 {
2381                   objc_implementation_context
2382                     = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2383                   objc_ivar_chain
2384                     = continue_class (objc_implementation_context);
2385                 }
2386
2387         | IMPLEMENTATION identifier ':' identifier '{'
2388                 {
2389                   objc_implementation_context = objc_ivar_context
2390                     = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2391                   objc_public_flag = 0;
2392                 }
2393           ivar_decl_list '}'
2394                 {
2395                   objc_ivar_chain
2396                     = continue_class (objc_implementation_context);
2397                 }
2398
2399         | IMPLEMENTATION identifier ':' identifier
2400                 {
2401                   objc_implementation_context
2402                     = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2403                   objc_ivar_chain
2404                     = continue_class (objc_implementation_context);
2405                 }
2406
2407         | INTERFACE identifier '(' identifier ')' protocolrefs
2408                 {
2409                   objc_interface_context
2410                     = start_class (CATEGORY_INTERFACE_TYPE, $2, $4, $6);
2411                   continue_class (objc_interface_context);
2412                 }
2413           methodprotolist
2414           END
2415                 {
2416                   finish_class (objc_interface_context);
2417                   objc_interface_context = NULL_TREE;
2418                 }
2419
2420         | IMPLEMENTATION identifier '(' identifier ')'
2421                 {
2422                   objc_implementation_context
2423                     = start_class (CATEGORY_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2424                   objc_ivar_chain
2425                     = continue_class (objc_implementation_context);
2426                 }
2427         ;
2428
2429 protocoldef:
2430           PROTOCOL identifier protocolrefs
2431                 {
2432                   remember_protocol_qualifiers ();
2433                   objc_interface_context
2434                     = start_protocol(PROTOCOL_INTERFACE_TYPE, $2, $3);
2435                 }
2436           methodprotolist END
2437                 {
2438                   forget_protocol_qualifiers();
2439                   finish_protocol(objc_interface_context);
2440                   objc_interface_context = NULL_TREE;
2441                 }
2442         ;
2443
2444 protocolrefs:
2445           /* empty */
2446                 {
2447                   $$ = NULL_TREE;
2448                 }
2449         | non_empty_protocolrefs
2450         ;
2451
2452 non_empty_protocolrefs:
2453           ARITHCOMPARE identifier_list ARITHCOMPARE
2454                 {
2455                   if ($1 == LT_EXPR && $3 == GT_EXPR)
2456                     $$ = $2;
2457                   else
2458                     YYERROR1;
2459                 }
2460         ;
2461
2462 ivar_decl_list:
2463           ivar_decl_list visibility_spec ivar_decls
2464         | ivar_decls
2465         ;
2466
2467 visibility_spec:
2468           PRIVATE { objc_public_flag = 2; }
2469         | PROTECTED { objc_public_flag = 0; }
2470         | PUBLIC { objc_public_flag = 1; }
2471         ;
2472
2473 ivar_decls:
2474           /* empty */
2475                 {
2476                   $$ = NULL_TREE;
2477                 }
2478         | ivar_decls ivar_decl ';'
2479         | ivar_decls ';'
2480                 {
2481                   if (pedantic)
2482                     pedwarn ("extra semicolon in struct or union specified");
2483                 }
2484         ;
2485
2486
2487 /* There is a shift-reduce conflict here, because `components' may
2488    start with a `typename'.  It happens that shifting (the default resolution)
2489    does the right thing, because it treats the `typename' as part of
2490    a `typed_typespecs'.
2491
2492    It is possible that this same technique would allow the distinction
2493    between `notype_initdecls' and `initdecls' to be eliminated.
2494    But I am being cautious and not trying it.  */
2495
2496 ivar_decl:
2497         typed_typespecs setspecs ivars
2498                 { $$ = $3;
2499                   current_declspecs = TREE_VALUE (declspec_stack);
2500                   prefix_attributes = TREE_PURPOSE (declspec_stack);
2501                   declspec_stack = TREE_CHAIN (declspec_stack);
2502                   resume_momentary ($2); }
2503         | nonempty_type_quals setspecs ivars
2504                 { $$ = $3;
2505                   current_declspecs = TREE_VALUE (declspec_stack);
2506                   prefix_attributes = TREE_PURPOSE (declspec_stack);
2507                   declspec_stack = TREE_CHAIN (declspec_stack);
2508                   resume_momentary ($2); }
2509         | error
2510                 { $$ = NULL_TREE; }
2511         ;
2512
2513 ivars:
2514           /* empty */
2515                 { $$ = NULL_TREE; }
2516         | ivar_declarator
2517         | ivars ',' ivar_declarator
2518         ;
2519
2520 ivar_declarator:
2521           declarator
2522                 {
2523                   $$ = add_instance_variable (objc_ivar_context,
2524                                               objc_public_flag,
2525                                               $1, current_declspecs,
2526                                               NULL_TREE);
2527                 }
2528         | declarator ':' expr_no_commas
2529                 {
2530                   $$ = add_instance_variable (objc_ivar_context,
2531                                               objc_public_flag,
2532                                               $1, current_declspecs, $3);
2533                 }
2534         | ':' expr_no_commas
2535                 {
2536                   $$ = add_instance_variable (objc_ivar_context,
2537                                               objc_public_flag,
2538                                               NULL_TREE,
2539                                               current_declspecs, $2);
2540                 }
2541         ;
2542
2543 methoddef:
2544           '+'
2545                 {
2546                   remember_protocol_qualifiers ();
2547                   if (objc_implementation_context)
2548                     objc_inherit_code = CLASS_METHOD_DECL;
2549                   else
2550                     fatal ("method definition not in class context");
2551                 }
2552           methoddecl
2553                 {
2554                   forget_protocol_qualifiers ();
2555                   add_class_method (objc_implementation_context, $3);
2556                   start_method_def ($3);
2557                   objc_method_context = $3;
2558                 }
2559           optarglist
2560                 {
2561                   continue_method_def ();
2562                 }
2563           compstmt_or_error
2564                 {
2565                   finish_method_def ();
2566                   objc_method_context = NULL_TREE;
2567                 }
2568
2569         | '-'
2570                 {
2571                   remember_protocol_qualifiers ();
2572                   if (objc_implementation_context)
2573                     objc_inherit_code = INSTANCE_METHOD_DECL;
2574                   else
2575                     fatal ("method definition not in class context");
2576                 }
2577           methoddecl
2578                 {
2579                   forget_protocol_qualifiers ();
2580                   add_instance_method (objc_implementation_context, $3);
2581                   start_method_def ($3);
2582                   objc_method_context = $3;
2583                 }
2584           optarglist
2585                 {
2586                   continue_method_def ();
2587                 }
2588           compstmt_or_error
2589                 {
2590                   finish_method_def ();
2591                   objc_method_context = NULL_TREE;
2592                 }
2593         ;
2594
2595 /* the reason for the strange actions in this rule
2596  is so that notype_initdecls when reached via datadef
2597  can find a valid list of type and sc specs in $0. */
2598
2599 methodprotolist:
2600           /* empty  */
2601         | {$<ttype>$ = NULL_TREE; } methodprotolist2
2602         ;
2603
2604 methodprotolist2:                /* eliminates a shift/reduce conflict */
2605            methodproto
2606         |  datadef
2607         | methodprotolist2 methodproto
2608         | methodprotolist2 {$<ttype>$ = NULL_TREE; } datadef
2609         ;
2610
2611 semi_or_error:
2612           ';'
2613         | error
2614         ;
2615
2616 methodproto:
2617           '+'
2618                 {
2619                   objc_inherit_code = CLASS_METHOD_DECL;
2620                 }
2621           methoddecl
2622                 {
2623                   add_class_method (objc_interface_context, $3);
2624                 }
2625           semi_or_error
2626
2627         | '-'
2628                 {
2629                   objc_inherit_code = INSTANCE_METHOD_DECL;
2630                 }
2631           methoddecl
2632                 {
2633                   add_instance_method (objc_interface_context, $3);
2634                 }
2635           semi_or_error
2636         ;
2637
2638 methoddecl:
2639           '(' typename ')' unaryselector
2640                 {
2641                   $$ = build_method_decl (objc_inherit_code, $2, $4, NULL_TREE);
2642                 }
2643
2644         | unaryselector
2645                 {
2646                   $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, NULL_TREE);
2647                 }
2648
2649         | '(' typename ')' keywordselector optparmlist
2650                 {
2651                   $$ = build_method_decl (objc_inherit_code, $2, $4, $5);
2652                 }
2653
2654         | keywordselector optparmlist
2655                 {
2656                   $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, $2);
2657                 }
2658         ;
2659
2660 /* "optarglist" assumes that start_method_def has already been called...
2661    if it is not, the "xdecls" will not be placed in the proper scope */
2662
2663 optarglist:
2664           /* empty */
2665         | ';' myxdecls
2666         ;
2667
2668 /* to get around the following situation: "int foo (int a) int b; {}" that
2669    is synthesized when parsing "- a:a b:b; id c; id d; { ... }" */
2670
2671 myxdecls:
2672           /* empty */
2673         | mydecls
2674         ;
2675
2676 mydecls:
2677         mydecl
2678         | errstmt
2679         | mydecls mydecl
2680         | mydecl errstmt
2681         ;
2682
2683 mydecl:
2684         typed_declspecs setspecs myparms ';'
2685                 { current_declspecs = TREE_VALUE (declspec_stack);
2686                   prefix_attributes = TREE_PURPOSE (declspec_stack);
2687                   declspec_stack = TREE_CHAIN (declspec_stack);
2688                   resume_momentary ($2); }
2689         | typed_declspecs ';'
2690                 { shadow_tag ($1); }
2691         | declmods ';'
2692                 { pedwarn ("empty declaration"); }
2693         ;
2694
2695 myparms:
2696         myparm
2697                 { push_parm_decl ($1); }
2698         | myparms ',' myparm
2699                 { push_parm_decl ($3); }
2700         ;
2701
2702 /* A single parameter declaration or parameter type name,
2703    as found in a parmlist. DOES NOT ALLOW AN INITIALIZER OR ASMSPEC */
2704
2705 myparm:
2706           parm_declarator maybe_attribute
2707                 { $$ = build_tree_list (build_tree_list (current_declspecs,
2708                                                          $1),
2709                                         build_tree_list (prefix_attributes,
2710                                                          $2)); }
2711         | notype_declarator maybe_attribute
2712                 { $$ = build_tree_list (build_tree_list (current_declspecs,
2713                                                          $1),
2714                                         build_tree_list (prefix_attributes,
2715                                                          $2)); }
2716         | absdcl maybe_attribute
2717                 { $$ = build_tree_list (build_tree_list (current_declspecs,
2718                                                          $1),
2719                                         build_tree_list (prefix_attributes,
2720                                                          $2)); }
2721         ;
2722
2723 optparmlist:
2724           /* empty */
2725                 {
2726                   $$ = NULL_TREE;
2727                 }
2728         | ',' ELLIPSIS
2729                 {
2730                   /* oh what a kludge! */
2731                   $$ = (tree)1;
2732                 }
2733         | ','
2734                 {
2735                   pushlevel (0);
2736                 }
2737           parmlist_2
2738                 {
2739                   /* returns a tree list node generated by get_parm_info */
2740                   $$ = $3;
2741                   poplevel (0, 0, 0);
2742                 }
2743         ;
2744
2745 unaryselector:
2746           selector
2747         ;
2748
2749 keywordselector:
2750           keyworddecl
2751
2752         | keywordselector keyworddecl
2753                 {
2754                   $$ = chainon ($1, $2);
2755                 }
2756         ;
2757
2758 selector:
2759           IDENTIFIER
2760         | TYPENAME
2761         | OBJECTNAME
2762         | reservedwords
2763         ;
2764
2765 reservedwords:
2766           ENUM { $$ = get_identifier (token_buffer); }
2767         | STRUCT { $$ = get_identifier (token_buffer); }
2768         | UNION { $$ = get_identifier (token_buffer); }
2769         | IF { $$ = get_identifier (token_buffer); }
2770         | ELSE { $$ = get_identifier (token_buffer); }
2771         | WHILE { $$ = get_identifier (token_buffer); }
2772         | DO { $$ = get_identifier (token_buffer); }
2773         | FOR { $$ = get_identifier (token_buffer); }
2774         | SWITCH { $$ = get_identifier (token_buffer); }
2775         | CASE { $$ = get_identifier (token_buffer); }
2776         | DEFAULT { $$ = get_identifier (token_buffer); }
2777         | BREAK { $$ = get_identifier (token_buffer); }
2778         | CONTINUE { $$ = get_identifier (token_buffer); }
2779         | RETURN  { $$ = get_identifier (token_buffer); }
2780         | GOTO { $$ = get_identifier (token_buffer); }
2781         | ASM_KEYWORD { $$ = get_identifier (token_buffer); }
2782         | SIZEOF { $$ = get_identifier (token_buffer); }
2783         | TYPEOF { $$ = get_identifier (token_buffer); }
2784         | ALIGNOF { $$ = get_identifier (token_buffer); }
2785         | TYPESPEC | TYPE_QUAL
2786         ;
2787
2788 keyworddecl:
2789           selector ':' '(' typename ')' identifier
2790                 {
2791                   $$ = build_keyword_decl ($1, $4, $6);
2792                 }
2793
2794         | selector ':' identifier
2795                 {
2796                   $$ = build_keyword_decl ($1, NULL_TREE, $3);
2797                 }
2798
2799         | ':' '(' typename ')' identifier
2800                 {
2801                   $$ = build_keyword_decl (NULL_TREE, $3, $5);
2802                 }
2803
2804         | ':' identifier
2805                 {
2806                   $$ = build_keyword_decl (NULL_TREE, NULL_TREE, $2);
2807                 }
2808         ;
2809
2810 messageargs:
2811           selector
2812         | keywordarglist
2813         ;
2814
2815 keywordarglist:
2816           keywordarg
2817         | keywordarglist keywordarg
2818                 {
2819                   $$ = chainon ($1, $2);
2820                 }
2821         ;
2822
2823
2824 keywordexpr:
2825           nonnull_exprlist
2826                 {
2827                   if (TREE_CHAIN ($1) == NULL_TREE)
2828                     /* just return the expr., remove a level of indirection */
2829                     $$ = TREE_VALUE ($1);
2830                   else
2831                     /* we have a comma expr., we will collapse later */
2832                     $$ = $1;
2833                 }
2834         ;
2835
2836 keywordarg:
2837           selector ':' keywordexpr
2838                 {
2839                   $$ = build_tree_list ($1, $3);
2840                 }
2841         | ':' keywordexpr
2842                 {
2843                   $$ = build_tree_list (NULL_TREE, $2);
2844                 }
2845         ;
2846
2847 receiver:
2848           expr
2849         | CLASSNAME
2850                 {
2851                   $$ = get_class_reference ($1);
2852                 }
2853         ;
2854
2855 objcmessageexpr:
2856           '['
2857                 { objc_receiver_context = 1; }
2858           receiver
2859                 { objc_receiver_context = 0; }
2860           messageargs ']'
2861                 {
2862                   $$ = build_tree_list ($3, $5);
2863                 }
2864         ;
2865
2866 selectorarg:
2867           selector
2868         | keywordnamelist
2869         ;
2870
2871 keywordnamelist:
2872           keywordname
2873         | keywordnamelist keywordname
2874                 {
2875                   $$ = chainon ($1, $2);
2876                 }
2877         ;
2878
2879 keywordname:
2880           selector ':'
2881                 {
2882                   $$ = build_tree_list ($1, NULL_TREE);
2883                 }
2884         | ':'
2885                 {
2886                   $$ = build_tree_list (NULL_TREE, NULL_TREE);
2887                 }
2888         ;
2889
2890 objcselectorexpr:
2891           SELECTOR '(' selectorarg ')'
2892                 {
2893                   $$ = $3;
2894                 }
2895         ;
2896
2897 objcprotocolexpr:
2898           PROTOCOL '(' identifier ')'
2899                 {
2900                   $$ = $3;
2901                 }
2902         ;
2903
2904 /* extension to support C-structures in the archiver */
2905
2906 objcencodeexpr:
2907           ENCODE '(' typename ')'
2908                 {
2909                   $$ = groktypename ($3);
2910                 }
2911         ;
2912
2913 end ifobjc
2914 %%