OSDN Git Service

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