OSDN Git Service

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