OSDN Git Service

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