OSDN Git Service

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