OSDN Git Service

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