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