OSDN Git Service

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