OSDN Git Service

* basic-block.h: Convert prototypes to ISO C90.
[pf3gnuchains/gcc-fork.git] / gcc / c-parse.in
1 /* YACC parser for C syntax and for Objective C.  -*-c-*-
2    Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996,
3    1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING.  If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.  */
21
22 /* This file defines the grammar of C and that of Objective C.
23    ifobjc ... end ifobjc  conditionals contain code for Objective C only.
24    ifc ... end ifc  conditionals contain code for C only.
25    Sed commands in Makefile.in are used to convert this file into
26    c-parse.y and into objc-parse.y.  */
27
28 /* To whomever it may concern: I have heard that such a thing was once
29    written by AT&T, but I have never seen it.  */
30
31 ifc
32 %expect 10 /* shift/reduce conflicts, and no reduce/reduce conflicts.  */
33 end ifc
34
35 %{
36 #include "config.h"
37 #include "system.h"
38 #include "coretypes.h"
39 #include "tm.h"
40 #include "tree.h"
41 #include "input.h"
42 #include "cpplib.h"
43 #include "intl.h"
44 #include "timevar.h"
45 #include "c-pragma.h"           /* For YYDEBUG definition, and parse_in.  */
46 #include "c-tree.h"
47 #include "flags.h"
48 #include "varray.h"
49 #include "output.h"
50 #include "toplev.h"
51 #include "ggc.h"
52
53 ifobjc
54 #include "objc-act.h"
55 end ifobjc
56
57 /* Like YYERROR but do call yyerror.  */
58 #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
59
60 /* Like the default stack expander, except (1) use realloc when possible,
61    (2) impose no hard maxiumum on stack size, (3) REALLY do not use alloca.
62
63    Irritatingly, YYSTYPE is defined after this %{ %} block, so we cannot
64    give malloced_yyvs its proper type.  This is ok since all we need from
65    it is to be able to free it.  */
66
67 static short *malloced_yyss;
68 static void *malloced_yyvs;
69
70 #define yyoverflow(MSG, SS, SSSIZE, VS, VSSIZE, YYSSZ)                  \
71 do {                                                                    \
72   size_t newsize;                                                       \
73   short *newss;                                                         \
74   YYSTYPE *newvs;                                                       \
75   newsize = *(YYSSZ) *= 2;                                              \
76   if (malloced_yyss)                                                    \
77     {                                                                   \
78       newss = (short *)                                                 \
79         really_call_realloc (*(SS), newsize * sizeof (short));          \
80       newvs = (YYSTYPE *)                                               \
81         really_call_realloc (*(VS), newsize * sizeof (YYSTYPE));        \
82     }                                                                   \
83   else                                                                  \
84     {                                                                   \
85       newss = (short *) really_call_malloc (newsize * sizeof (short));  \
86       newvs = (YYSTYPE *) really_call_malloc (newsize * sizeof (YYSTYPE)); \
87       if (newss)                                                        \
88         memcpy (newss, *(SS), (SSSIZE));                                \
89       if (newvs)                                                        \
90         memcpy (newvs, *(VS), (VSSIZE));                                \
91     }                                                                   \
92   if (!newss || !newvs)                                                 \
93     {                                                                   \
94       yyerror (MSG);                                                    \
95       return 2;                                                         \
96     }                                                                   \
97   *(SS) = newss;                                                        \
98   *(VS) = newvs;                                                        \
99   malloced_yyss = newss;                                                \
100   malloced_yyvs = (void *) newvs;                                       \
101 } while (0)
102 %}
103
104 %start program
105
106 %union {long itype; tree ttype; enum tree_code code;
107         location_t location; }
108
109 /* All identifiers that are not reserved words
110    and are not declared typedefs in the current block */
111 %token IDENTIFIER
112
113 /* All identifiers that are declared typedefs in the current block.
114    In some contexts, they are treated just like IDENTIFIER,
115    but they can also serve as typespecs in declarations.  */
116 %token TYPENAME
117
118 /* Reserved words that specify storage class.
119    yylval contains an IDENTIFIER_NODE which indicates which one.  */
120 %token SCSPEC                   /* Storage class other than static.  */
121 %token STATIC                   /* Static storage class.  */
122
123 /* Reserved words that specify type.
124    yylval contains an IDENTIFIER_NODE which indicates which one.  */
125 %token TYPESPEC
126
127 /* Reserved words that qualify type: "const", "volatile", or "restrict".
128    yylval contains an IDENTIFIER_NODE which indicates which one.  */
129 %token TYPE_QUAL
130
131 /* Character or numeric constants.
132    yylval is the node for the constant.  */
133 %token CONSTANT
134
135 /* String constants in raw form.
136    yylval is a STRING_CST node.  */
137
138 %token STRING
139
140 /* "...", used for functions with variable arglists.  */
141 %token ELLIPSIS
142
143 /* the reserved words */
144 /* SCO include files test "ASM", so use something else. */
145 %token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
146 %token BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF
147 %token ATTRIBUTE EXTENSION LABEL
148 %token REALPART IMAGPART VA_ARG CHOOSE_EXPR TYPES_COMPATIBLE_P
149 %token PTR_VALUE PTR_BASE PTR_EXTENT
150 %token FUNC_NAME
151
152 /* Add precedence rules to solve dangling else s/r conflict */
153 %nonassoc IF
154 %nonassoc ELSE
155
156 /* Define the operator tokens and their precedences.
157    The value is an integer because, if used, it is the tree code
158    to use in the expression made from the operator.  */
159
160 %right <code> ASSIGN '='
161 %right <code> '?' ':'
162 %left <code> OROR
163 %left <code> ANDAND
164 %left <code> '|'
165 %left <code> '^'
166 %left <code> '&'
167 %left <code> EQCOMPARE
168 %left <code> ARITHCOMPARE
169 %left <code> LSHIFT RSHIFT
170 %left <code> '+' '-'
171 %left <code> '*' '/' '%'
172 %right <code> UNARY PLUSPLUS MINUSMINUS
173 %left HYPERUNARY
174 %left <code> POINTSAT '.' '(' '['
175
176 /* The Objective-C keywords.  These are included in C and in
177    Objective C, so that the token codes are the same in both.  */
178 %token INTERFACE IMPLEMENTATION END SELECTOR DEFS ENCODE
179 %token CLASSNAME PUBLIC PRIVATE PROTECTED PROTOCOL OBJECTNAME CLASS ALIAS
180 %token OBJC_STRING
181
182 %type <code> unop
183 %type <ttype> ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
184 %type <ttype> BREAK CONTINUE RETURN GOTO ASM_KEYWORD SIZEOF TYPEOF ALIGNOF
185
186 %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist
187 %type <ttype> expr_no_commas cast_expr unary_expr primary STRING
188 %type <ttype> declspecs_nosc_nots_nosa_noea declspecs_nosc_nots_nosa_ea
189 %type <ttype> declspecs_nosc_nots_sa_noea declspecs_nosc_nots_sa_ea
190 %type <ttype> declspecs_nosc_ts_nosa_noea declspecs_nosc_ts_nosa_ea
191 %type <ttype> declspecs_nosc_ts_sa_noea declspecs_nosc_ts_sa_ea
192 %type <ttype> declspecs_sc_nots_nosa_noea declspecs_sc_nots_nosa_ea
193 %type <ttype> declspecs_sc_nots_sa_noea declspecs_sc_nots_sa_ea
194 %type <ttype> declspecs_sc_ts_nosa_noea declspecs_sc_ts_nosa_ea
195 %type <ttype> declspecs_sc_ts_sa_noea declspecs_sc_ts_sa_ea
196 %type <ttype> declspecs_ts declspecs_nots
197 %type <ttype> declspecs_ts_nosa declspecs_nots_nosa
198 %type <ttype> declspecs_nosc_ts declspecs_nosc_nots declspecs_nosc declspecs
199 %type <ttype> maybe_type_quals_attrs typespec_nonattr typespec_attr
200 %type <ttype> typespec_reserved_nonattr typespec_reserved_attr
201 %type <ttype> typespec_nonreserved_nonattr
202
203 %type <ttype> scspec SCSPEC STATIC TYPESPEC TYPE_QUAL maybe_type_qual
204 %type <ttype> initdecls notype_initdecls initdcl notype_initdcl
205 %type <ttype> init maybeasm
206 %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
207 %type <ttype> maybe_attribute attributes attribute attribute_list attrib
208 %type <ttype> any_word extension
209
210 %type <ttype> compstmt compstmt_start compstmt_nostart compstmt_primary_start
211 %type <ttype> do_stmt_start poplevel stmt label
212
213 %type <ttype> c99_block_start c99_block_end
214 %type <ttype> declarator
215 %type <ttype> notype_declarator after_type_declarator
216 %type <ttype> parm_declarator
217 %type <ttype> parm_declarator_starttypename parm_declarator_nostarttypename
218 %type <ttype> array_declarator
219
220 %type <ttype> structsp_attr structsp_nonattr
221 %type <ttype> component_decl_list component_decl_list2
222 %type <ttype> component_decl components components_notype component_declarator
223 %type <ttype> component_notype_declarator
224 %type <ttype> enumlist enumerator
225 %type <ttype> struct_head union_head enum_head
226 %type <ttype> typename absdcl absdcl1 absdcl1_ea absdcl1_noea
227 %type <ttype> direct_absdcl1 absdcl_maybe_attribute
228 %type <ttype> xexpr parms parm firstparm identifiers
229
230 %type <ttype> parmlist parmlist_1 parmlist_2
231 %type <ttype> parmlist_or_identifiers parmlist_or_identifiers_1
232 %type <ttype> identifiers_or_typenames
233
234 %type <itype> setspecs setspecs_fp
235
236 %type <location> save_location
237 \f
238 ifobjc
239 /* the Objective-C nonterminals */
240
241 %type <ttype> ivar_decl_list ivar_decls ivar_decl ivars ivar_declarator
242 %type <ttype> methoddecl unaryselector keywordselector selector
243 %type <ttype> keyworddecl receiver objcmessageexpr messageargs
244 %type <ttype> keywordexpr keywordarglist keywordarg
245 %type <ttype> myparms myparm optparmlist reservedwords objcselectorexpr
246 %type <ttype> selectorarg keywordnamelist keywordname objcencodeexpr
247 %type <ttype> non_empty_protocolrefs protocolrefs identifier_list objcprotocolexpr
248
249 %type <ttype> CLASSNAME OBJECTNAME OBJC_STRING
250 end ifobjc
251 \f
252 %{
253 /* Number of statements (loosely speaking) and compound statements
254    seen so far.  */
255 static int stmt_count;
256 static int compstmt_count;
257
258 /* Input location of the end of the body of last simple_if;
259    used by the stmt-rule immediately after simple_if returns.  */
260 static location_t if_stmt_locus;
261
262
263 /* List of types and structure classes of the current declaration.  */
264 static GTY(()) tree current_declspecs;
265 static GTY(()) tree prefix_attributes;
266
267 /* List of all the attributes applying to the identifier currently being
268    declared; includes prefix_attributes and possibly some more attributes
269    just after a comma.  */
270 static GTY(()) tree all_prefix_attributes;
271
272 /* Stack of saved values of current_declspecs, prefix_attributes and
273    all_prefix_attributes.  */
274 static GTY(()) tree declspec_stack;
275
276 /* PUSH_DECLSPEC_STACK is called from setspecs; POP_DECLSPEC_STACK
277    should be called from the productions making use of setspecs.  */
278 #define PUSH_DECLSPEC_STACK                                              \
279   do {                                                                   \
280     declspec_stack = tree_cons (build_tree_list (prefix_attributes,      \
281                                                  all_prefix_attributes), \
282                                 current_declspecs,                       \
283                                 declspec_stack);                         \
284   } while (0)
285
286 #define POP_DECLSPEC_STACK                                              \
287   do {                                                                  \
288     current_declspecs = TREE_VALUE (declspec_stack);                    \
289     prefix_attributes = TREE_PURPOSE (TREE_PURPOSE (declspec_stack));   \
290     all_prefix_attributes = TREE_VALUE (TREE_PURPOSE (declspec_stack)); \
291     declspec_stack = TREE_CHAIN (declspec_stack);                       \
292   } while (0)
293
294 /* For __extension__, save/restore the warning flags which are
295    controlled by __extension__.  */
296 #define SAVE_EXT_FLAGS()                        \
297         size_int (pedantic                      \
298                   | (warn_pointer_arith << 1)   \
299                   | (warn_traditional << 2)     \
300                   | (flag_iso << 3))
301
302 #define RESTORE_EXT_FLAGS(tval)                 \
303   do {                                          \
304     int val = tree_low_cst (tval, 0);           \
305     pedantic = val & 1;                         \
306     warn_pointer_arith = (val >> 1) & 1;        \
307     warn_traditional = (val >> 2) & 1;          \
308     flag_iso = (val >> 3) & 1;                  \
309   } while (0)
310
311 ifobjc
312 /* Objective-C specific parser/lexer information */
313
314 static enum tree_code objc_inherit_code;
315 static int objc_pq_context = 0, objc_public_flag = 0;
316
317 /* The following flag is needed to contextualize ObjC lexical analysis.
318    In some cases (e.g., 'int NSObject;'), it is undesirable to bind
319    an identifier to an ObjC class, even if a class with that name
320    exists.  */
321 static int objc_need_raw_identifier;
322 #define OBJC_NEED_RAW_IDENTIFIER(VAL)   objc_need_raw_identifier = VAL
323 end ifobjc
324
325 ifc
326 #define OBJC_NEED_RAW_IDENTIFIER(VAL)   /* nothing */
327 end ifc
328
329 static bool parsing_iso_function_signature;
330
331 /* Tell yyparse how to print a token's value, if yydebug is set.  */
332
333 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
334
335 static void yyprint (FILE *, int, YYSTYPE);
336 static void yyerror (const char *);
337 static int yylexname (void);
338 static inline int _yylex (void);
339 static int  yylex (void);
340 static void init_reswords (void);
341
342   /* Initialisation routine for this file.  */
343 void
344 c_parse_init (void)
345 {
346   init_reswords ();
347 }
348
349 %}
350 \f
351 %%
352 program: /* empty */
353                 { if (pedantic)
354                     pedwarn ("ISO C forbids an empty source file");
355                   finish_file ();
356                 }
357         | extdefs
358                 {
359                   /* In case there were missing closebraces,
360                      get us back to the global binding level.  */
361                   while (! global_bindings_p ())
362                     poplevel (0, 0, 0);
363                   /* __FUNCTION__ is defined at file scope ("").  This
364                      call may not be necessary as my tests indicate it
365                      still works without it.  */
366                   finish_fname_decls ();
367                   finish_file ();
368                 }
369         ;
370
371 /* the reason for the strange actions in this rule
372  is so that notype_initdecls when reached via datadef
373  can find a valid list of type and sc specs in $0. */
374
375 extdefs:
376         {$<ttype>$ = NULL_TREE; } extdef
377         | extdefs {$<ttype>$ = NULL_TREE; ggc_collect(); } extdef
378         ;
379
380 extdef:
381         extdef_1
382         { parsing_iso_function_signature = false; } /* Reset after any external definition.  */
383         ;
384
385 extdef_1:
386         fndef
387         | datadef
388 ifobjc
389         | objcdef
390 end ifobjc
391         | ASM_KEYWORD '(' expr ')' ';'
392                 { STRIP_NOPS ($3);
393                   if ((TREE_CODE ($3) == ADDR_EXPR
394                        && TREE_CODE (TREE_OPERAND ($3, 0)) == STRING_CST)
395                       || TREE_CODE ($3) == STRING_CST)
396                     assemble_asm ($3);
397                   else
398                     error ("argument of `asm' is not a constant string"); }
399         | extension extdef
400                 { RESTORE_EXT_FLAGS ($1); }
401         ;
402
403 datadef:
404           setspecs notype_initdecls ';'
405                 { if (pedantic)
406                     error ("ISO C forbids data definition with no type or storage class");
407                   else
408                     warning ("data definition has no type or storage class");
409
410                   POP_DECLSPEC_STACK; }
411         | declspecs_nots setspecs notype_initdecls ';'
412                 { POP_DECLSPEC_STACK; }
413         | declspecs_ts setspecs initdecls ';'
414                 { POP_DECLSPEC_STACK; }
415         | declspecs ';'
416           { shadow_tag ($1); }
417         | error ';'
418         | error '}'
419         | ';'
420                 { if (pedantic)
421                     pedwarn ("ISO C does not allow extra `;' outside of a function"); }
422         ;
423 \f
424 fndef:
425           declspecs_ts setspecs declarator
426                 { if (! start_function (current_declspecs, $3,
427                                         all_prefix_attributes))
428                     YYERROR1;
429                 }
430           old_style_parm_decls save_location
431                 { DECL_SOURCE_LOCATION (current_function_decl) = $6;
432                   store_parm_decls (); }
433           compstmt_or_error
434                 { finish_function (0, 1);
435                   POP_DECLSPEC_STACK; }
436         | declspecs_ts setspecs declarator error
437                 { POP_DECLSPEC_STACK; }
438         | declspecs_nots setspecs notype_declarator
439                 { if (! start_function (current_declspecs, $3,
440                                         all_prefix_attributes))
441                     YYERROR1;
442                 }
443           old_style_parm_decls save_location
444                 { DECL_SOURCE_LOCATION (current_function_decl) = $6;
445                   store_parm_decls (); }
446           compstmt_or_error
447                 { finish_function (0, 1);
448                   POP_DECLSPEC_STACK; }
449         | declspecs_nots setspecs notype_declarator error
450                 { POP_DECLSPEC_STACK; }
451         | setspecs notype_declarator
452                 { if (! start_function (NULL_TREE, $2,
453                                         all_prefix_attributes))
454                     YYERROR1;
455                 }
456           old_style_parm_decls save_location
457                 { DECL_SOURCE_LOCATION (current_function_decl) = $5;
458                   store_parm_decls (); }
459           compstmt_or_error
460                 { finish_function (0, 1);
461                   POP_DECLSPEC_STACK; }
462         | setspecs notype_declarator error
463                 { POP_DECLSPEC_STACK; }
464         ;
465
466 identifier:
467         IDENTIFIER
468         | TYPENAME
469 ifobjc
470         | OBJECTNAME
471         | CLASSNAME
472 end ifobjc
473         ;
474
475 unop:     '&'
476                 { $$ = ADDR_EXPR; }
477         | '-'
478                 { $$ = NEGATE_EXPR; }
479         | '+'
480                 { $$ = CONVERT_EXPR;
481 ifc
482   if (warn_traditional && !in_system_header)
483     warning ("traditional C rejects the unary plus operator");
484 end ifc
485                 }
486         | PLUSPLUS
487                 { $$ = PREINCREMENT_EXPR; }
488         | MINUSMINUS
489                 { $$ = PREDECREMENT_EXPR; }
490         | '~'
491                 { $$ = BIT_NOT_EXPR; }
492         | '!'
493                 { $$ = TRUTH_NOT_EXPR; }
494         ;
495
496 expr:   nonnull_exprlist
497                 { $$ = build_compound_expr ($1); }
498         ;
499
500 exprlist:
501           /* empty */
502                 { $$ = NULL_TREE; }
503         | nonnull_exprlist
504         ;
505
506 nonnull_exprlist:
507         expr_no_commas
508                 { $$ = build_tree_list (NULL_TREE, $1); }
509         | nonnull_exprlist ',' expr_no_commas
510                 { chainon ($1, build_tree_list (NULL_TREE, $3)); }
511         ;
512
513 unary_expr:
514         primary
515         | '*' cast_expr   %prec UNARY
516                 { $$ = build_indirect_ref ($2, "unary *"); }
517         /* __extension__ turns off -pedantic for following primary.  */
518         | extension cast_expr     %prec UNARY
519                 { $$ = $2;
520                   RESTORE_EXT_FLAGS ($1); }
521         | unop cast_expr  %prec UNARY
522                 { $$ = build_unary_op ($1, $2, 0);
523                   overflow_warning ($$); }
524         /* Refer to the address of a label as a pointer.  */
525         | ANDAND identifier
526                 { $$ = finish_label_address_expr ($2); }
527         | sizeof unary_expr  %prec UNARY
528                 { skip_evaluation--;
529                   if (TREE_CODE ($2) == COMPONENT_REF
530                       && DECL_C_BIT_FIELD (TREE_OPERAND ($2, 1)))
531                     error ("`sizeof' applied to a bit-field");
532                   $$ = c_sizeof (TREE_TYPE ($2)); }
533         | sizeof '(' typename ')'  %prec HYPERUNARY
534                 { skip_evaluation--;
535                   $$ = c_sizeof (groktypename ($3)); }
536         | alignof unary_expr  %prec UNARY
537                 { skip_evaluation--;
538                   $$ = c_alignof_expr ($2); }
539         | alignof '(' typename ')'  %prec HYPERUNARY
540                 { skip_evaluation--;
541                   $$ = c_alignof (groktypename ($3)); }
542         | REALPART cast_expr %prec UNARY
543                 { $$ = build_unary_op (REALPART_EXPR, $2, 0); }
544         | IMAGPART cast_expr %prec UNARY
545                 { $$ = build_unary_op (IMAGPART_EXPR, $2, 0); }
546         ;
547
548 sizeof:
549         SIZEOF { skip_evaluation++; }
550         ;
551
552 alignof:
553         ALIGNOF { skip_evaluation++; }
554         ;
555
556 typeof:
557         TYPEOF { skip_evaluation++; }
558         ;
559
560 cast_expr:
561         unary_expr
562         | '(' typename ')' cast_expr  %prec UNARY
563                 { $$ = c_cast_expr ($2, $4); }
564         ;
565
566 expr_no_commas:
567           cast_expr
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 '/' expr_no_commas
575                 { $$ = parser_build_binary_op ($2, $1, $3); }
576         | expr_no_commas '%' expr_no_commas
577                 { $$ = parser_build_binary_op ($2, $1, $3); }
578         | expr_no_commas LSHIFT expr_no_commas
579                 { $$ = parser_build_binary_op ($2, $1, $3); }
580         | expr_no_commas RSHIFT expr_no_commas
581                 { $$ = parser_build_binary_op ($2, $1, $3); }
582         | expr_no_commas ARITHCOMPARE expr_no_commas
583                 { $$ = parser_build_binary_op ($2, $1, $3); }
584         | expr_no_commas EQCOMPARE expr_no_commas
585                 { $$ = parser_build_binary_op ($2, $1, $3); }
586         | expr_no_commas '&' expr_no_commas
587                 { $$ = parser_build_binary_op ($2, $1, $3); }
588         | expr_no_commas '|' expr_no_commas
589                 { $$ = parser_build_binary_op ($2, $1, $3); }
590         | expr_no_commas '^' expr_no_commas
591                 { $$ = parser_build_binary_op ($2, $1, $3); }
592         | expr_no_commas ANDAND
593                 { $1 = c_common_truthvalue_conversion
594                     (default_conversion ($1));
595                   skip_evaluation += $1 == boolean_false_node; }
596           expr_no_commas
597                 { skip_evaluation -= $1 == boolean_false_node;
598                   $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $4); }
599         | expr_no_commas OROR
600                 { $1 = c_common_truthvalue_conversion
601                     (default_conversion ($1));
602                   skip_evaluation += $1 == boolean_true_node; }
603           expr_no_commas
604                 { skip_evaluation -= $1 == boolean_true_node;
605                   $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $4); }
606         | expr_no_commas '?'
607                 { $1 = c_common_truthvalue_conversion
608                     (default_conversion ($1));
609                   skip_evaluation += $1 == boolean_false_node; }
610           expr ':'
611                 { skip_evaluation += (($1 == boolean_true_node)
612                                       - ($1 == boolean_false_node)); }
613           expr_no_commas
614                 { skip_evaluation -= $1 == boolean_true_node;
615                   $$ = build_conditional_expr ($1, $4, $7); }
616         | expr_no_commas '?'
617                 { if (pedantic)
618                     pedwarn ("ISO C forbids omitting the middle term of a ?: expression");
619                   /* Make sure first operand is calculated only once.  */
620                   $<ttype>2 = save_expr ($1);
621                   $1 = c_common_truthvalue_conversion
622                     (default_conversion ($<ttype>2));
623                   skip_evaluation += $1 == boolean_true_node; }
624           ':' expr_no_commas
625                 { skip_evaluation -= $1 == boolean_true_node;
626                   $$ = build_conditional_expr ($1, $<ttype>2, $5); }
627         | expr_no_commas '=' expr_no_commas
628                 { char class;
629                   $$ = build_modify_expr ($1, NOP_EXPR, $3);
630                   class = TREE_CODE_CLASS (TREE_CODE ($$));
631                   if (IS_EXPR_CODE_CLASS (class))
632                     C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR);
633                 }
634         | expr_no_commas ASSIGN expr_no_commas
635                 { char class;
636                   $$ = build_modify_expr ($1, $2, $3);
637                   /* This inhibits warnings in
638                      c_common_truthvalue_conversion.  */
639                   class = TREE_CODE_CLASS (TREE_CODE ($$));
640                   if (IS_EXPR_CODE_CLASS (class))
641                     C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK);
642                 }
643         ;
644
645 primary:
646         IDENTIFIER
647                 {
648                   if (yychar == YYEMPTY)
649                     yychar = YYLEX;
650                   $$ = build_external_ref ($1, yychar == '(');
651                 }
652         | CONSTANT
653         | STRING
654         | FUNC_NAME
655                 { $$ = fname_decl (C_RID_CODE ($$), $$); }
656         | '(' typename ')' '{'
657                 { start_init (NULL_TREE, NULL, 0);
658                   $2 = groktypename ($2);
659                   really_start_incremental_init ($2); }
660           initlist_maybe_comma '}'  %prec UNARY
661                 { tree constructor = pop_init_level (0);
662                   tree type = $2;
663                   finish_init ();
664
665                   if (pedantic && ! flag_isoc99)
666                     pedwarn ("ISO C89 forbids compound literals");
667                   $$ = build_compound_literal (type, constructor);
668                 }
669         | '(' expr ')'
670                 { char class = TREE_CODE_CLASS (TREE_CODE ($2));
671                   if (IS_EXPR_CODE_CLASS (class))
672                     C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK);
673                   $$ = $2; }
674         | '(' error ')'
675                 { $$ = error_mark_node; }
676         | compstmt_primary_start compstmt_nostart ')'
677                  { tree saved_last_tree;
678
679                    if (pedantic)
680                      pedwarn ("ISO C forbids braced-groups within expressions");
681                   pop_label_level ();
682
683                   saved_last_tree = COMPOUND_BODY ($1);
684                   RECHAIN_STMTS ($1, COMPOUND_BODY ($1));
685                   last_tree = saved_last_tree;
686                   TREE_CHAIN (last_tree) = NULL_TREE;
687                   if (!last_expr_type)
688                     last_expr_type = void_type_node;
689                   $$ = build1 (STMT_EXPR, last_expr_type, $1);
690                   TREE_SIDE_EFFECTS ($$) = 1;
691                 }
692         | compstmt_primary_start error ')'
693                 {
694                   pop_label_level ();
695                   last_tree = COMPOUND_BODY ($1);
696                   TREE_CHAIN (last_tree) = NULL_TREE;
697                   $$ = error_mark_node;
698                 }
699         | primary '(' exprlist ')'   %prec '.'
700                 { $$ = build_function_call ($1, $3); }
701         | VA_ARG '(' expr_no_commas ',' typename ')'
702                 { $$ = build_va_arg ($3, groktypename ($5)); }
703
704       | CHOOSE_EXPR '(' expr_no_commas ',' expr_no_commas ',' expr_no_commas ')'
705                 {
706                   tree c;
707
708                   c = fold ($3);
709                   STRIP_NOPS (c);
710                   if (TREE_CODE (c) != INTEGER_CST)
711                     error ("first argument to __builtin_choose_expr not a constant");
712                   $$ = integer_zerop (c) ? $7 : $5;
713                 }
714       | TYPES_COMPATIBLE_P '(' typename ',' typename ')'
715                 {
716                   tree e1, e2;
717
718                   e1 = TYPE_MAIN_VARIANT (groktypename ($3));
719                   e2 = TYPE_MAIN_VARIANT (groktypename ($5));
720
721                   $$ = comptypes (e1, e2)
722                     ? build_int_2 (1, 0) : build_int_2 (0, 0);
723                 }
724         | primary '[' expr ']'   %prec '.'
725                 { $$ = build_array_ref ($1, $3); }
726         | primary '.' identifier
727                 {
728 ifobjc
729                     if (!is_public ($1, $3))
730                       $$ = error_mark_node;
731                     else
732 end ifobjc
733                       $$ = build_component_ref ($1, $3);
734                 }
735         | primary POINTSAT identifier
736                 {
737                   tree expr = build_indirect_ref ($1, "->");
738
739 ifobjc
740                       if (!is_public (expr, $3))
741                         $$ = error_mark_node;
742                       else
743 end ifobjc
744                         $$ = build_component_ref (expr, $3);
745                 }
746         | primary PLUSPLUS
747                 { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
748         | primary MINUSMINUS
749                 { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
750 ifobjc
751         | objcmessageexpr
752                 { $$ = build_message_expr ($1); }
753         | objcselectorexpr
754                 { $$ = build_selector_expr ($1); }
755         | objcprotocolexpr
756                 { $$ = build_protocol_expr ($1); }
757         | objcencodeexpr
758                 { $$ = build_encode_expr ($1); }
759         | OBJC_STRING
760                 { $$ = build_objc_string_object ($1); }
761 end ifobjc
762         ;
763
764 old_style_parm_decls:
765         old_style_parm_decls_1
766         {
767           parsing_iso_function_signature = false; /* Reset after decls.  */
768         }
769         ;
770
771 old_style_parm_decls_1:
772         /* empty */
773         {
774           if (warn_traditional && !in_system_header
775               && parsing_iso_function_signature)
776             warning ("traditional C rejects ISO C style function definitions");
777           parsing_iso_function_signature = false; /* Reset after warning.  */
778         }
779         | datadecls
780         ;
781
782 /* The following are analogous to lineno_decl, decls and decl
783    except that they do not allow nested functions.
784    They are used for old-style parm decls.  */
785 lineno_datadecl:
786           save_location datadecl
787                 { }
788         ;
789
790 datadecls:
791         lineno_datadecl
792         | errstmt
793         | datadecls lineno_datadecl
794         | lineno_datadecl errstmt
795         ;
796
797 /* We don't allow prefix attributes here because they cause reduce/reduce
798    conflicts: we can't know whether we're parsing a function decl with
799    attribute suffix, or function defn with attribute prefix on first old
800    style parm.  */
801 datadecl:
802         declspecs_ts_nosa setspecs initdecls ';'
803                 { POP_DECLSPEC_STACK; }
804         | declspecs_nots_nosa setspecs notype_initdecls ';'
805                 { POP_DECLSPEC_STACK; }
806         | declspecs_ts_nosa ';'
807                 { shadow_tag_warned ($1, 1);
808                   pedwarn ("empty declaration"); }
809         | declspecs_nots_nosa ';'
810                 { pedwarn ("empty declaration"); }
811         ;
812
813 /* This combination which saves a lineno before a decl
814    is the normal thing to use, rather than decl itself.
815    This is to avoid shift/reduce conflicts in contexts
816    where statement labels are allowed.  */
817 lineno_decl:
818           save_location decl
819                 { }
820         ;
821
822 /* records the type and storage class specs to use for processing
823    the declarators that follow.
824    Maintains a stack of outer-level values of current_declspecs,
825    for the sake of parm declarations nested in function declarators.  */
826 setspecs: /* empty */
827                 { pending_xref_error ();
828                   PUSH_DECLSPEC_STACK;
829                   split_specs_attrs ($<ttype>0,
830                                      &current_declspecs, &prefix_attributes);
831                   all_prefix_attributes = prefix_attributes; }
832         ;
833
834 /* Possibly attributes after a comma, which should reset all_prefix_attributes
835    to prefix_attributes with these ones chained on the front.  */
836 maybe_resetattrs:
837           maybe_attribute
838                 { all_prefix_attributes = chainon ($1, prefix_attributes); }
839         ;
840
841 decl:
842         declspecs_ts setspecs initdecls ';'
843                 { POP_DECLSPEC_STACK; }
844         | declspecs_nots setspecs notype_initdecls ';'
845                 { POP_DECLSPEC_STACK; }
846         | declspecs_ts setspecs nested_function
847                 { POP_DECLSPEC_STACK; }
848         | declspecs_nots setspecs notype_nested_function
849                 { POP_DECLSPEC_STACK; }
850         | declspecs ';'
851                 { shadow_tag ($1); }
852         | extension decl
853                 { RESTORE_EXT_FLAGS ($1); }
854         ;
855
856 /* A list of declaration specifiers.  These are:
857
858    - Storage class specifiers (scspec), which for GCC currently includes
859    function specifiers ("inline").
860
861    - Type specifiers (typespec_*).
862
863    - Type qualifiers (TYPE_QUAL).
864
865    - Attribute specifier lists (attributes).
866
867    These are stored as a TREE_LIST; the head of the list is the last
868    item in the specifier list.  Each entry in the list has either a
869    TREE_PURPOSE that is an attribute specifier list, or a TREE_VALUE that
870    is a single other specifier or qualifier; and a TREE_CHAIN that is the
871    rest of the list.  TREE_STATIC is set on the list if something other
872    than a storage class specifier or attribute has been seen; this is used
873    to warn for the obsolescent usage of storage class specifiers other than
874    at the start of the list.  (Doing this properly would require function
875    specifiers to be handled separately from storage class specifiers.)
876
877    The various cases below are classified according to:
878
879    (a) Whether a storage class specifier is included or not; some
880    places in the grammar disallow storage class specifiers (_sc or _nosc).
881
882    (b) Whether a type specifier has been seen; after a type specifier,
883    a typedef name is an identifier to redeclare (_ts or _nots).
884
885    (c) Whether the list starts with an attribute; in certain places,
886    the grammar requires specifiers that don't start with an attribute
887    (_sa or _nosa).
888
889    (d) Whether the list ends with an attribute (or a specifier such that
890    any following attribute would have been parsed as part of that specifier);
891    this avoids shift-reduce conflicts in the parsing of attributes
892    (_ea or _noea).
893
894    TODO:
895
896    (i) Distinguish between function specifiers and storage class specifiers,
897    at least for the purpose of warnings about obsolescent usage.
898
899    (ii) Halve the number of productions here by eliminating the _sc/_nosc
900    distinction and instead checking where required that storage class
901    specifiers aren't present.  */
902
903 /* Declspecs which contain at least one type specifier or typedef name.
904    (Just `const' or `volatile' is not enough.)
905    A typedef'd name following these is taken as a name to be declared.
906    Declspecs have a non-NULL TREE_VALUE, attributes do not.  */
907
908 declspecs_nosc_nots_nosa_noea:
909           TYPE_QUAL
910                 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
911                   TREE_STATIC ($$) = 1; }
912         | declspecs_nosc_nots_nosa_noea TYPE_QUAL
913                 { $$ = tree_cons (NULL_TREE, $2, $1);
914                   TREE_STATIC ($$) = 1; }
915         | declspecs_nosc_nots_nosa_ea TYPE_QUAL
916                 { $$ = tree_cons (NULL_TREE, $2, $1);
917                   TREE_STATIC ($$) = 1; }
918         ;
919
920 declspecs_nosc_nots_nosa_ea:
921           declspecs_nosc_nots_nosa_noea attributes
922                 { $$ = tree_cons ($2, NULL_TREE, $1);
923                   TREE_STATIC ($$) = TREE_STATIC ($1); }
924         ;
925
926 declspecs_nosc_nots_sa_noea:
927           declspecs_nosc_nots_sa_noea TYPE_QUAL
928                 { $$ = tree_cons (NULL_TREE, $2, $1);
929                   TREE_STATIC ($$) = 1; }
930         | declspecs_nosc_nots_sa_ea TYPE_QUAL
931                 { $$ = tree_cons (NULL_TREE, $2, $1);
932                   TREE_STATIC ($$) = 1; }
933         ;
934
935 declspecs_nosc_nots_sa_ea:
936           attributes
937                 { $$ = tree_cons ($1, NULL_TREE, NULL_TREE);
938                   TREE_STATIC ($$) = 0; }
939         | declspecs_nosc_nots_sa_noea attributes
940                 { $$ = tree_cons ($2, NULL_TREE, $1);
941                   TREE_STATIC ($$) = TREE_STATIC ($1); }
942         ;
943
944 declspecs_nosc_ts_nosa_noea:
945           typespec_nonattr
946                 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
947                   TREE_STATIC ($$) = 1; }
948         | declspecs_nosc_ts_nosa_noea TYPE_QUAL
949                 { $$ = tree_cons (NULL_TREE, $2, $1);
950                   TREE_STATIC ($$) = 1; }
951         | declspecs_nosc_ts_nosa_ea TYPE_QUAL
952                 { $$ = tree_cons (NULL_TREE, $2, $1);
953                   TREE_STATIC ($$) = 1; }
954         | declspecs_nosc_ts_nosa_noea typespec_reserved_nonattr
955                 { $$ = tree_cons (NULL_TREE, $2, $1);
956                   TREE_STATIC ($$) = 1; }
957         | declspecs_nosc_ts_nosa_ea typespec_reserved_nonattr
958                 { $$ = tree_cons (NULL_TREE, $2, $1);
959                   TREE_STATIC ($$) = 1; }
960         | declspecs_nosc_nots_nosa_noea typespec_nonattr
961                 { $$ = tree_cons (NULL_TREE, $2, $1);
962                   TREE_STATIC ($$) = 1; }
963         | declspecs_nosc_nots_nosa_ea typespec_nonattr
964                 { $$ = tree_cons (NULL_TREE, $2, $1);
965                   TREE_STATIC ($$) = 1; }
966         ;
967
968 declspecs_nosc_ts_nosa_ea:
969           typespec_attr
970                 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
971                   TREE_STATIC ($$) = 1; }
972         | declspecs_nosc_ts_nosa_noea attributes
973                 { $$ = tree_cons ($2, NULL_TREE, $1);
974                   TREE_STATIC ($$) = TREE_STATIC ($1); }
975         | declspecs_nosc_ts_nosa_noea typespec_reserved_attr
976                 { $$ = tree_cons (NULL_TREE, $2, $1);
977                   TREE_STATIC ($$) = 1; }
978         | declspecs_nosc_ts_nosa_ea typespec_reserved_attr
979                 { $$ = tree_cons (NULL_TREE, $2, $1);
980                   TREE_STATIC ($$) = 1; }
981         | declspecs_nosc_nots_nosa_noea typespec_attr
982                 { $$ = tree_cons (NULL_TREE, $2, $1);
983                   TREE_STATIC ($$) = 1; }
984         | declspecs_nosc_nots_nosa_ea typespec_attr
985                 { $$ = tree_cons (NULL_TREE, $2, $1);
986                   TREE_STATIC ($$) = 1; }
987         ;
988
989 declspecs_nosc_ts_sa_noea:
990           declspecs_nosc_ts_sa_noea TYPE_QUAL
991                 { $$ = tree_cons (NULL_TREE, $2, $1);
992                   TREE_STATIC ($$) = 1; }
993         | declspecs_nosc_ts_sa_ea TYPE_QUAL
994                 { $$ = tree_cons (NULL_TREE, $2, $1);
995                   TREE_STATIC ($$) = 1; }
996         | declspecs_nosc_ts_sa_noea typespec_reserved_nonattr
997                 { $$ = tree_cons (NULL_TREE, $2, $1);
998                   TREE_STATIC ($$) = 1; }
999         | declspecs_nosc_ts_sa_ea typespec_reserved_nonattr
1000                 { $$ = tree_cons (NULL_TREE, $2, $1);
1001                   TREE_STATIC ($$) = 1; }
1002         | declspecs_nosc_nots_sa_noea typespec_nonattr
1003                 { $$ = tree_cons (NULL_TREE, $2, $1);
1004                   TREE_STATIC ($$) = 1; }
1005         | declspecs_nosc_nots_sa_ea typespec_nonattr
1006                 { $$ = tree_cons (NULL_TREE, $2, $1);
1007                   TREE_STATIC ($$) = 1; }
1008         ;
1009
1010 declspecs_nosc_ts_sa_ea:
1011           declspecs_nosc_ts_sa_noea attributes
1012                 { $$ = tree_cons ($2, NULL_TREE, $1);
1013                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1014         | declspecs_nosc_ts_sa_noea typespec_reserved_attr
1015                 { $$ = tree_cons (NULL_TREE, $2, $1);
1016                   TREE_STATIC ($$) = 1; }
1017         | declspecs_nosc_ts_sa_ea typespec_reserved_attr
1018                 { $$ = tree_cons (NULL_TREE, $2, $1);
1019                   TREE_STATIC ($$) = 1; }
1020         | declspecs_nosc_nots_sa_noea typespec_attr
1021                 { $$ = tree_cons (NULL_TREE, $2, $1);
1022                   TREE_STATIC ($$) = 1; }
1023         | declspecs_nosc_nots_sa_ea typespec_attr
1024                 { $$ = tree_cons (NULL_TREE, $2, $1);
1025                   TREE_STATIC ($$) = 1; }
1026         ;
1027
1028 declspecs_sc_nots_nosa_noea:
1029           scspec
1030                 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
1031                   TREE_STATIC ($$) = 0; }
1032         | declspecs_sc_nots_nosa_noea TYPE_QUAL
1033                 { $$ = tree_cons (NULL_TREE, $2, $1);
1034                   TREE_STATIC ($$) = 1; }
1035         | declspecs_sc_nots_nosa_ea TYPE_QUAL
1036                 { $$ = tree_cons (NULL_TREE, $2, $1);
1037                   TREE_STATIC ($$) = 1; }
1038         | declspecs_nosc_nots_nosa_noea scspec
1039                 { if (extra_warnings && TREE_STATIC ($1))
1040                     warning ("`%s' is not at beginning of declaration",
1041                              IDENTIFIER_POINTER ($2));
1042                   $$ = tree_cons (NULL_TREE, $2, $1);
1043                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1044         | declspecs_nosc_nots_nosa_ea scspec
1045                 { if (extra_warnings && TREE_STATIC ($1))
1046                     warning ("`%s' is not at beginning of declaration",
1047                              IDENTIFIER_POINTER ($2));
1048                   $$ = tree_cons (NULL_TREE, $2, $1);
1049                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1050         | declspecs_sc_nots_nosa_noea scspec
1051                 { if (extra_warnings && TREE_STATIC ($1))
1052                     warning ("`%s' is not at beginning of declaration",
1053                              IDENTIFIER_POINTER ($2));
1054                   $$ = tree_cons (NULL_TREE, $2, $1);
1055                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1056         | declspecs_sc_nots_nosa_ea scspec
1057                 { if (extra_warnings && TREE_STATIC ($1))
1058                     warning ("`%s' is not at beginning of declaration",
1059                              IDENTIFIER_POINTER ($2));
1060                   $$ = tree_cons (NULL_TREE, $2, $1);
1061                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1062         ;
1063
1064 declspecs_sc_nots_nosa_ea:
1065           declspecs_sc_nots_nosa_noea attributes
1066                 { $$ = tree_cons ($2, NULL_TREE, $1);
1067                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1068         ;
1069
1070 declspecs_sc_nots_sa_noea:
1071           declspecs_sc_nots_sa_noea TYPE_QUAL
1072                 { $$ = tree_cons (NULL_TREE, $2, $1);
1073                   TREE_STATIC ($$) = 1; }
1074         | declspecs_sc_nots_sa_ea TYPE_QUAL
1075                 { $$ = tree_cons (NULL_TREE, $2, $1);
1076                   TREE_STATIC ($$) = 1; }
1077         | declspecs_nosc_nots_sa_noea scspec
1078                 { if (extra_warnings && TREE_STATIC ($1))
1079                     warning ("`%s' is not at beginning of declaration",
1080                              IDENTIFIER_POINTER ($2));
1081                   $$ = tree_cons (NULL_TREE, $2, $1);
1082                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1083         | declspecs_nosc_nots_sa_ea scspec
1084                 { if (extra_warnings && TREE_STATIC ($1))
1085                     warning ("`%s' is not at beginning of declaration",
1086                              IDENTIFIER_POINTER ($2));
1087                   $$ = tree_cons (NULL_TREE, $2, $1);
1088                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1089         | declspecs_sc_nots_sa_noea scspec
1090                 { if (extra_warnings && TREE_STATIC ($1))
1091                     warning ("`%s' is not at beginning of declaration",
1092                              IDENTIFIER_POINTER ($2));
1093                   $$ = tree_cons (NULL_TREE, $2, $1);
1094                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1095         | declspecs_sc_nots_sa_ea scspec
1096                 { if (extra_warnings && TREE_STATIC ($1))
1097                     warning ("`%s' is not at beginning of declaration",
1098                              IDENTIFIER_POINTER ($2));
1099                   $$ = tree_cons (NULL_TREE, $2, $1);
1100                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1101         ;
1102
1103 declspecs_sc_nots_sa_ea:
1104           declspecs_sc_nots_sa_noea attributes
1105                 { $$ = tree_cons ($2, NULL_TREE, $1);
1106                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1107         ;
1108
1109 declspecs_sc_ts_nosa_noea:
1110           declspecs_sc_ts_nosa_noea TYPE_QUAL
1111                 { $$ = tree_cons (NULL_TREE, $2, $1);
1112                   TREE_STATIC ($$) = 1; }
1113         | declspecs_sc_ts_nosa_ea TYPE_QUAL
1114                 { $$ = tree_cons (NULL_TREE, $2, $1);
1115                   TREE_STATIC ($$) = 1; }
1116         | declspecs_sc_ts_nosa_noea typespec_reserved_nonattr
1117                 { $$ = tree_cons (NULL_TREE, $2, $1);
1118                   TREE_STATIC ($$) = 1; }
1119         | declspecs_sc_ts_nosa_ea typespec_reserved_nonattr
1120                 { $$ = tree_cons (NULL_TREE, $2, $1);
1121                   TREE_STATIC ($$) = 1; }
1122         | declspecs_sc_nots_nosa_noea typespec_nonattr
1123                 { $$ = tree_cons (NULL_TREE, $2, $1);
1124                   TREE_STATIC ($$) = 1; }
1125         | declspecs_sc_nots_nosa_ea typespec_nonattr
1126                 { $$ = tree_cons (NULL_TREE, $2, $1);
1127                   TREE_STATIC ($$) = 1; }
1128         | declspecs_nosc_ts_nosa_noea scspec
1129                 { if (extra_warnings && TREE_STATIC ($1))
1130                     warning ("`%s' is not at beginning of declaration",
1131                              IDENTIFIER_POINTER ($2));
1132                   $$ = tree_cons (NULL_TREE, $2, $1);
1133                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1134         | declspecs_nosc_ts_nosa_ea scspec
1135                 { if (extra_warnings && TREE_STATIC ($1))
1136                     warning ("`%s' is not at beginning of declaration",
1137                              IDENTIFIER_POINTER ($2));
1138                   $$ = tree_cons (NULL_TREE, $2, $1);
1139                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1140         | declspecs_sc_ts_nosa_noea scspec
1141                 { if (extra_warnings && TREE_STATIC ($1))
1142                     warning ("`%s' is not at beginning of declaration",
1143                              IDENTIFIER_POINTER ($2));
1144                   $$ = tree_cons (NULL_TREE, $2, $1);
1145                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1146         | declspecs_sc_ts_nosa_ea scspec
1147                 { if (extra_warnings && TREE_STATIC ($1))
1148                     warning ("`%s' is not at beginning of declaration",
1149                              IDENTIFIER_POINTER ($2));
1150                   $$ = tree_cons (NULL_TREE, $2, $1);
1151                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1152         ;
1153
1154 declspecs_sc_ts_nosa_ea:
1155           declspecs_sc_ts_nosa_noea attributes
1156                 { $$ = tree_cons ($2, NULL_TREE, $1);
1157                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1158         | declspecs_sc_ts_nosa_noea typespec_reserved_attr
1159                 { $$ = tree_cons (NULL_TREE, $2, $1);
1160                   TREE_STATIC ($$) = 1; }
1161         | declspecs_sc_ts_nosa_ea typespec_reserved_attr
1162                 { $$ = tree_cons (NULL_TREE, $2, $1);
1163                   TREE_STATIC ($$) = 1; }
1164         | declspecs_sc_nots_nosa_noea typespec_attr
1165                 { $$ = tree_cons (NULL_TREE, $2, $1);
1166                   TREE_STATIC ($$) = 1; }
1167         | declspecs_sc_nots_nosa_ea typespec_attr
1168                 { $$ = tree_cons (NULL_TREE, $2, $1);
1169                   TREE_STATIC ($$) = 1; }
1170         ;
1171
1172 declspecs_sc_ts_sa_noea:
1173           declspecs_sc_ts_sa_noea TYPE_QUAL
1174                 { $$ = tree_cons (NULL_TREE, $2, $1);
1175                   TREE_STATIC ($$) = 1; }
1176         | declspecs_sc_ts_sa_ea TYPE_QUAL
1177                 { $$ = tree_cons (NULL_TREE, $2, $1);
1178                   TREE_STATIC ($$) = 1; }
1179         | declspecs_sc_ts_sa_noea typespec_reserved_nonattr
1180                 { $$ = tree_cons (NULL_TREE, $2, $1);
1181                   TREE_STATIC ($$) = 1; }
1182         | declspecs_sc_ts_sa_ea typespec_reserved_nonattr
1183                 { $$ = tree_cons (NULL_TREE, $2, $1);
1184                   TREE_STATIC ($$) = 1; }
1185         | declspecs_sc_nots_sa_noea typespec_nonattr
1186                 { $$ = tree_cons (NULL_TREE, $2, $1);
1187                   TREE_STATIC ($$) = 1; }
1188         | declspecs_sc_nots_sa_ea typespec_nonattr
1189                 { $$ = tree_cons (NULL_TREE, $2, $1);
1190                   TREE_STATIC ($$) = 1; }
1191         | declspecs_nosc_ts_sa_noea scspec
1192                 { if (extra_warnings && TREE_STATIC ($1))
1193                     warning ("`%s' is not at beginning of declaration",
1194                              IDENTIFIER_POINTER ($2));
1195                   $$ = tree_cons (NULL_TREE, $2, $1);
1196                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1197         | declspecs_nosc_ts_sa_ea scspec
1198                 { if (extra_warnings && TREE_STATIC ($1))
1199                     warning ("`%s' is not at beginning of declaration",
1200                              IDENTIFIER_POINTER ($2));
1201                   $$ = tree_cons (NULL_TREE, $2, $1);
1202                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1203         | declspecs_sc_ts_sa_noea scspec
1204                 { if (extra_warnings && TREE_STATIC ($1))
1205                     warning ("`%s' is not at beginning of declaration",
1206                              IDENTIFIER_POINTER ($2));
1207                   $$ = tree_cons (NULL_TREE, $2, $1);
1208                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1209         | declspecs_sc_ts_sa_ea scspec
1210                 { if (extra_warnings && TREE_STATIC ($1))
1211                     warning ("`%s' is not at beginning of declaration",
1212                              IDENTIFIER_POINTER ($2));
1213                   $$ = tree_cons (NULL_TREE, $2, $1);
1214                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1215         ;
1216
1217 declspecs_sc_ts_sa_ea:
1218           declspecs_sc_ts_sa_noea attributes
1219                 { $$ = tree_cons ($2, NULL_TREE, $1);
1220                   TREE_STATIC ($$) = TREE_STATIC ($1); }
1221         | declspecs_sc_ts_sa_noea typespec_reserved_attr
1222                 { $$ = tree_cons (NULL_TREE, $2, $1);
1223                   TREE_STATIC ($$) = 1; }
1224         | declspecs_sc_ts_sa_ea typespec_reserved_attr
1225                 { $$ = tree_cons (NULL_TREE, $2, $1);
1226                   TREE_STATIC ($$) = 1; }
1227         | declspecs_sc_nots_sa_noea typespec_attr
1228                 { $$ = tree_cons (NULL_TREE, $2, $1);
1229                   TREE_STATIC ($$) = 1; }
1230         | declspecs_sc_nots_sa_ea typespec_attr
1231                 { $$ = tree_cons (NULL_TREE, $2, $1);
1232                   TREE_STATIC ($$) = 1; }
1233         ;
1234
1235 /* Particular useful classes of declspecs.  */
1236 declspecs_ts:
1237           declspecs_nosc_ts_nosa_noea
1238         | declspecs_nosc_ts_nosa_ea
1239         | declspecs_nosc_ts_sa_noea
1240         | declspecs_nosc_ts_sa_ea
1241         | declspecs_sc_ts_nosa_noea
1242         | declspecs_sc_ts_nosa_ea
1243         | declspecs_sc_ts_sa_noea
1244         | declspecs_sc_ts_sa_ea
1245         ;
1246
1247 declspecs_nots:
1248           declspecs_nosc_nots_nosa_noea
1249         | declspecs_nosc_nots_nosa_ea
1250         | declspecs_nosc_nots_sa_noea
1251         | declspecs_nosc_nots_sa_ea
1252         | declspecs_sc_nots_nosa_noea
1253         | declspecs_sc_nots_nosa_ea
1254         | declspecs_sc_nots_sa_noea
1255         | declspecs_sc_nots_sa_ea
1256         ;
1257
1258 declspecs_ts_nosa:
1259           declspecs_nosc_ts_nosa_noea
1260         | declspecs_nosc_ts_nosa_ea
1261         | declspecs_sc_ts_nosa_noea
1262         | declspecs_sc_ts_nosa_ea
1263         ;
1264
1265 declspecs_nots_nosa:
1266           declspecs_nosc_nots_nosa_noea
1267         | declspecs_nosc_nots_nosa_ea
1268         | declspecs_sc_nots_nosa_noea
1269         | declspecs_sc_nots_nosa_ea
1270         ;
1271
1272 declspecs_nosc_ts:
1273           declspecs_nosc_ts_nosa_noea
1274         | declspecs_nosc_ts_nosa_ea
1275         | declspecs_nosc_ts_sa_noea
1276         | declspecs_nosc_ts_sa_ea
1277         ;
1278
1279 declspecs_nosc_nots:
1280           declspecs_nosc_nots_nosa_noea
1281         | declspecs_nosc_nots_nosa_ea
1282         | declspecs_nosc_nots_sa_noea
1283         | declspecs_nosc_nots_sa_ea
1284         ;
1285
1286 declspecs_nosc:
1287           declspecs_nosc_ts_nosa_noea
1288         | declspecs_nosc_ts_nosa_ea
1289         | declspecs_nosc_ts_sa_noea
1290         | declspecs_nosc_ts_sa_ea
1291         | declspecs_nosc_nots_nosa_noea
1292         | declspecs_nosc_nots_nosa_ea
1293         | declspecs_nosc_nots_sa_noea
1294         | declspecs_nosc_nots_sa_ea
1295         ;
1296
1297 declspecs:
1298           declspecs_nosc_nots_nosa_noea
1299         | declspecs_nosc_nots_nosa_ea
1300         | declspecs_nosc_nots_sa_noea
1301         | declspecs_nosc_nots_sa_ea
1302         | declspecs_nosc_ts_nosa_noea
1303         | declspecs_nosc_ts_nosa_ea
1304         | declspecs_nosc_ts_sa_noea
1305         | declspecs_nosc_ts_sa_ea
1306         | declspecs_sc_nots_nosa_noea
1307         | declspecs_sc_nots_nosa_ea
1308         | declspecs_sc_nots_sa_noea
1309         | declspecs_sc_nots_sa_ea
1310         | declspecs_sc_ts_nosa_noea
1311         | declspecs_sc_ts_nosa_ea
1312         | declspecs_sc_ts_sa_noea
1313         | declspecs_sc_ts_sa_ea
1314         ;
1315
1316 /* A (possibly empty) sequence of type qualifiers and attributes.  */
1317 maybe_type_quals_attrs:
1318           /* empty */
1319                 { $$ = NULL_TREE; }
1320         | declspecs_nosc_nots
1321                 { $$ = $1; }
1322         ;
1323
1324 /* A type specifier (but not a type qualifier).
1325    Once we have seen one of these in a declaration,
1326    if a typedef name appears then it is being redeclared.
1327
1328    The _reserved versions start with a reserved word and may appear anywhere
1329    in the declaration specifiers; the _nonreserved versions may only
1330    appear before any other type specifiers, and after that are (if names)
1331    being redeclared.
1332
1333    FIXME: should the _nonreserved version be restricted to names being
1334    redeclared only?  The other entries there relate only the GNU extensions
1335    and Objective C, and are historically parsed thus, and don't make sense
1336    after other type specifiers, but it might be cleaner to count them as
1337    _reserved.
1338
1339    _attr means: specifiers that either end with attributes,
1340    or are such that any following attributes would
1341    be parsed as part of the specifier.
1342
1343    _nonattr: specifiers.  */
1344
1345 typespec_nonattr:
1346           typespec_reserved_nonattr
1347         | typespec_nonreserved_nonattr
1348         ;
1349
1350 typespec_attr:
1351           typespec_reserved_attr
1352         ;
1353
1354 typespec_reserved_nonattr:
1355           TYPESPEC
1356                 { OBJC_NEED_RAW_IDENTIFIER (1); }
1357         | structsp_nonattr
1358         ;
1359
1360 typespec_reserved_attr:
1361           structsp_attr
1362         ;
1363
1364 typespec_nonreserved_nonattr:
1365           TYPENAME
1366                 { /* For a typedef name, record the meaning, not the name.
1367                      In case of `foo foo, bar;'.  */
1368                   $$ = lookup_name ($1); }
1369 ifobjc
1370         | CLASSNAME protocolrefs
1371                 { $$ = get_static_reference ($1, $2); }
1372         | OBJECTNAME protocolrefs
1373                 { $$ = get_object_reference ($2); }
1374
1375 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>"
1376    - nisse@lysator.liu.se */
1377         | non_empty_protocolrefs
1378                 { $$ = get_object_reference ($1); }
1379 end ifobjc
1380         | typeof '(' expr ')'
1381                 { skip_evaluation--; $$ = TREE_TYPE ($3); }
1382         | typeof '(' typename ')'
1383                 { skip_evaluation--; $$ = groktypename ($3); }
1384         ;
1385
1386 /* typespec_nonreserved_attr does not exist.  */
1387
1388 initdecls:
1389         initdcl
1390         | initdecls ',' maybe_resetattrs initdcl
1391         ;
1392
1393 notype_initdecls:
1394         notype_initdcl
1395         | notype_initdecls ',' maybe_resetattrs notype_initdcl
1396         ;
1397
1398 maybeasm:
1399           /* empty */
1400                 { $$ = NULL_TREE; }
1401         | ASM_KEYWORD '(' STRING ')'
1402                 { $$ = $3; }
1403         ;
1404
1405 initdcl:
1406           declarator maybeasm maybe_attribute '='
1407                 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1408                                           chainon ($3, all_prefix_attributes));
1409                   start_init ($<ttype>$, $2, global_bindings_p ()); }
1410           init
1411 /* Note how the declaration of the variable is in effect while its init is parsed! */
1412                 { finish_init ();
1413                   finish_decl ($<ttype>5, $6, $2); }
1414         | declarator maybeasm maybe_attribute
1415                 { tree d = start_decl ($1, current_declspecs, 0,
1416                                        chainon ($3, all_prefix_attributes));
1417                   finish_decl (d, NULL_TREE, $2);
1418                 }
1419         ;
1420
1421 notype_initdcl:
1422           notype_declarator maybeasm maybe_attribute '='
1423                 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1424                                           chainon ($3, all_prefix_attributes));
1425                   start_init ($<ttype>$, $2, global_bindings_p ()); }
1426           init
1427 /* Note how the declaration of the variable is in effect while its init is parsed! */
1428                 { finish_init ();
1429                   finish_decl ($<ttype>5, $6, $2); }
1430         | notype_declarator maybeasm maybe_attribute
1431                 { tree d = start_decl ($1, current_declspecs, 0,
1432                                        chainon ($3, all_prefix_attributes));
1433                   finish_decl (d, NULL_TREE, $2); }
1434         ;
1435 /* the * rules are dummies to accept the Apollo extended syntax
1436    so that the header files compile. */
1437 maybe_attribute:
1438       /* empty */
1439                 { $$ = NULL_TREE; }
1440         | attributes
1441                 { $$ = $1; }
1442         ;
1443
1444 attributes:
1445       attribute
1446                 { $$ = $1; }
1447         | attributes attribute
1448                 { $$ = chainon ($1, $2); }
1449         ;
1450
1451 attribute:
1452       ATTRIBUTE '(' '(' attribute_list ')' ')'
1453                 { $$ = $4; }
1454         ;
1455
1456 attribute_list:
1457       attrib
1458                 { $$ = $1; }
1459         | attribute_list ',' attrib
1460                 { $$ = chainon ($1, $3); }
1461         ;
1462
1463 attrib:
1464     /* empty */
1465                 { $$ = NULL_TREE; }
1466         | any_word
1467                 { $$ = build_tree_list ($1, NULL_TREE); }
1468         | any_word '(' IDENTIFIER ')'
1469                 { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
1470         | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
1471                 { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
1472         | any_word '(' exprlist ')'
1473                 { $$ = build_tree_list ($1, $3); }
1474         ;
1475
1476 /* This still leaves out most reserved keywords,
1477    shouldn't we include them?  */
1478
1479 any_word:
1480           identifier
1481         | scspec
1482         | TYPESPEC
1483         | TYPE_QUAL
1484         ;
1485
1486 scspec:
1487           STATIC
1488         | SCSPEC
1489         ;
1490 \f
1491 /* Initializers.  `init' is the entry point.  */
1492
1493 init:
1494         expr_no_commas
1495         | '{'
1496                 { really_start_incremental_init (NULL_TREE); }
1497           initlist_maybe_comma '}'
1498                 { $$ = pop_init_level (0); }
1499         | error
1500                 { $$ = error_mark_node; }
1501         ;
1502
1503 /* `initlist_maybe_comma' is the guts of an initializer in braces.  */
1504 initlist_maybe_comma:
1505           /* empty */
1506                 { if (pedantic)
1507                     pedwarn ("ISO C forbids empty initializer braces"); }
1508         | initlist1 maybecomma
1509         ;
1510
1511 initlist1:
1512           initelt
1513         | initlist1 ',' initelt
1514         ;
1515
1516 /* `initelt' is a single element of an initializer.
1517    It may use braces.  */
1518 initelt:
1519           designator_list '=' initval
1520                 { if (pedantic && ! flag_isoc99)
1521                     pedwarn ("ISO C89 forbids specifying subobject to initialize"); }
1522         | designator initval
1523                 { if (pedantic)
1524                     pedwarn ("obsolete use of designated initializer without `='"); }
1525         | identifier ':'
1526                 { set_init_label ($1);
1527                   if (pedantic)
1528                     pedwarn ("obsolete use of designated initializer with `:'"); }
1529           initval
1530                 {}
1531         | initval
1532         ;
1533
1534 initval:
1535           '{'
1536                 { push_init_level (0); }
1537           initlist_maybe_comma '}'
1538                 { process_init_element (pop_init_level (0)); }
1539         | expr_no_commas
1540                 { process_init_element ($1); }
1541         | error
1542         ;
1543
1544 designator_list:
1545           designator
1546         | designator_list designator
1547         ;
1548
1549 designator:
1550           '.' identifier
1551                 { set_init_label ($2); }
1552         | '[' expr_no_commas ELLIPSIS expr_no_commas ']'
1553                 { set_init_index ($2, $4);
1554                   if (pedantic)
1555                     pedwarn ("ISO C forbids specifying range of elements to initialize"); }
1556         | '[' expr_no_commas ']'
1557                 { set_init_index ($2, NULL_TREE); }
1558         ;
1559 \f
1560 nested_function:
1561           declarator
1562                 { if (pedantic)
1563                     pedwarn ("ISO C forbids nested functions");
1564
1565                   push_function_context ();
1566                   if (! start_function (current_declspecs, $1,
1567                                         all_prefix_attributes))
1568                     {
1569                       pop_function_context ();
1570                       YYERROR1;
1571                     }
1572                   parsing_iso_function_signature = false; /* Don't warn about nested functions.  */
1573                 }
1574            old_style_parm_decls save_location
1575                 { tree decl = current_function_decl;
1576                   DECL_SOURCE_LOCATION (decl) = $4;
1577                   store_parm_decls (); }
1578 /* This used to use compstmt_or_error.
1579    That caused a bug with input `f(g) int g {}',
1580    where the use of YYERROR1 above caused an error
1581    which then was handled by compstmt_or_error.
1582    There followed a repeated execution of that same rule,
1583    which called YYERROR1 again, and so on.  */
1584           compstmt
1585                 { tree decl = current_function_decl;
1586                   finish_function (1, 1);
1587                   pop_function_context ();
1588                   add_decl_stmt (decl); }
1589         ;
1590
1591 notype_nested_function:
1592           notype_declarator
1593                 { if (pedantic)
1594                     pedwarn ("ISO C forbids nested functions");
1595
1596                   push_function_context ();
1597                   if (! start_function (current_declspecs, $1,
1598                                         all_prefix_attributes))
1599                     {
1600                       pop_function_context ();
1601                       YYERROR1;
1602                     }
1603                   parsing_iso_function_signature = false; /* Don't warn about nested functions.  */
1604                 }
1605           old_style_parm_decls save_location
1606                 { tree decl = current_function_decl;
1607                   DECL_SOURCE_LOCATION (decl) = $4;
1608                   store_parm_decls (); }
1609 /* This used to use compstmt_or_error.
1610    That caused a bug with input `f(g) int g {}',
1611    where the use of YYERROR1 above caused an error
1612    which then was handled by compstmt_or_error.
1613    There followed a repeated execution of that same rule,
1614    which called YYERROR1 again, and so on.  */
1615           compstmt
1616                 { tree decl = current_function_decl;
1617                   finish_function (1, 1);
1618                   pop_function_context ();
1619                   add_decl_stmt (decl); }
1620         ;
1621
1622 /* Any kind of declarator (thus, all declarators allowed
1623    after an explicit typespec).  */
1624
1625 declarator:
1626           after_type_declarator
1627         | notype_declarator
1628         ;
1629
1630 /* A declarator that is allowed only after an explicit typespec.  */
1631
1632 after_type_declarator:
1633           '(' maybe_attribute after_type_declarator ')'
1634                 { $$ = $2 ? tree_cons ($2, $3, NULL_TREE) : $3; }
1635         | after_type_declarator '(' parmlist_or_identifiers  %prec '.'
1636                 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1637 /*      | after_type_declarator '(' error ')'  %prec '.'
1638                 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1639                   poplevel (0, 0, 0); }  */
1640         | after_type_declarator array_declarator  %prec '.'
1641                 { $$ = set_array_declarator_type ($2, $1, 0); }
1642         | '*' maybe_type_quals_attrs after_type_declarator  %prec UNARY
1643                 { $$ = make_pointer_declarator ($2, $3); }
1644         | TYPENAME
1645 ifobjc
1646         | OBJECTNAME
1647 end ifobjc
1648         ;
1649
1650 /* Kinds of declarator that can appear in a parameter list
1651    in addition to notype_declarator.  This is like after_type_declarator
1652    but does not allow a typedef name in parentheses as an identifier
1653    (because it would conflict with a function with that typedef as arg).  */
1654 parm_declarator:
1655           parm_declarator_starttypename
1656         | parm_declarator_nostarttypename
1657         ;
1658
1659 parm_declarator_starttypename:
1660           parm_declarator_starttypename '(' parmlist_or_identifiers  %prec '.'
1661                 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1662 /*      | parm_declarator_starttypename '(' error ')'  %prec '.'
1663                 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1664                   poplevel (0, 0, 0); }  */
1665         | parm_declarator_starttypename array_declarator  %prec '.'
1666                 { $$ = set_array_declarator_type ($2, $1, 0); }
1667         | TYPENAME
1668 ifobjc
1669         | OBJECTNAME
1670 end ifobjc
1671         ;
1672
1673 parm_declarator_nostarttypename:
1674           parm_declarator_nostarttypename '(' parmlist_or_identifiers  %prec '.'
1675                 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1676 /*      | parm_declarator_nostarttypename '(' error ')'  %prec '.'
1677                 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1678                   poplevel (0, 0, 0); }  */
1679         | parm_declarator_nostarttypename array_declarator  %prec '.'
1680                 { $$ = set_array_declarator_type ($2, $1, 0); }
1681         | '*' maybe_type_quals_attrs parm_declarator_starttypename  %prec UNARY
1682                 { $$ = make_pointer_declarator ($2, $3); }
1683         | '*' maybe_type_quals_attrs parm_declarator_nostarttypename  %prec UNARY
1684                 { $$ = make_pointer_declarator ($2, $3); }
1685         | '(' maybe_attribute parm_declarator_nostarttypename ')'
1686                 { $$ = $2 ? tree_cons ($2, $3, NULL_TREE) : $3; }
1687         ;
1688
1689 /* A declarator allowed whether or not there has been
1690    an explicit typespec.  These cannot redeclare a typedef-name.  */
1691
1692 notype_declarator:
1693           notype_declarator '(' parmlist_or_identifiers  %prec '.'
1694                 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1695 /*      | notype_declarator '(' error ')'  %prec '.'
1696                 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1697                   poplevel (0, 0, 0); }  */
1698         | '(' maybe_attribute notype_declarator ')'
1699                 { $$ = $2 ? tree_cons ($2, $3, NULL_TREE) : $3; }
1700         | '*' maybe_type_quals_attrs notype_declarator  %prec UNARY
1701                 { $$ = make_pointer_declarator ($2, $3); }
1702         | notype_declarator array_declarator  %prec '.'
1703                 { $$ = set_array_declarator_type ($2, $1, 0); }
1704         | IDENTIFIER
1705         ;
1706
1707 struct_head:
1708           STRUCT
1709                 { $$ = NULL_TREE; }
1710         | STRUCT attributes
1711                 { $$ = $2; }
1712         ;
1713
1714 union_head:
1715           UNION
1716                 { $$ = NULL_TREE; }
1717         | UNION attributes
1718                 { $$ = $2; }
1719         ;
1720
1721 enum_head:
1722           ENUM
1723                 { $$ = NULL_TREE; }
1724         | ENUM attributes
1725                 { $$ = $2; }
1726         ;
1727
1728 /* structsp_attr: struct/union/enum specifiers that either
1729    end with attributes, or are such that any following attributes would
1730    be parsed as part of the struct/union/enum specifier.
1731
1732    structsp_nonattr: other struct/union/enum specifiers.  */
1733
1734 structsp_attr:
1735           struct_head identifier '{'
1736                 { $$ = start_struct (RECORD_TYPE, $2);
1737                   /* Start scope of tag before parsing components.  */
1738                 }
1739           component_decl_list '}' maybe_attribute
1740                 { $$ = finish_struct ($<ttype>4, nreverse ($5),
1741                                       chainon ($1, $7)); }
1742         | struct_head '{' component_decl_list '}' maybe_attribute
1743                 { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
1744                                       nreverse ($3), chainon ($1, $5));
1745                 }
1746         | union_head identifier '{'
1747                 { $$ = start_struct (UNION_TYPE, $2); }
1748           component_decl_list '}' maybe_attribute
1749                 { $$ = finish_struct ($<ttype>4, nreverse ($5),
1750                                       chainon ($1, $7)); }
1751         | union_head '{' component_decl_list '}' maybe_attribute
1752                 { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
1753                                       nreverse ($3), chainon ($1, $5));
1754                 }
1755         | enum_head identifier '{'
1756                 { $$ = start_enum ($2); }
1757           enumlist maybecomma_warn '}' maybe_attribute
1758                 { $$ = finish_enum ($<ttype>4, nreverse ($5),
1759                                     chainon ($1, $8)); }
1760         | enum_head '{'
1761                 { $$ = start_enum (NULL_TREE); }
1762           enumlist maybecomma_warn '}' maybe_attribute
1763                 { $$ = finish_enum ($<ttype>3, nreverse ($4),
1764                                     chainon ($1, $7)); }
1765         ;
1766
1767 structsp_nonattr:
1768           struct_head identifier
1769                 { $$ = xref_tag (RECORD_TYPE, $2); }
1770         | union_head identifier
1771                 { $$ = xref_tag (UNION_TYPE, $2); }
1772         | enum_head identifier
1773                 { $$ = xref_tag (ENUMERAL_TYPE, $2);
1774                   /* In ISO C, enumerated types can be referred to
1775                      only if already defined.  */
1776                   if (pedantic && !COMPLETE_TYPE_P ($$))
1777                     pedwarn ("ISO C forbids forward references to `enum' types"); }
1778         ;
1779
1780 maybecomma:
1781           /* empty */
1782         | ','
1783         ;
1784
1785 maybecomma_warn:
1786           /* empty */
1787         | ','
1788                 { if (pedantic && ! flag_isoc99)
1789                     pedwarn ("comma at end of enumerator list"); }
1790         ;
1791
1792 /* We chain the components in reverse order.  They are put in forward
1793    order in structsp_attr.
1794
1795    Note that component_declarator returns single decls, so components
1796    and components_notype can use TREE_CHAIN directly, wheras components
1797    and components_notype return lists (of comma separated decls), so
1798    component_decl_list and component_decl_list2 must use chainon.
1799
1800    The theory behind all this is that there will be more semicolon
1801    separated fields than comma separated fields, and so we'll be
1802    minimizing the number of node traversals required by chainon.  */
1803
1804 component_decl_list:
1805           component_decl_list2
1806                 { $$ = $1; }
1807         | component_decl_list2 component_decl
1808                 { $$ = chainon ($2, $1);
1809                   pedwarn ("no semicolon at end of struct or union"); }
1810         ;
1811
1812 component_decl_list2:   /* empty */
1813                 { $$ = NULL_TREE; }
1814         | component_decl_list2 component_decl ';'
1815                 { $$ = chainon ($2, $1); }
1816         | component_decl_list2 ';'
1817                 { if (pedantic)
1818                     pedwarn ("extra semicolon in struct or union specified"); }
1819 ifobjc
1820         /* foo(sizeof(struct{ @defs(ClassName)})); */
1821         | DEFS '(' CLASSNAME ')'
1822                 {
1823                   tree interface = lookup_interface ($3);
1824
1825                   if (interface)
1826                     $$ = nreverse (get_class_ivars (interface));
1827                   else
1828                     {
1829                       error ("cannot find interface declaration for `%s'",
1830                              IDENTIFIER_POINTER ($3));
1831                       $$ = NULL_TREE;
1832                     }
1833                 }
1834 end ifobjc
1835         ;
1836
1837 component_decl:
1838           declspecs_nosc_ts setspecs components
1839                 { $$ = $3;
1840                   POP_DECLSPEC_STACK; }
1841         | declspecs_nosc_ts setspecs
1842                 {
1843                   /* Support for unnamed structs or unions as members of
1844                      structs or unions (which is [a] useful and [b] supports
1845                      MS P-SDK).  */
1846                   if (pedantic)
1847                     pedwarn ("ISO C doesn't support unnamed structs/unions");
1848
1849                   $$ = grokfield(NULL, current_declspecs, NULL_TREE);
1850                   POP_DECLSPEC_STACK; }
1851         | declspecs_nosc_nots setspecs components_notype
1852                 { $$ = $3;
1853                   POP_DECLSPEC_STACK; }
1854         | declspecs_nosc_nots
1855                 { if (pedantic)
1856                     pedwarn ("ISO C forbids member declarations with no members");
1857                   shadow_tag($1);
1858                   $$ = NULL_TREE; }
1859         | error
1860                 { $$ = NULL_TREE; }
1861         | extension component_decl
1862                 { $$ = $2;
1863                   RESTORE_EXT_FLAGS ($1); }
1864         ;
1865
1866 components:
1867           component_declarator
1868         | components ',' maybe_resetattrs component_declarator
1869                 { TREE_CHAIN ($4) = $1; $$ = $4; }
1870         ;
1871
1872 components_notype:
1873           component_notype_declarator
1874         | components_notype ',' maybe_resetattrs component_notype_declarator
1875                 { TREE_CHAIN ($4) = $1; $$ = $4; }
1876         ;
1877
1878 component_declarator:
1879           declarator maybe_attribute
1880                 { $$ = grokfield ($1, current_declspecs, NULL_TREE);
1881                   decl_attributes (&$$,
1882                                    chainon ($2, all_prefix_attributes), 0); }
1883         | declarator ':' expr_no_commas maybe_attribute
1884                 { $$ = grokfield ($1, current_declspecs, $3);
1885                   decl_attributes (&$$,
1886                                    chainon ($4, all_prefix_attributes), 0); }
1887         | ':' expr_no_commas maybe_attribute
1888                 { $$ = grokfield (NULL_TREE, current_declspecs, $2);
1889                   decl_attributes (&$$,
1890                                    chainon ($3, all_prefix_attributes), 0); }
1891         ;
1892
1893 component_notype_declarator:
1894           notype_declarator maybe_attribute
1895                 { $$ = grokfield ($1, current_declspecs, NULL_TREE);
1896                   decl_attributes (&$$,
1897                                    chainon ($2, all_prefix_attributes), 0); }
1898         | notype_declarator ':' expr_no_commas maybe_attribute
1899                 { $$ = grokfield ($1, current_declspecs, $3);
1900                   decl_attributes (&$$,
1901                                    chainon ($4, all_prefix_attributes), 0); }
1902         | ':' expr_no_commas maybe_attribute
1903                 { $$ = grokfield (NULL_TREE, current_declspecs, $2);
1904                   decl_attributes (&$$,
1905                                    chainon ($3, all_prefix_attributes), 0); }
1906         ;
1907
1908 /* We chain the enumerators in reverse order.
1909    They are put in forward order in structsp_attr.  */
1910
1911 enumlist:
1912           enumerator
1913         | enumlist ',' enumerator
1914                 { if ($1 == error_mark_node)
1915                     $$ = $1;
1916                   else
1917                     TREE_CHAIN ($3) = $1, $$ = $3; }
1918         | error
1919                 { $$ = error_mark_node; }
1920         ;
1921
1922
1923 enumerator:
1924           identifier
1925                 { $$ = build_enumerator ($1, NULL_TREE); }
1926         | identifier '=' expr_no_commas
1927                 { $$ = build_enumerator ($1, $3); }
1928         ;
1929
1930 typename:
1931           declspecs_nosc
1932                 { pending_xref_error ();
1933                   $<ttype>$ = $1; }
1934           absdcl
1935                 { $$ = build_tree_list ($<ttype>2, $3); }
1936         ;
1937
1938 absdcl:   /* an absolute declarator */
1939         /* empty */
1940                 { $$ = NULL_TREE; }
1941         | absdcl1
1942         ;
1943
1944 absdcl_maybe_attribute:   /* absdcl maybe_attribute, but not just attributes */
1945         /* empty */
1946                 { $$ = build_tree_list (build_tree_list (current_declspecs,
1947                                                          NULL_TREE),
1948                                         all_prefix_attributes); }
1949         | absdcl1
1950                 { $$ = build_tree_list (build_tree_list (current_declspecs,
1951                                                          $1),
1952                                         all_prefix_attributes); }
1953         | absdcl1_noea attributes
1954                 { $$ = build_tree_list (build_tree_list (current_declspecs,
1955                                                          $1),
1956                                         chainon ($2, all_prefix_attributes)); }
1957         ;
1958
1959 absdcl1:  /* a nonempty absolute declarator */
1960           absdcl1_ea
1961         | absdcl1_noea
1962         ;
1963
1964 absdcl1_noea:
1965           direct_absdcl1
1966         | '*' maybe_type_quals_attrs absdcl1_noea
1967                 { $$ = make_pointer_declarator ($2, $3); }
1968         ;
1969
1970 absdcl1_ea:
1971           '*' maybe_type_quals_attrs
1972                 { $$ = make_pointer_declarator ($2, NULL_TREE); }
1973         | '*' maybe_type_quals_attrs absdcl1_ea
1974                 { $$ = make_pointer_declarator ($2, $3); }
1975         ;
1976
1977 direct_absdcl1:
1978           '(' maybe_attribute absdcl1 ')'
1979                 { $$ = $2 ? tree_cons ($2, $3, NULL_TREE) : $3; }
1980         | direct_absdcl1 '(' parmlist
1981                 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1982         | direct_absdcl1 array_declarator
1983                 { $$ = set_array_declarator_type ($2, $1, 1); }
1984         | '(' parmlist
1985                 { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
1986         | array_declarator
1987                 { $$ = set_array_declarator_type ($1, NULL_TREE, 1); }
1988         ;
1989
1990 /* The [...] part of a declarator for an array type.  */
1991
1992 array_declarator:
1993         '[' maybe_type_quals_attrs expr ']'
1994                 { $$ = build_array_declarator ($3, $2, 0, 0); }
1995         | '[' maybe_type_quals_attrs ']'
1996                 { $$ = build_array_declarator (NULL_TREE, $2, 0, 0); }
1997         | '[' maybe_type_quals_attrs '*' ']'
1998                 { $$ = build_array_declarator (NULL_TREE, $2, 0, 1); }
1999         | '[' STATIC maybe_type_quals_attrs expr ']'
2000                 { $$ = build_array_declarator ($4, $3, 1, 0); }
2001         /* declspecs_nosc_nots is a synonym for type_quals_attrs.  */
2002         | '[' declspecs_nosc_nots STATIC expr ']'
2003                 { $$ = build_array_declarator ($4, $2, 1, 0); }
2004         ;
2005
2006 /* A nonempty series of declarations and statements (possibly followed by
2007    some labels) that can form the body of a compound statement.
2008    NOTE: we don't allow labels on declarations; this might seem like a
2009    natural extension, but there would be a conflict between attributes
2010    on the label and prefix attributes on the declaration.  */
2011
2012 stmts_and_decls:
2013           lineno_stmt_decl_or_labels_ending_stmt
2014         | lineno_stmt_decl_or_labels_ending_decl
2015         | lineno_stmt_decl_or_labels_ending_label
2016                 {
2017                   pedwarn ("deprecated use of label at end of compound statement");
2018                 }
2019         | lineno_stmt_decl_or_labels_ending_error
2020         ;
2021
2022 lineno_stmt_decl_or_labels_ending_stmt:
2023           lineno_stmt
2024         | lineno_stmt_decl_or_labels_ending_stmt lineno_stmt
2025         | lineno_stmt_decl_or_labels_ending_decl lineno_stmt
2026         | lineno_stmt_decl_or_labels_ending_label lineno_stmt
2027         | lineno_stmt_decl_or_labels_ending_error lineno_stmt
2028         ;
2029
2030 lineno_stmt_decl_or_labels_ending_decl:
2031           lineno_decl
2032         | lineno_stmt_decl_or_labels_ending_stmt lineno_decl
2033                 { if (pedantic && !flag_isoc99)
2034                     pedwarn ("ISO C89 forbids mixed declarations and code"); }
2035         | lineno_stmt_decl_or_labels_ending_decl lineno_decl
2036         | lineno_stmt_decl_or_labels_ending_error lineno_decl
2037         ;
2038
2039 lineno_stmt_decl_or_labels_ending_label:
2040           lineno_label
2041         | lineno_stmt_decl_or_labels_ending_stmt lineno_label
2042         | lineno_stmt_decl_or_labels_ending_decl lineno_label
2043         | lineno_stmt_decl_or_labels_ending_label lineno_label
2044         | lineno_stmt_decl_or_labels_ending_error lineno_label
2045         ;
2046
2047 lineno_stmt_decl_or_labels_ending_error:
2048         errstmt
2049         | lineno_stmt_decl_or_labels errstmt
2050         ;
2051
2052 lineno_stmt_decl_or_labels:
2053           lineno_stmt_decl_or_labels_ending_stmt
2054         | lineno_stmt_decl_or_labels_ending_decl
2055         | lineno_stmt_decl_or_labels_ending_label
2056         | lineno_stmt_decl_or_labels_ending_error
2057         ;
2058
2059 errstmt:  error ';'
2060         ;
2061
2062 pushlevel:  /* empty */
2063                 { pushlevel (0);
2064                   clear_last_expr ();
2065                   add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
2066 ifobjc
2067                   if (objc_method_context)
2068                     add_objc_decls ();
2069 end ifobjc
2070                 }
2071         ;
2072
2073 poplevel:  /* empty */
2074                 { $$ = add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0); }
2075         ;
2076
2077 /* Start and end blocks created for the new scopes of C99.  */
2078 c99_block_start: /* empty */
2079                 { if (flag_isoc99)
2080                     {
2081                       $$ = c_begin_compound_stmt ();
2082                       pushlevel (0);
2083                       clear_last_expr ();
2084                       add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
2085 ifobjc
2086                       if (objc_method_context)
2087                         add_objc_decls ();
2088 end ifobjc
2089                     }
2090                   else
2091                     $$ = NULL_TREE;
2092                 }
2093         ;
2094
2095 /* Productions using c99_block_start and c99_block_end will need to do what's
2096    in compstmt: RECHAIN_STMTS ($1, COMPOUND_BODY ($1)); $$ = $2; where
2097    $1 is the value of c99_block_start and $2 of c99_block_end.  */
2098 c99_block_end: /* empty */
2099                 { if (flag_isoc99)
2100                     {
2101                       tree scope_stmt = add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0);
2102                       $$ = poplevel (kept_level_p (), 0, 0);
2103                       SCOPE_STMT_BLOCK (TREE_PURPOSE (scope_stmt))
2104                         = SCOPE_STMT_BLOCK (TREE_VALUE (scope_stmt))
2105                         = $$;
2106                     }
2107                   else
2108                     $$ = NULL_TREE; }
2109         ;
2110
2111 /* Read zero or more forward-declarations for labels
2112    that nested functions can jump to.  */
2113 maybe_label_decls:
2114           /* empty */
2115         | label_decls
2116                 { if (pedantic)
2117                     pedwarn ("ISO C forbids label declarations"); }
2118         ;
2119
2120 label_decls:
2121           label_decl
2122         | label_decls label_decl
2123         ;
2124
2125 label_decl:
2126           LABEL identifiers_or_typenames ';'
2127                 { tree link;
2128                   for (link = $2; link; link = TREE_CHAIN (link))
2129                     {
2130                       tree label = shadow_label (TREE_VALUE (link));
2131                       C_DECLARED_LABEL_FLAG (label) = 1;
2132                       add_decl_stmt (label);
2133                     }
2134                 }
2135         ;
2136
2137 /* This is the body of a function definition.
2138    It causes syntax errors to ignore to the next openbrace.  */
2139 compstmt_or_error:
2140           compstmt
2141                 {}
2142         | error compstmt
2143         ;
2144
2145 compstmt_start: '{' { compstmt_count++;
2146                       $$ = c_begin_compound_stmt (); }
2147         ;
2148
2149 compstmt_nostart: '}'
2150                 { $$ = convert (void_type_node, integer_zero_node); }
2151         | pushlevel maybe_label_decls compstmt_contents_nonempty '}' poplevel
2152                 { $$ = poplevel (kept_level_p (), 1, 0);
2153                   SCOPE_STMT_BLOCK (TREE_PURPOSE ($5))
2154                     = SCOPE_STMT_BLOCK (TREE_VALUE ($5))
2155                     = $$; }
2156         ;
2157
2158 compstmt_contents_nonempty:
2159           stmts_and_decls
2160         | error
2161         ;
2162
2163 compstmt_primary_start:
2164         '(' '{'
2165                 { if (current_function_decl == 0)
2166                     {
2167                       error ("braced-group within expression allowed only inside a function");
2168                       YYERROR;
2169                     }
2170                   /* We must force a BLOCK for this level
2171                      so that, if it is not expanded later,
2172                      there is a way to turn off the entire subtree of blocks
2173                      that are contained in it.  */
2174                   keep_next_level ();
2175                   push_label_level ();
2176                   compstmt_count++;
2177                   $$ = add_stmt (build_stmt (COMPOUND_STMT, last_tree));
2178                 }
2179         ;
2180
2181 compstmt: compstmt_start compstmt_nostart
2182                 { RECHAIN_STMTS ($1, COMPOUND_BODY ($1));
2183                   last_expr_type = NULL_TREE;
2184                   $$ = $1; }
2185         ;
2186
2187 /* Value is number of statements counted as of the closeparen.  */
2188 simple_if:
2189           if_prefix c99_block_lineno_labeled_stmt
2190                 { c_finish_then (); }
2191 /* Make sure c_expand_end_cond is run once
2192    for each call to c_expand_start_cond.
2193    Otherwise a crash is likely.  */
2194         | if_prefix error
2195         ;
2196
2197 if_prefix:
2198           /* We must build the IF_STMT node before parsing its
2199              condition so that STMT_LINENO refers to the line
2200              containing the "if", and not the line containing
2201              the close-parenthesis.
2202
2203              c_begin_if_stmt returns the IF_STMT node, which
2204              we later pass to c_expand_start_cond to fill
2205              in the condition and other tidbits.  */
2206           IF
2207                 { $<ttype>$ = c_begin_if_stmt (); }
2208             '(' expr ')'
2209                 { c_expand_start_cond (c_common_truthvalue_conversion ($4),
2210                                        compstmt_count,$<ttype>2);
2211                   $<itype>$ = stmt_count;
2212                   if_stmt_locus = $<location>-1; }
2213         ;
2214
2215 /* This is a subroutine of stmt.
2216    It is used twice, once for valid DO statements
2217    and once for catching errors in parsing the end test.  */
2218 do_stmt_start:
2219           DO
2220                 { stmt_count++;
2221                   compstmt_count++;
2222                   $<ttype>$
2223                     = add_stmt (build_stmt (DO_STMT, NULL_TREE,
2224                                             NULL_TREE));
2225                   /* In the event that a parse error prevents
2226                      parsing the complete do-statement, set the
2227                      condition now.  Otherwise, we can get crashes at
2228                      RTL-generation time.  */
2229                   DO_COND ($<ttype>$) = error_mark_node; }
2230           c99_block_lineno_labeled_stmt WHILE
2231                 { $$ = $<ttype>2;
2232                   RECHAIN_STMTS ($$, DO_BODY ($$)); }
2233         ;
2234
2235 /* The forced readahead in here is because we might be at the end of a
2236    line, and the line and file won't be bumped until yylex absorbs the
2237    first token on the next line.  */
2238
2239 save_location:
2240                 { if (yychar == YYEMPTY)
2241                     yychar = YYLEX;
2242                   $$ = input_location; }
2243         ;
2244
2245 lineno_labeled_stmt:
2246           lineno_stmt
2247         | lineno_label lineno_labeled_stmt
2248         ;
2249
2250 /* Like lineno_labeled_stmt, but a block in C99.  */
2251 c99_block_lineno_labeled_stmt:
2252           c99_block_start lineno_labeled_stmt c99_block_end
2253                 { if (flag_isoc99)
2254                     RECHAIN_STMTS ($1, COMPOUND_BODY ($1)); }
2255         ;
2256
2257 lineno_stmt:
2258           save_location stmt
2259                 { if ($2)
2260                     {
2261                       STMT_LINENO ($2) = $1.line;
2262                       /* ??? We currently have no way of recording
2263                          the filename for a statement.  This probably
2264                          matters little in practice at the moment,
2265                          but I suspect that problems will occur when
2266                          doing inlining at the tree level.  */
2267                     }
2268                 }
2269         ;
2270
2271 lineno_label:
2272           save_location label
2273                 { if ($2)
2274                     {
2275                       STMT_LINENO ($2) = $1.line;
2276                     }
2277                 }
2278         ;
2279
2280 select_or_iter_stmt:
2281           simple_if ELSE
2282                 { c_expand_start_else ();
2283                   $<itype>1 = stmt_count; }
2284           c99_block_lineno_labeled_stmt
2285                 { c_finish_else ();
2286                   c_expand_end_cond ();
2287                   if (extra_warnings && stmt_count == $<itype>1)
2288                     warning ("empty body in an else-statement"); }
2289         | simple_if %prec IF
2290                 { c_expand_end_cond ();
2291                   /* This warning is here instead of in simple_if, because we
2292                      do not want a warning if an empty if is followed by an
2293                      else statement.  Increment stmt_count so we don't
2294                      give a second error if this is a nested `if'.  */
2295                   if (extra_warnings && stmt_count++ == $<itype>1)
2296                     warning ("%Hempty body in an if-statement",
2297                              &if_stmt_locus); }
2298 /* Make sure c_expand_end_cond is run once
2299    for each call to c_expand_start_cond.
2300    Otherwise a crash is likely.  */
2301         | simple_if ELSE error
2302                 { c_expand_end_cond (); }
2303        /* We must build the WHILE_STMT node before parsing its
2304           condition so that STMT_LINENO refers to the line
2305           containing the "while", and not the line containing
2306           the close-parenthesis.
2307
2308           c_begin_while_stmt returns the WHILE_STMT node, which
2309           we later pass to c_finish_while_stmt_cond to fill
2310           in the condition and other tidbits.  */
2311         | WHILE
2312                 { stmt_count++;
2313                   $<ttype>$ = c_begin_while_stmt (); }
2314           '(' expr ')'
2315                 { $4 = c_common_truthvalue_conversion ($4);
2316                   c_finish_while_stmt_cond
2317                     (c_common_truthvalue_conversion ($4), $<ttype>2);
2318                   $<ttype>$ = add_stmt ($<ttype>2); }
2319           c99_block_lineno_labeled_stmt
2320                 { RECHAIN_STMTS ($<ttype>6, WHILE_BODY ($<ttype>6)); }
2321         | do_stmt_start
2322           '(' expr ')' ';'
2323                 { DO_COND ($1) = c_common_truthvalue_conversion ($3); }
2324         | do_stmt_start error
2325                 { }
2326         | FOR
2327                 { $<ttype>$ = build_stmt (FOR_STMT, NULL_TREE, NULL_TREE,
2328                                           NULL_TREE, NULL_TREE);
2329                   add_stmt ($<ttype>$); }
2330           '(' for_init_stmt
2331                 { stmt_count++;
2332                   RECHAIN_STMTS ($<ttype>2, FOR_INIT_STMT ($<ttype>2)); }
2333           xexpr ';'
2334                 { if ($6)
2335                     FOR_COND ($<ttype>2)
2336                       = c_common_truthvalue_conversion ($6); }
2337           xexpr ')'
2338                 { FOR_EXPR ($<ttype>2) = $9; }
2339           c99_block_lineno_labeled_stmt
2340                 { RECHAIN_STMTS ($<ttype>2, FOR_BODY ($<ttype>2)); }
2341         | SWITCH '(' expr ')'
2342                 { stmt_count++;
2343                   $<ttype>$ = c_start_case ($3); }
2344           c99_block_lineno_labeled_stmt
2345                 { c_finish_case (); }
2346         ;
2347
2348 for_init_stmt:
2349           xexpr ';'
2350                 { add_stmt (build_stmt (EXPR_STMT, $1)); }
2351         | decl
2352                 { check_for_loop_decls (); }
2353         ;
2354
2355 /* Parse a single real statement, not including any labels.  */
2356 stmt:
2357           compstmt
2358                 { stmt_count++; $$ = $1; }
2359         | expr ';'
2360                 { stmt_count++;
2361                   $$ = c_expand_expr_stmt ($1); }
2362         | c99_block_start select_or_iter_stmt c99_block_end
2363                 { if (flag_isoc99)
2364                     RECHAIN_STMTS ($1, COMPOUND_BODY ($1));
2365                   $$ = NULL_TREE; }
2366         | BREAK ';'
2367                 { stmt_count++;
2368                   $$ = add_stmt (build_break_stmt ()); }
2369         | CONTINUE ';'
2370                 { stmt_count++;
2371                   $$ = add_stmt (build_continue_stmt ()); }
2372         | RETURN ';'
2373                 { stmt_count++;
2374                   $$ = c_expand_return (NULL_TREE); }
2375         | RETURN expr ';'
2376                 { stmt_count++;
2377                   $$ = c_expand_return ($2); }
2378         | ASM_KEYWORD maybe_type_qual '(' expr ')' ';'
2379                 { stmt_count++;
2380                   $$ = simple_asm_stmt ($4); }
2381         /* This is the case with just output operands.  */
2382         | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';'
2383                 { stmt_count++;
2384                   $$ = build_asm_stmt ($2, $4, $6, NULL_TREE, NULL_TREE); }
2385         /* This is the case with input operands as well.  */
2386         | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
2387           asm_operands ')' ';'
2388                 { stmt_count++;
2389                   $$ = build_asm_stmt ($2, $4, $6, $8, NULL_TREE); }
2390         /* This is the case with clobbered registers as well.  */
2391         | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
2392           asm_operands ':' asm_clobbers ')' ';'
2393                 { stmt_count++;
2394                   $$ = build_asm_stmt ($2, $4, $6, $8, $10); }
2395         | GOTO identifier ';'
2396                 { tree decl;
2397                   stmt_count++;
2398                   decl = lookup_label ($2);
2399                   if (decl != 0)
2400                     {
2401                       TREE_USED (decl) = 1;
2402                       $$ = add_stmt (build_stmt (GOTO_STMT, decl));
2403                     }
2404                   else
2405                     $$ = NULL_TREE;
2406                 }
2407         | GOTO '*' expr ';'
2408                 { if (pedantic)
2409                     pedwarn ("ISO C forbids `goto *expr;'");
2410                   stmt_count++;
2411                   $3 = convert (ptr_type_node, $3);
2412                   $$ = add_stmt (build_stmt (GOTO_STMT, $3)); }
2413         | ';'
2414                 { $$ = NULL_TREE; }
2415         ;
2416
2417 /* Any kind of label, including jump labels and case labels.
2418    ANSI C accepts labels only before statements, but we allow them
2419    also at the end of a compound statement.  */
2420
2421 label:    CASE expr_no_commas ':'
2422                 { stmt_count++;
2423                   $$ = do_case ($2, NULL_TREE); }
2424         | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
2425                 { stmt_count++;
2426                   $$ = do_case ($2, $4); }
2427         | DEFAULT ':'
2428                 { stmt_count++;
2429                   $$ = do_case (NULL_TREE, NULL_TREE); }
2430         | identifier save_location ':' maybe_attribute
2431                 { tree label = define_label ($2, $1);
2432                   stmt_count++;
2433                   if (label)
2434                     {
2435                       decl_attributes (&label, $4, 0);
2436                       $$ = add_stmt (build_stmt (LABEL_STMT, label));
2437                     }
2438                   else
2439                     $$ = NULL_TREE;
2440                 }
2441         ;
2442
2443 /* Either a type-qualifier or nothing.  First thing in an `asm' statement.  */
2444
2445 maybe_type_qual:
2446         /* empty */
2447                 { emit_line_note (input_filename, input_line);
2448                   $$ = NULL_TREE; }
2449         | TYPE_QUAL
2450                 { emit_line_note (input_filename, input_line); }
2451         ;
2452
2453 xexpr:
2454         /* empty */
2455                 { $$ = NULL_TREE; }
2456         | expr
2457         ;
2458
2459 /* These are the operands other than the first string and colon
2460    in  asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x))  */
2461 asm_operands: /* empty */
2462                 { $$ = NULL_TREE; }
2463         | nonnull_asm_operands
2464         ;
2465
2466 nonnull_asm_operands:
2467           asm_operand
2468         | nonnull_asm_operands ',' asm_operand
2469                 { $$ = chainon ($1, $3); }
2470         ;
2471
2472 asm_operand:
2473           STRING '(' expr ')'
2474                 { $$ = build_tree_list (build_tree_list (NULL_TREE, $1), $3); }
2475         | '[' identifier ']' STRING '(' expr ')'
2476                 { $2 = build_string (IDENTIFIER_LENGTH ($2),
2477                                      IDENTIFIER_POINTER ($2));
2478                   $$ = build_tree_list (build_tree_list ($2, $4), $6); }
2479         ;
2480
2481 asm_clobbers:
2482           STRING
2483                 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
2484         | asm_clobbers ',' STRING
2485                 { $$ = tree_cons (NULL_TREE, $3, $1); }
2486         ;
2487 \f
2488 /* This is what appears inside the parens in a function declarator.
2489    Its value is a list of ..._TYPE nodes.  Attributes must appear here
2490    to avoid a conflict with their appearance after an open parenthesis
2491    in an abstract declarator, as in
2492    "void bar (int (__attribute__((__mode__(SI))) int foo));".  */
2493 parmlist:
2494           maybe_attribute
2495                 { pushlevel (0);
2496                   clear_parm_order ();
2497                   declare_parm_level (0); }
2498           parmlist_1
2499                 { $$ = $3;
2500                   parmlist_tags_warning ();
2501                   poplevel (0, 0, 0); }
2502         ;
2503
2504 parmlist_1:
2505           parmlist_2 ')'
2506         | parms ';'
2507                 { tree parm;
2508                   if (pedantic)
2509                     pedwarn ("ISO C forbids forward parameter declarations");
2510                   /* Mark the forward decls as such.  */
2511                   for (parm = getdecls (); parm; parm = TREE_CHAIN (parm))
2512                     TREE_ASM_WRITTEN (parm) = 1;
2513                   clear_parm_order (); }
2514           maybe_attribute
2515                 { /* Dummy action so attributes are in known place
2516                      on parser stack.  */ }
2517           parmlist_1
2518                 { $$ = $6; }
2519         | error ')'
2520                 { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
2521         ;
2522
2523 /* This is what appears inside the parens in a function declarator.
2524    Is value is represented in the format that grokdeclarator expects.  */
2525 parmlist_2:  /* empty */
2526                 { $$ = get_parm_info (0); }
2527         | ELLIPSIS
2528                 { $$ = get_parm_info (0);
2529                   /* Gcc used to allow this as an extension.  However, it does
2530                      not work for all targets, and thus has been disabled.
2531                      Also, since func (...) and func () are indistinguishable,
2532                      it caused problems with the code in expand_builtin which
2533                      tries to verify that BUILT_IN_NEXT_ARG is being used
2534                      correctly.  */
2535                   error ("ISO C requires a named argument before `...'");
2536                 }
2537         | parms
2538                 { $$ = get_parm_info (1);
2539                   parsing_iso_function_signature = true;
2540                 }
2541         | parms ',' ELLIPSIS
2542                 { $$ = get_parm_info (0); }
2543         ;
2544
2545 parms:
2546         firstparm
2547                 { push_parm_decl ($1); }
2548         | parms ',' parm
2549                 { push_parm_decl ($3); }
2550         ;
2551
2552 /* A single parameter declaration or parameter type name,
2553    as found in a parmlist.  */
2554 parm:
2555           declspecs_ts setspecs parm_declarator maybe_attribute
2556                 { $$ = build_tree_list (build_tree_list (current_declspecs,
2557                                                          $3),
2558                                         chainon ($4, all_prefix_attributes));
2559                   POP_DECLSPEC_STACK; }
2560         | declspecs_ts setspecs notype_declarator maybe_attribute
2561                 { $$ = build_tree_list (build_tree_list (current_declspecs,
2562                                                          $3),
2563                                         chainon ($4, all_prefix_attributes));
2564                   POP_DECLSPEC_STACK; }
2565         | declspecs_ts setspecs absdcl_maybe_attribute
2566                 { $$ = $3;
2567                   POP_DECLSPEC_STACK; }
2568         | declspecs_nots setspecs notype_declarator maybe_attribute
2569                 { $$ = build_tree_list (build_tree_list (current_declspecs,
2570                                                          $3),
2571                                         chainon ($4, all_prefix_attributes));
2572                   POP_DECLSPEC_STACK; }
2573
2574         | declspecs_nots setspecs absdcl_maybe_attribute
2575                 { $$ = $3;
2576                   POP_DECLSPEC_STACK; }
2577         ;
2578
2579 /* The first parm, which must suck attributes from off the top of the parser
2580    stack.  */
2581 firstparm:
2582           declspecs_ts_nosa setspecs_fp parm_declarator maybe_attribute
2583                 { $$ = build_tree_list (build_tree_list (current_declspecs,
2584                                                          $3),
2585                                         chainon ($4, all_prefix_attributes));
2586                   POP_DECLSPEC_STACK; }
2587         | declspecs_ts_nosa setspecs_fp notype_declarator maybe_attribute
2588                 { $$ = build_tree_list (build_tree_list (current_declspecs,
2589                                                          $3),
2590                                         chainon ($4, all_prefix_attributes));
2591                   POP_DECLSPEC_STACK; }
2592         | declspecs_ts_nosa setspecs_fp absdcl_maybe_attribute
2593                 { $$ = $3;
2594                   POP_DECLSPEC_STACK; }
2595         | declspecs_nots_nosa setspecs_fp notype_declarator maybe_attribute
2596                 { $$ = build_tree_list (build_tree_list (current_declspecs,
2597                                                          $3),
2598                                         chainon ($4, all_prefix_attributes));
2599                   POP_DECLSPEC_STACK; }
2600
2601         | declspecs_nots_nosa setspecs_fp absdcl_maybe_attribute
2602                 { $$ = $3;
2603                   POP_DECLSPEC_STACK; }
2604         ;
2605
2606 setspecs_fp:
2607           setspecs
2608                 { prefix_attributes = chainon (prefix_attributes, $<ttype>-2);
2609                   all_prefix_attributes = prefix_attributes; }
2610         ;
2611
2612 /* This is used in a function definition
2613    where either a parmlist or an identifier list is ok.
2614    Its value is a list of ..._TYPE nodes or a list of identifiers.  */
2615 parmlist_or_identifiers:
2616           maybe_attribute
2617                 { pushlevel (0);
2618                   clear_parm_order ();
2619                   declare_parm_level (1); }
2620           parmlist_or_identifiers_1
2621                 { $$ = $3;
2622                   parmlist_tags_warning ();
2623                   poplevel (0, 0, 0); }
2624         ;
2625
2626 parmlist_or_identifiers_1:
2627           parmlist_1
2628         | identifiers ')'
2629                 { tree t;
2630                   for (t = $1; t; t = TREE_CHAIN (t))
2631                     if (TREE_VALUE (t) == NULL_TREE)
2632                       error ("`...' in old-style identifier list");
2633                   $$ = tree_cons (NULL_TREE, NULL_TREE, $1);
2634
2635                   /* Make sure we have a parmlist after attributes.  */
2636                   if ($<ttype>-1 != 0
2637                       && (TREE_CODE ($$) != TREE_LIST
2638                           || TREE_PURPOSE ($$) == 0
2639                           || TREE_CODE (TREE_PURPOSE ($$)) != PARM_DECL))
2640                     YYERROR1;
2641                 }
2642         ;
2643
2644 /* A nonempty list of identifiers.  */
2645 identifiers:
2646         IDENTIFIER
2647                 { $$ = build_tree_list (NULL_TREE, $1); }
2648         | identifiers ',' IDENTIFIER
2649                 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2650         ;
2651
2652 /* A nonempty list of identifiers, including typenames.  */
2653 identifiers_or_typenames:
2654         identifier
2655                 { $$ = build_tree_list (NULL_TREE, $1); }
2656         | identifiers_or_typenames ',' identifier
2657                 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2658         ;
2659
2660 extension:
2661         EXTENSION
2662                 { $$ = SAVE_EXT_FLAGS();
2663                   pedantic = 0;
2664                   warn_pointer_arith = 0;
2665                   warn_traditional = 0;
2666                   flag_iso = 0; }
2667         ;
2668 \f
2669 ifobjc
2670 /* Objective-C productions.  */
2671
2672 objcdef:
2673           classdef
2674         | classdecl
2675         | aliasdecl
2676         | protocoldef
2677         | methoddef
2678         | END
2679                 {
2680                   if (objc_implementation_context)
2681                     {
2682                       finish_class (objc_implementation_context);
2683                       objc_ivar_chain = NULL_TREE;
2684                       objc_implementation_context = NULL_TREE;
2685                     }
2686                   else
2687                     warning ("`@end' must appear in an implementation context");
2688                 }
2689         ;
2690
2691 /* A nonempty list of identifiers.  */
2692 identifier_list:
2693         identifier
2694                 { $$ = build_tree_list (NULL_TREE, $1); }
2695         | identifier_list ',' identifier
2696                 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2697         ;
2698
2699 classdecl:
2700           CLASS identifier_list ';'
2701                 {
2702                   objc_declare_class ($2);
2703                 }
2704         ;
2705
2706 aliasdecl:
2707           ALIAS identifier identifier ';'
2708                 {
2709                   objc_declare_alias ($2, $3);
2710                 }
2711         ;
2712
2713 classdef:
2714           INTERFACE identifier protocolrefs '{'
2715                 {
2716                   objc_interface_context = objc_ivar_context
2717                     = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2718                   objc_public_flag = 0;
2719                 }
2720           ivar_decl_list '}'
2721                 {
2722                   continue_class (objc_interface_context);
2723                 }
2724           methodprotolist
2725           END
2726                 {
2727                   finish_class (objc_interface_context);
2728                   objc_interface_context = NULL_TREE;
2729                 }
2730
2731         | INTERFACE identifier protocolrefs
2732                 {
2733                   objc_interface_context
2734                     = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2735                   continue_class (objc_interface_context);
2736                 }
2737           methodprotolist
2738           END
2739                 {
2740                   finish_class (objc_interface_context);
2741                   objc_interface_context = NULL_TREE;
2742                 }
2743
2744         | INTERFACE identifier ':' identifier protocolrefs '{'
2745                 {
2746                   objc_interface_context = objc_ivar_context
2747                     = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2748                   objc_public_flag = 0;
2749                 }
2750           ivar_decl_list '}'
2751                 {
2752                   continue_class (objc_interface_context);
2753                 }
2754           methodprotolist
2755           END
2756                 {
2757                   finish_class (objc_interface_context);
2758                   objc_interface_context = NULL_TREE;
2759                 }
2760
2761         | INTERFACE identifier ':' identifier protocolrefs
2762                 {
2763                   objc_interface_context
2764                     = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2765                   continue_class (objc_interface_context);
2766                 }
2767           methodprotolist
2768           END
2769                 {
2770                   finish_class (objc_interface_context);
2771                   objc_interface_context = NULL_TREE;
2772                 }
2773
2774         | IMPLEMENTATION identifier '{'
2775                 {
2776                   objc_implementation_context = objc_ivar_context
2777                     = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2778                   objc_public_flag = 0;
2779                 }
2780           ivar_decl_list '}'
2781                 {
2782                   objc_ivar_chain
2783                     = continue_class (objc_implementation_context);
2784                 }
2785
2786         | IMPLEMENTATION identifier
2787                 {
2788                   objc_implementation_context
2789                     = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2790                   objc_ivar_chain
2791                     = continue_class (objc_implementation_context);
2792                 }
2793
2794         | IMPLEMENTATION identifier ':' identifier '{'
2795                 {
2796                   objc_implementation_context = objc_ivar_context
2797                     = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2798                   objc_public_flag = 0;
2799                 }
2800           ivar_decl_list '}'
2801                 {
2802                   objc_ivar_chain
2803                     = continue_class (objc_implementation_context);
2804                 }
2805
2806         | IMPLEMENTATION identifier ':' identifier
2807                 {
2808                   objc_implementation_context
2809                     = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2810                   objc_ivar_chain
2811                     = continue_class (objc_implementation_context);
2812                 }
2813
2814         | INTERFACE identifier '(' identifier ')' protocolrefs
2815                 {
2816                   objc_interface_context
2817                     = start_class (CATEGORY_INTERFACE_TYPE, $2, $4, $6);
2818                   continue_class (objc_interface_context);
2819                 }
2820           methodprotolist
2821           END
2822                 {
2823                   finish_class (objc_interface_context);
2824                   objc_interface_context = NULL_TREE;
2825                 }
2826
2827         | IMPLEMENTATION identifier '(' identifier ')'
2828                 {
2829                   objc_implementation_context
2830                     = start_class (CATEGORY_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2831                   objc_ivar_chain
2832                     = continue_class (objc_implementation_context);
2833                 }
2834         ;
2835
2836 protocoldef:
2837           PROTOCOL identifier protocolrefs
2838                 {
2839                   objc_pq_context = 1;
2840                   objc_interface_context
2841                     = start_protocol(PROTOCOL_INTERFACE_TYPE, $2, $3);
2842                 }
2843           methodprotolist END
2844                 {
2845                   objc_pq_context = 0;
2846                   finish_protocol(objc_interface_context);
2847                   objc_interface_context = NULL_TREE;
2848                 }
2849         /* The @protocol forward-declaration production introduces a
2850            reduce/reduce conflict on ';', which should be resolved in
2851            favor of the production 'identifier_list -> identifier'.  */
2852         | PROTOCOL identifier_list ';'
2853                 {
2854                   objc_declare_protocols ($2);
2855                 }
2856         ;
2857
2858 protocolrefs:
2859           /* empty */
2860                 {
2861                   $$ = NULL_TREE;
2862                 }
2863         | non_empty_protocolrefs
2864         ;
2865
2866 non_empty_protocolrefs:
2867           ARITHCOMPARE identifier_list ARITHCOMPARE
2868                 {
2869                   if ($1 == LT_EXPR && $3 == GT_EXPR)
2870                     $$ = $2;
2871                   else
2872                     YYERROR1;
2873                 }
2874         ;
2875
2876 ivar_decl_list:
2877           ivar_decl_list visibility_spec ivar_decls
2878         | ivar_decls
2879         ;
2880
2881 visibility_spec:
2882           PRIVATE { objc_public_flag = 2; }
2883         | PROTECTED { objc_public_flag = 0; }
2884         | PUBLIC { objc_public_flag = 1; }
2885         ;
2886
2887 ivar_decls:
2888           /* empty */
2889                 {
2890                   $$ = NULL_TREE;
2891                 }
2892         | ivar_decls ivar_decl ';'
2893         | ivar_decls ';'
2894                 {
2895                   if (pedantic)
2896                     pedwarn ("extra semicolon in struct or union specified");
2897                 }
2898         ;
2899
2900
2901 /* There is a shift-reduce conflict here, because `components' may
2902    start with a `typename'.  It happens that shifting (the default resolution)
2903    does the right thing, because it treats the `typename' as part of
2904    a `typed_typespecs'.
2905
2906    It is possible that this same technique would allow the distinction
2907    between `notype_initdecls' and `initdecls' to be eliminated.
2908    But I am being cautious and not trying it.  */
2909
2910 ivar_decl:
2911         declspecs_nosc_ts setspecs ivars
2912                 { $$ = $3;
2913                   POP_DECLSPEC_STACK; }
2914         | declspecs_nosc_nots setspecs ivars
2915                 { $$ = $3;
2916                   POP_DECLSPEC_STACK; }
2917         | error
2918                 { $$ = NULL_TREE; }
2919         ;
2920
2921 ivars:
2922           /* empty */
2923                 { $$ = NULL_TREE; }
2924         | ivar_declarator
2925         | ivars ',' maybe_resetattrs ivar_declarator
2926         ;
2927
2928 ivar_declarator:
2929           declarator
2930                 {
2931                   $$ = add_instance_variable (objc_ivar_context,
2932                                               objc_public_flag,
2933                                               $1, current_declspecs,
2934                                               NULL_TREE);
2935                 }
2936         | declarator ':' expr_no_commas
2937                 {
2938                   $$ = add_instance_variable (objc_ivar_context,
2939                                               objc_public_flag,
2940                                               $1, current_declspecs, $3);
2941                 }
2942         | ':' expr_no_commas
2943                 {
2944                   $$ = add_instance_variable (objc_ivar_context,
2945                                               objc_public_flag,
2946                                               NULL_TREE,
2947                                               current_declspecs, $2);
2948                 }
2949         ;
2950
2951 methodtype:
2952           '+'
2953                 { objc_inherit_code = CLASS_METHOD_DECL; }
2954         | '-'
2955                 { objc_inherit_code = INSTANCE_METHOD_DECL; }
2956         ;
2957
2958 methoddef:
2959           methodtype
2960                 {
2961                   objc_pq_context = 1;
2962                   if (!objc_implementation_context)
2963                     fatal_error ("method definition not in class context");
2964                 }
2965           methoddecl
2966                 {
2967                   objc_pq_context = 0;
2968                   if (objc_inherit_code == CLASS_METHOD_DECL)
2969                     add_class_method (objc_implementation_context, $3);
2970                   else
2971                     add_instance_method (objc_implementation_context, $3);
2972                   start_method_def ($3);
2973                 }
2974           optarglist
2975                 {
2976                   continue_method_def ();
2977                 }
2978           compstmt_or_error
2979                 {
2980                   finish_method_def ();
2981                 }
2982         ;
2983
2984 /* the reason for the strange actions in this rule
2985  is so that notype_initdecls when reached via datadef
2986  can find a valid list of type and sc specs in $0. */
2987
2988 methodprotolist:
2989           /* empty  */
2990         | {$<ttype>$ = NULL_TREE; } methodprotolist2
2991         ;
2992
2993 methodprotolist2:                /* eliminates a shift/reduce conflict */
2994            methodproto
2995         |  datadef
2996         | methodprotolist2 methodproto
2997         | methodprotolist2 {$<ttype>$ = NULL_TREE; } datadef
2998         ;
2999
3000 semi_or_error:
3001           ';'
3002         | error
3003         ;
3004
3005 methodproto:
3006           methodtype
3007                 {
3008                   /* Remember protocol qualifiers in prototypes.  */
3009                   objc_pq_context = 1;
3010                 }
3011           methoddecl
3012                 {
3013                   /* Forget protocol qualifiers here.  */
3014                   objc_pq_context = 0;
3015                   if (objc_inherit_code == CLASS_METHOD_DECL)
3016                     add_class_method (objc_interface_context, $3);
3017                   else
3018                     add_instance_method (objc_interface_context, $3);
3019                 }
3020           semi_or_error
3021         ;
3022
3023 methoddecl:
3024           '(' typename ')' unaryselector
3025                 {
3026                   $$ = build_method_decl (objc_inherit_code, $2, $4, NULL_TREE);
3027                 }
3028
3029         | unaryselector
3030                 {
3031                   $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, NULL_TREE);
3032                 }
3033
3034         | '(' typename ')' keywordselector optparmlist
3035                 {
3036                   $$ = build_method_decl (objc_inherit_code, $2, $4, $5);
3037                 }
3038
3039         | keywordselector optparmlist
3040                 {
3041                   $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, $2);
3042                 }
3043         ;
3044
3045 /* "optarglist" assumes that start_method_def has already been called...
3046    if it is not, the "xdecls" will not be placed in the proper scope */
3047
3048 optarglist:
3049           /* empty */
3050         | ';' myxdecls
3051         ;
3052
3053 /* to get around the following situation: "int foo (int a) int b; {}" that
3054    is synthesized when parsing "- a:a b:b; id c; id d; { ... }" */
3055
3056 myxdecls:
3057           /* empty */
3058         | mydecls
3059         ;
3060
3061 mydecls:
3062         mydecl
3063         | errstmt
3064         | mydecls mydecl
3065         | mydecl errstmt
3066         ;
3067
3068 mydecl:
3069         declspecs_ts setspecs myparms ';'
3070                 { POP_DECLSPEC_STACK; }
3071         | declspecs_ts ';'
3072                 { shadow_tag ($1); }
3073         | declspecs_nots ';'
3074                 { pedwarn ("empty declaration"); }
3075         ;
3076
3077 myparms:
3078         myparm
3079                 { push_parm_decl ($1); }
3080         | myparms ',' myparm
3081                 { push_parm_decl ($3); }
3082         ;
3083
3084 /* A single parameter declaration or parameter type name,
3085    as found in a parmlist. DOES NOT ALLOW AN INITIALIZER OR ASMSPEC */
3086
3087 myparm:
3088           parm_declarator maybe_attribute
3089                 { $$ = build_tree_list (build_tree_list (current_declspecs,
3090                                                          $1),
3091                                         chainon ($2, all_prefix_attributes)); }
3092         | notype_declarator maybe_attribute
3093                 { $$ = build_tree_list (build_tree_list (current_declspecs,
3094                                                          $1),
3095                                         chainon ($2, all_prefix_attributes)); }
3096         | absdcl_maybe_attribute
3097                 { $$ = $1; }
3098         ;
3099
3100 optparmlist:
3101           /* empty */
3102                 {
3103                   $$ = NULL_TREE;
3104                 }
3105         | ',' ELLIPSIS
3106                 {
3107                   /* oh what a kludge! */
3108                   $$ = objc_ellipsis_node;
3109                 }
3110         | ','
3111                 {
3112                   pushlevel (0);
3113                 }
3114           parmlist_2
3115                 {
3116                   /* returns a tree list node generated by get_parm_info */
3117                   $$ = $3;
3118                   poplevel (0, 0, 0);
3119                 }
3120         ;
3121
3122 unaryselector:
3123           selector
3124         ;
3125
3126 keywordselector:
3127           keyworddecl
3128
3129         | keywordselector keyworddecl
3130                 {
3131                   $$ = chainon ($1, $2);
3132                 }
3133         ;
3134
3135 selector:
3136           IDENTIFIER
3137         | TYPENAME
3138         | CLASSNAME
3139         | OBJECTNAME
3140         | reservedwords
3141         ;
3142
3143 reservedwords:
3144           ENUM | STRUCT | UNION | IF | ELSE | WHILE | DO | FOR
3145         | SWITCH | CASE | DEFAULT | BREAK | CONTINUE | RETURN
3146         | GOTO | ASM_KEYWORD | SIZEOF | TYPEOF | ALIGNOF
3147         | TYPESPEC | TYPE_QUAL
3148         ;
3149
3150 keyworddecl:
3151           selector ':' '(' typename ')' identifier
3152                 {
3153                   $$ = build_keyword_decl ($1, $4, $6);
3154                 }
3155
3156         | selector ':' identifier
3157                 {
3158                   $$ = build_keyword_decl ($1, NULL_TREE, $3);
3159                 }
3160
3161         | ':' '(' typename ')' identifier
3162                 {
3163                   $$ = build_keyword_decl (NULL_TREE, $3, $5);
3164                 }
3165
3166         | ':' identifier
3167                 {
3168                   $$ = build_keyword_decl (NULL_TREE, NULL_TREE, $2);
3169                 }
3170         ;
3171
3172 messageargs:
3173           selector
3174         | keywordarglist
3175         ;
3176
3177 keywordarglist:
3178           keywordarg
3179         | keywordarglist keywordarg
3180                 {
3181                   $$ = chainon ($1, $2);
3182                 }
3183         ;
3184
3185
3186 keywordexpr:
3187           nonnull_exprlist
3188                 {
3189                   if (TREE_CHAIN ($1) == NULL_TREE)
3190                     /* just return the expr., remove a level of indirection */
3191                     $$ = TREE_VALUE ($1);
3192                   else
3193                     /* we have a comma expr., we will collapse later */
3194                     $$ = $1;
3195                 }
3196         ;
3197
3198 keywordarg:
3199           selector ':' keywordexpr
3200                 {
3201                   $$ = build_tree_list ($1, $3);
3202                 }
3203         | ':' keywordexpr
3204                 {
3205                   $$ = build_tree_list (NULL_TREE, $2);
3206                 }
3207         ;
3208
3209 receiver:
3210           expr
3211         | CLASSNAME
3212                 {
3213                   $$ = get_class_reference ($1);
3214                 }
3215         ;
3216
3217 objcmessageexpr:
3218           '[' receiver messageargs ']'
3219                 { $$ = build_tree_list ($2, $3); }
3220         ;
3221
3222 selectorarg:
3223           selector
3224         | keywordnamelist
3225         ;
3226
3227 keywordnamelist:
3228           keywordname
3229         | keywordnamelist keywordname
3230                 {
3231                   $$ = chainon ($1, $2);
3232                 }
3233         ;
3234
3235 keywordname:
3236           selector ':'
3237                 {
3238                   $$ = build_tree_list ($1, NULL_TREE);
3239                 }
3240         | ':'
3241                 {
3242                   $$ = build_tree_list (NULL_TREE, NULL_TREE);
3243                 }
3244         ;
3245
3246 objcselectorexpr:
3247           SELECTOR '(' selectorarg ')'
3248                 {
3249                   $$ = $3;
3250                 }
3251         ;
3252
3253 objcprotocolexpr:
3254           PROTOCOL '(' identifier ')'
3255                 {
3256                   $$ = $3;
3257                 }
3258         ;
3259
3260 /* extension to support C-structures in the archiver */
3261
3262 objcencodeexpr:
3263           ENCODE '(' typename ')'
3264                 {
3265                   $$ = groktypename ($3);
3266                 }
3267         ;
3268
3269 end ifobjc
3270 %%
3271
3272 /* yylex() is a thin wrapper around c_lex(), all it does is translate
3273    cpplib.h's token codes into yacc's token codes.  */
3274
3275 static enum cpp_ttype last_token;
3276
3277 /* The reserved keyword table.  */
3278 struct resword
3279 {
3280   const char *word;
3281   ENUM_BITFIELD(rid) rid : 16;
3282   unsigned int disable   : 16;
3283 };
3284
3285 /* Disable mask.  Keywords are disabled if (reswords[i].disable & mask) is
3286    _true_.  */
3287 #define D_C89   0x01    /* not in C89 */
3288 #define D_EXT   0x02    /* GCC extension */
3289 #define D_EXT89 0x04    /* GCC extension incorporated in C99 */
3290 #define D_OBJC  0x08    /* Objective C only */
3291
3292 static const struct resword reswords[] =
3293 {
3294   { "_Bool",            RID_BOOL,       0 },
3295   { "_Complex",         RID_COMPLEX,    0 },
3296   { "__FUNCTION__",     RID_FUNCTION_NAME, 0 },
3297   { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
3298   { "__alignof",        RID_ALIGNOF,    0 },
3299   { "__alignof__",      RID_ALIGNOF,    0 },
3300   { "__asm",            RID_ASM,        0 },
3301   { "__asm__",          RID_ASM,        0 },
3302   { "__attribute",      RID_ATTRIBUTE,  0 },
3303   { "__attribute__",    RID_ATTRIBUTE,  0 },
3304   { "__builtin_choose_expr", RID_CHOOSE_EXPR, 0 },
3305   { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P, 0 },
3306   { "__builtin_va_arg", RID_VA_ARG,     0 },
3307   { "__complex",        RID_COMPLEX,    0 },
3308   { "__complex__",      RID_COMPLEX,    0 },
3309   { "__const",          RID_CONST,      0 },
3310   { "__const__",        RID_CONST,      0 },
3311   { "__extension__",    RID_EXTENSION,  0 },
3312   { "__func__",         RID_C99_FUNCTION_NAME, 0 },
3313   { "__imag",           RID_IMAGPART,   0 },
3314   { "__imag__",         RID_IMAGPART,   0 },
3315   { "__inline",         RID_INLINE,     0 },
3316   { "__inline__",       RID_INLINE,     0 },
3317   { "__label__",        RID_LABEL,      0 },
3318   { "__ptrbase",        RID_PTRBASE,    0 },
3319   { "__ptrbase__",      RID_PTRBASE,    0 },
3320   { "__ptrextent",      RID_PTREXTENT,  0 },
3321   { "__ptrextent__",    RID_PTREXTENT,  0 },
3322   { "__ptrvalue",       RID_PTRVALUE,   0 },
3323   { "__ptrvalue__",     RID_PTRVALUE,   0 },
3324   { "__real",           RID_REALPART,   0 },
3325   { "__real__",         RID_REALPART,   0 },
3326   { "__restrict",       RID_RESTRICT,   0 },
3327   { "__restrict__",     RID_RESTRICT,   0 },
3328   { "__signed",         RID_SIGNED,     0 },
3329   { "__signed__",       RID_SIGNED,     0 },
3330   { "__thread",         RID_THREAD,     0 },
3331   { "__typeof",         RID_TYPEOF,     0 },
3332   { "__typeof__",       RID_TYPEOF,     0 },
3333   { "__volatile",       RID_VOLATILE,   0 },
3334   { "__volatile__",     RID_VOLATILE,   0 },
3335   { "asm",              RID_ASM,        D_EXT },
3336   { "auto",             RID_AUTO,       0 },
3337   { "break",            RID_BREAK,      0 },
3338   { "case",             RID_CASE,       0 },
3339   { "char",             RID_CHAR,       0 },
3340   { "const",            RID_CONST,      0 },
3341   { "continue",         RID_CONTINUE,   0 },
3342   { "default",          RID_DEFAULT,    0 },
3343   { "do",               RID_DO,         0 },
3344   { "double",           RID_DOUBLE,     0 },
3345   { "else",             RID_ELSE,       0 },
3346   { "enum",             RID_ENUM,       0 },
3347   { "extern",           RID_EXTERN,     0 },
3348   { "float",            RID_FLOAT,      0 },
3349   { "for",              RID_FOR,        0 },
3350   { "goto",             RID_GOTO,       0 },
3351   { "if",               RID_IF,         0 },
3352   { "inline",           RID_INLINE,     D_EXT89 },
3353   { "int",              RID_INT,        0 },
3354   { "long",             RID_LONG,       0 },
3355   { "register",         RID_REGISTER,   0 },
3356   { "restrict",         RID_RESTRICT,   D_C89 },
3357   { "return",           RID_RETURN,     0 },
3358   { "short",            RID_SHORT,      0 },
3359   { "signed",           RID_SIGNED,     0 },
3360   { "sizeof",           RID_SIZEOF,     0 },
3361   { "static",           RID_STATIC,     0 },
3362   { "struct",           RID_STRUCT,     0 },
3363   { "switch",           RID_SWITCH,     0 },
3364   { "typedef",          RID_TYPEDEF,    0 },
3365   { "typeof",           RID_TYPEOF,     D_EXT },
3366   { "union",            RID_UNION,      0 },
3367   { "unsigned",         RID_UNSIGNED,   0 },
3368   { "void",             RID_VOID,       0 },
3369   { "volatile",         RID_VOLATILE,   0 },
3370   { "while",            RID_WHILE,      0 },
3371 ifobjc
3372   { "id",               RID_ID,                 D_OBJC },
3373
3374   /* These objc keywords are recognized only immediately after
3375      an '@'.  */
3376   { "class",            RID_AT_CLASS,           D_OBJC },
3377   { "compatibility_alias", RID_AT_ALIAS,        D_OBJC },
3378   { "defs",             RID_AT_DEFS,            D_OBJC },
3379   { "encode",           RID_AT_ENCODE,          D_OBJC },
3380   { "end",              RID_AT_END,             D_OBJC },
3381   { "implementation",   RID_AT_IMPLEMENTATION,  D_OBJC },
3382   { "interface",        RID_AT_INTERFACE,       D_OBJC },
3383   { "private",          RID_AT_PRIVATE,         D_OBJC },
3384   { "protected",        RID_AT_PROTECTED,       D_OBJC },
3385   { "protocol",         RID_AT_PROTOCOL,        D_OBJC },
3386   { "public",           RID_AT_PUBLIC,          D_OBJC },
3387   { "selector",         RID_AT_SELECTOR,        D_OBJC },
3388
3389   /* These are recognized only in protocol-qualifier context
3390      (see above) */
3391   { "bycopy",           RID_BYCOPY,             D_OBJC },
3392   { "byref",            RID_BYREF,              D_OBJC },
3393   { "in",               RID_IN,                 D_OBJC },
3394   { "inout",            RID_INOUT,              D_OBJC },
3395   { "oneway",           RID_ONEWAY,             D_OBJC },
3396   { "out",              RID_OUT,                D_OBJC },
3397 end ifobjc
3398 };
3399 #define N_reswords (sizeof reswords / sizeof (struct resword))
3400
3401 /* Table mapping from RID_* constants to yacc token numbers.
3402    Unfortunately we have to have entries for all the keywords in all
3403    three languages.  */
3404 static const short rid_to_yy[RID_MAX] =
3405 {
3406   /* RID_STATIC */      STATIC,
3407   /* RID_UNSIGNED */    TYPESPEC,
3408   /* RID_LONG */        TYPESPEC,
3409   /* RID_CONST */       TYPE_QUAL,
3410   /* RID_EXTERN */      SCSPEC,
3411   /* RID_REGISTER */    SCSPEC,
3412   /* RID_TYPEDEF */     SCSPEC,
3413   /* RID_SHORT */       TYPESPEC,
3414   /* RID_INLINE */      SCSPEC,
3415   /* RID_VOLATILE */    TYPE_QUAL,
3416   /* RID_SIGNED */      TYPESPEC,
3417   /* RID_AUTO */        SCSPEC,
3418   /* RID_RESTRICT */    TYPE_QUAL,
3419
3420   /* C extensions */
3421   /* RID_COMPLEX */     TYPESPEC,
3422   /* RID_THREAD */      SCSPEC,
3423
3424   /* C++ */
3425   /* RID_FRIEND */      0,
3426   /* RID_VIRTUAL */     0,
3427   /* RID_EXPLICIT */    0,
3428   /* RID_EXPORT */      0,
3429   /* RID_MUTABLE */     0,
3430
3431   /* ObjC */
3432   /* RID_IN */          TYPE_QUAL,
3433   /* RID_OUT */         TYPE_QUAL,
3434   /* RID_INOUT */       TYPE_QUAL,
3435   /* RID_BYCOPY */      TYPE_QUAL,
3436   /* RID_BYREF */       TYPE_QUAL,
3437   /* RID_ONEWAY */      TYPE_QUAL,
3438
3439   /* C */
3440   /* RID_INT */         TYPESPEC,
3441   /* RID_CHAR */        TYPESPEC,
3442   /* RID_FLOAT */       TYPESPEC,
3443   /* RID_DOUBLE */      TYPESPEC,
3444   /* RID_VOID */        TYPESPEC,
3445   /* RID_ENUM */        ENUM,
3446   /* RID_STRUCT */      STRUCT,
3447   /* RID_UNION */       UNION,
3448   /* RID_IF */          IF,
3449   /* RID_ELSE */        ELSE,
3450   /* RID_WHILE */       WHILE,
3451   /* RID_DO */          DO,
3452   /* RID_FOR */         FOR,
3453   /* RID_SWITCH */      SWITCH,
3454   /* RID_CASE */        CASE,
3455   /* RID_DEFAULT */     DEFAULT,
3456   /* RID_BREAK */       BREAK,
3457   /* RID_CONTINUE */    CONTINUE,
3458   /* RID_RETURN */      RETURN,
3459   /* RID_GOTO */        GOTO,
3460   /* RID_SIZEOF */      SIZEOF,
3461
3462   /* C extensions */
3463   /* RID_ASM */         ASM_KEYWORD,
3464   /* RID_TYPEOF */      TYPEOF,
3465   /* RID_ALIGNOF */     ALIGNOF,
3466   /* RID_ATTRIBUTE */   ATTRIBUTE,
3467   /* RID_VA_ARG */      VA_ARG,
3468   /* RID_EXTENSION */   EXTENSION,
3469   /* RID_IMAGPART */    IMAGPART,
3470   /* RID_REALPART */    REALPART,
3471   /* RID_LABEL */       LABEL,
3472   /* RID_PTRBASE */     PTR_BASE,
3473   /* RID_PTREXTENT */   PTR_EXTENT,
3474   /* RID_PTRVALUE */    PTR_VALUE,
3475
3476   /* RID_CHOOSE_EXPR */                 CHOOSE_EXPR,
3477   /* RID_TYPES_COMPATIBLE_P */          TYPES_COMPATIBLE_P,
3478
3479   /* RID_FUNCTION_NAME */               FUNC_NAME,
3480   /* RID_PRETTY_FUNCTION_NAME */        FUNC_NAME,
3481   /* RID_C99_FUNCTION_NAME */           FUNC_NAME,
3482
3483   /* C++ */
3484   /* RID_BOOL */        TYPESPEC,
3485   /* RID_WCHAR */       0,
3486   /* RID_CLASS */       0,
3487   /* RID_PUBLIC */      0,
3488   /* RID_PRIVATE */     0,
3489   /* RID_PROTECTED */   0,
3490   /* RID_TEMPLATE */    0,
3491   /* RID_NULL */        0,
3492   /* RID_CATCH */       0,
3493   /* RID_DELETE */      0,
3494   /* RID_FALSE */       0,
3495   /* RID_NAMESPACE */   0,
3496   /* RID_NEW */         0,
3497   /* RID_OPERATOR */    0,
3498   /* RID_THIS */        0,
3499   /* RID_THROW */       0,
3500   /* RID_TRUE */        0,
3501   /* RID_TRY */         0,
3502   /* RID_TYPENAME */    0,
3503   /* RID_TYPEID */      0,
3504   /* RID_USING */       0,
3505
3506   /* casts */
3507   /* RID_CONSTCAST */   0,
3508   /* RID_DYNCAST */     0,
3509   /* RID_REINTCAST */   0,
3510   /* RID_STATCAST */    0,
3511
3512   /* Objective C */
3513   /* RID_ID */                  OBJECTNAME,
3514   /* RID_AT_ENCODE */           ENCODE,
3515   /* RID_AT_END */              END,
3516   /* RID_AT_CLASS */            CLASS,
3517   /* RID_AT_ALIAS */            ALIAS,
3518   /* RID_AT_DEFS */             DEFS,
3519   /* RID_AT_PRIVATE */          PRIVATE,
3520   /* RID_AT_PROTECTED */        PROTECTED,
3521   /* RID_AT_PUBLIC */           PUBLIC,
3522   /* RID_AT_PROTOCOL */         PROTOCOL,
3523   /* RID_AT_SELECTOR */         SELECTOR,
3524   /* RID_AT_INTERFACE */        INTERFACE,
3525   /* RID_AT_IMPLEMENTATION */   IMPLEMENTATION
3526 };
3527
3528 static void
3529 init_reswords (void)
3530 {
3531   unsigned int i;
3532   tree id;
3533   int mask = (flag_isoc99 ? 0 : D_C89)
3534               | (flag_no_asm ? (flag_isoc99 ? D_EXT : D_EXT|D_EXT89) : 0);
3535
3536   if (!c_dialect_objc ())
3537      mask |= D_OBJC;
3538
3539   ridpointers = (tree *) ggc_calloc ((int) RID_MAX, sizeof (tree));
3540   for (i = 0; i < N_reswords; i++)
3541     {
3542       /* If a keyword is disabled, do not enter it into the table
3543          and so create a canonical spelling that isn't a keyword.  */
3544       if (reswords[i].disable & mask)
3545         continue;
3546
3547       id = get_identifier (reswords[i].word);
3548       C_RID_CODE (id) = reswords[i].rid;
3549       C_IS_RESERVED_WORD (id) = 1;
3550       ridpointers [(int) reswords[i].rid] = id;
3551     }
3552 }
3553
3554 #define NAME(type) cpp_type2name (type)
3555
3556 static void
3557 yyerror (const char *msgid)
3558 {
3559   const char *string = _(msgid);
3560
3561   if (last_token == CPP_EOF)
3562     error ("%s at end of input", string);
3563   else if (last_token == CPP_CHAR || last_token == CPP_WCHAR)
3564     {
3565       unsigned int val = TREE_INT_CST_LOW (yylval.ttype);
3566       const char *const ell = (last_token == CPP_CHAR) ? "" : "L";
3567       if (val <= UCHAR_MAX && ISGRAPH (val))
3568         error ("%s before %s'%c'", string, ell, val);
3569       else
3570         error ("%s before %s'\\x%x'", string, ell, val);
3571     }
3572   else if (last_token == CPP_STRING
3573            || last_token == CPP_WSTRING)
3574     error ("%s before string constant", string);
3575   else if (last_token == CPP_NUMBER)
3576     error ("%s before numeric constant", string);
3577   else if (last_token == CPP_NAME)
3578     error ("%s before \"%s\"", string, IDENTIFIER_POINTER (yylval.ttype));
3579   else
3580     error ("%s before '%s' token", string, NAME(last_token));
3581 }
3582
3583 static int
3584 yylexname (void)
3585 {
3586   tree decl;
3587
3588 ifobjc
3589   int objc_force_identifier = objc_need_raw_identifier;
3590   OBJC_NEED_RAW_IDENTIFIER (0);
3591 end ifobjc
3592
3593   if (C_IS_RESERVED_WORD (yylval.ttype))
3594     {
3595       enum rid rid_code = C_RID_CODE (yylval.ttype);
3596
3597 ifobjc
3598       /* Turn non-typedefed refs to "id" into plain identifiers; this
3599          allows constructs like "void foo(id id);" to work.  */
3600       if (rid_code == RID_ID)
3601       {
3602         decl = lookup_name (yylval.ttype);
3603         if (decl == NULL_TREE || TREE_CODE (decl) != TYPE_DECL)
3604           return IDENTIFIER;
3605       }
3606
3607       if (!OBJC_IS_AT_KEYWORD (rid_code)
3608           && (!OBJC_IS_PQ_KEYWORD (rid_code) || objc_pq_context))
3609 end ifobjc
3610       {
3611         /* Return the canonical spelling for this keyword.  */
3612         yylval.ttype = ridpointers[(int) rid_code];
3613         return rid_to_yy[(int) rid_code];
3614       }
3615     }
3616
3617   decl = lookup_name (yylval.ttype);
3618   if (decl)
3619     {
3620       if (TREE_CODE (decl) == TYPE_DECL)
3621         return TYPENAME;
3622     }
3623 ifobjc
3624   else
3625     {
3626       tree objc_interface_decl = is_class_name (yylval.ttype);
3627       /* ObjC class names are in the same namespace as variables and
3628          typedefs, and hence are shadowed by local declarations.  */
3629       if (objc_interface_decl
3630           && (global_bindings_p ()
3631               || (!objc_force_identifier && !decl)))
3632         {
3633           yylval.ttype = objc_interface_decl;
3634           return CLASSNAME;
3635         }
3636     }
3637 end ifobjc
3638
3639   return IDENTIFIER;
3640 }
3641
3642 static inline int
3643 _yylex (void)
3644 {
3645  get_next:
3646   last_token = c_lex (&yylval.ttype);
3647   switch (last_token)
3648     {
3649     case CPP_EQ:                                        return '=';
3650     case CPP_NOT:                                       return '!';
3651     case CPP_GREATER:   yylval.code = GT_EXPR;          return ARITHCOMPARE;
3652     case CPP_LESS:      yylval.code = LT_EXPR;          return ARITHCOMPARE;
3653     case CPP_PLUS:      yylval.code = PLUS_EXPR;        return '+';
3654     case CPP_MINUS:     yylval.code = MINUS_EXPR;       return '-';
3655     case CPP_MULT:      yylval.code = MULT_EXPR;        return '*';
3656     case CPP_DIV:       yylval.code = TRUNC_DIV_EXPR;   return '/';
3657     case CPP_MOD:       yylval.code = TRUNC_MOD_EXPR;   return '%';
3658     case CPP_AND:       yylval.code = BIT_AND_EXPR;     return '&';
3659     case CPP_OR:        yylval.code = BIT_IOR_EXPR;     return '|';
3660     case CPP_XOR:       yylval.code = BIT_XOR_EXPR;     return '^';
3661     case CPP_RSHIFT:    yylval.code = RSHIFT_EXPR;      return RSHIFT;
3662     case CPP_LSHIFT:    yylval.code = LSHIFT_EXPR;      return LSHIFT;
3663
3664     case CPP_COMPL:                                     return '~';
3665     case CPP_AND_AND:                                   return ANDAND;
3666     case CPP_OR_OR:                                     return OROR;
3667     case CPP_QUERY:                                     return '?';
3668     case CPP_OPEN_PAREN:                                return '(';
3669     case CPP_EQ_EQ:     yylval.code = EQ_EXPR;          return EQCOMPARE;
3670     case CPP_NOT_EQ:    yylval.code = NE_EXPR;          return EQCOMPARE;
3671     case CPP_GREATER_EQ:yylval.code = GE_EXPR;          return ARITHCOMPARE;
3672     case CPP_LESS_EQ:   yylval.code = LE_EXPR;          return ARITHCOMPARE;
3673
3674     case CPP_PLUS_EQ:   yylval.code = PLUS_EXPR;        return ASSIGN;
3675     case CPP_MINUS_EQ:  yylval.code = MINUS_EXPR;       return ASSIGN;
3676     case CPP_MULT_EQ:   yylval.code = MULT_EXPR;        return ASSIGN;
3677     case CPP_DIV_EQ:    yylval.code = TRUNC_DIV_EXPR;   return ASSIGN;
3678     case CPP_MOD_EQ:    yylval.code = TRUNC_MOD_EXPR;   return ASSIGN;
3679     case CPP_AND_EQ:    yylval.code = BIT_AND_EXPR;     return ASSIGN;
3680     case CPP_OR_EQ:     yylval.code = BIT_IOR_EXPR;     return ASSIGN;
3681     case CPP_XOR_EQ:    yylval.code = BIT_XOR_EXPR;     return ASSIGN;
3682     case CPP_RSHIFT_EQ: yylval.code = RSHIFT_EXPR;      return ASSIGN;
3683     case CPP_LSHIFT_EQ: yylval.code = LSHIFT_EXPR;      return ASSIGN;
3684
3685     case CPP_OPEN_SQUARE:                               return '[';
3686     case CPP_CLOSE_SQUARE:                              return ']';
3687     case CPP_OPEN_BRACE:                                return '{';
3688     case CPP_CLOSE_BRACE:                               return '}';
3689     case CPP_ELLIPSIS:                                  return ELLIPSIS;
3690
3691     case CPP_PLUS_PLUS:                                 return PLUSPLUS;
3692     case CPP_MINUS_MINUS:                               return MINUSMINUS;
3693     case CPP_DEREF:                                     return POINTSAT;
3694     case CPP_DOT:                                       return '.';
3695
3696       /* The following tokens may affect the interpretation of any
3697          identifiers following, if doing Objective-C.  */
3698     case CPP_COLON:             OBJC_NEED_RAW_IDENTIFIER (0);   return ':';
3699     case CPP_COMMA:             OBJC_NEED_RAW_IDENTIFIER (0);   return ',';
3700     case CPP_CLOSE_PAREN:       OBJC_NEED_RAW_IDENTIFIER (0);   return ')';
3701     case CPP_SEMICOLON:         OBJC_NEED_RAW_IDENTIFIER (0);   return ';';
3702
3703     case CPP_EOF:
3704       return 0;
3705
3706     case CPP_NAME:
3707       return yylexname ();
3708
3709     case CPP_AT_NAME:
3710       /* This only happens in Objective-C; it must be a keyword.  */
3711       return rid_to_yy [(int) C_RID_CODE (yylval.ttype)];
3712
3713     case CPP_NUMBER:
3714     case CPP_CHAR:
3715     case CPP_WCHAR:
3716       return CONSTANT;
3717
3718     case CPP_STRING:
3719     case CPP_WSTRING:
3720       return STRING;
3721       
3722     case CPP_OBJC_STRING:
3723       return OBJC_STRING;
3724
3725       /* These tokens are C++ specific (and will not be generated
3726          in C mode, but let's be cautious).  */
3727     case CPP_SCOPE:
3728     case CPP_DEREF_STAR:
3729     case CPP_DOT_STAR:
3730     case CPP_MIN_EQ:
3731     case CPP_MAX_EQ:
3732     case CPP_MIN:
3733     case CPP_MAX:
3734       /* These tokens should not survive translation phase 4.  */
3735     case CPP_HASH:
3736     case CPP_PASTE:
3737       error ("syntax error at '%s' token", NAME(last_token));
3738       goto get_next;
3739
3740     default:
3741       abort ();
3742     }
3743   /* NOTREACHED */
3744 }
3745
3746 static int
3747 yylex (void)
3748 {
3749   int r;
3750   timevar_push (TV_LEX);
3751   r = _yylex();
3752   timevar_pop (TV_LEX);
3753   return r;
3754 }
3755
3756 /* Function used when yydebug is set, to print a token in more detail.  */
3757
3758 static void
3759 yyprint (FILE *file, int yychar, YYSTYPE yyl)
3760 {
3761   tree t = yyl.ttype;
3762
3763   fprintf (file, " [%s]", NAME(last_token));
3764
3765   switch (yychar)
3766     {
3767     case IDENTIFIER:
3768     case TYPENAME:
3769     case OBJECTNAME:
3770     case TYPESPEC:
3771     case TYPE_QUAL:
3772     case SCSPEC:
3773     case STATIC:
3774       if (IDENTIFIER_POINTER (t))
3775         fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
3776       break;
3777
3778     case CONSTANT:
3779       fprintf (file, " %s", GET_MODE_NAME (TYPE_MODE (TREE_TYPE (t))));
3780       if (TREE_CODE (t) == INTEGER_CST)
3781         {
3782           fputs (" ", file);
3783           fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
3784                    TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
3785         }
3786       break;
3787     }
3788 }
3789 \f
3790 /* This is not the ideal place to put these, but we have to get them out
3791    of c-lex.c because cp/lex.c has its own versions.  */
3792
3793 /* Free malloced parser stacks if necessary.  */
3794
3795 void
3796 free_parser_stacks (void)
3797 {
3798   if (malloced_yyss)
3799     {
3800       free (malloced_yyss);
3801       free (malloced_yyvs);
3802     }
3803 }
3804
3805 #include "gt-c-parse.h"