OSDN Git Service

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