OSDN Git Service

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