OSDN Git Service

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