OSDN Git Service

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