OSDN Git Service

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