OSDN Git Service

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