OSDN Git Service

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