OSDN Git Service

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