OSDN Git Service

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