OSDN Git Service

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