OSDN Git Service

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