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