OSDN Git Service

* config/c4x/rtems.h: New file.
[pf3gnuchains/gcc-fork.git] / gcc / c-parse.y
1 /*WARNING: This file is automatically generated!*/
2 /* YACC parser for C syntax and for Objective C.  -*-c-*-
3    Copyright (C) 1987, 88, 89, 92-98, 1999 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 %expect 53
32
33 %{
34 #include "config.h"
35 #include "system.h"
36 #include <setjmp.h>
37 #include "tree.h"
38 #include "input.h"
39 #include "c-lex.h"
40 #include "c-tree.h"
41 #include "flags.h"
42 #include "output.h"
43 #include "toplev.h"
44 #include "ggc.h"
45   
46 #ifdef MULTIBYTE_CHARS
47 #include <locale.h>
48 #endif
49
50
51 /* Since parsers are distinct for each language, put the language string
52    definition here.  */
53 const char * const language_string = "GNU C";
54
55 /* Like YYERROR but do call yyerror.  */
56 #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
57
58 /* Cause the `yydebug' variable to be defined.  */
59 #define YYDEBUG 1
60 %}
61
62 %start program
63
64 %union {long itype; tree ttype; enum tree_code code;
65         char *filename; int lineno; int ends_in_label; }
66
67 /* All identifiers that are not reserved words
68    and are not declared typedefs in the current block */
69 %token IDENTIFIER
70
71 /* All identifiers that are declared typedefs in the current block.
72    In some contexts, they are treated just like IDENTIFIER,
73    but they can also serve as typespecs in declarations.  */
74 %token TYPENAME
75
76 /* Reserved words that specify storage class.
77    yylval contains an IDENTIFIER_NODE which indicates which one.  */
78 %token SCSPEC
79
80 /* Reserved words that specify type.
81    yylval contains an IDENTIFIER_NODE which indicates which one.  */
82 %token TYPESPEC
83
84 /* Reserved words that qualify type: "const", "volatile", or "restrict".
85    yylval contains an IDENTIFIER_NODE which indicates which one.  */
86 %token TYPE_QUAL
87
88 /* Character or numeric constants.
89    yylval is the node for the constant.  */
90 %token CONSTANT
91
92 /* String constants in raw form.
93    yylval is a STRING_CST node.  */
94 %token STRING
95
96 /* "...", used for functions with variable arglists.  */
97 %token ELLIPSIS
98
99 /* the reserved words */
100 /* SCO include files test "ASM", so use something else. */
101 %token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
102 %token BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF
103 %token ATTRIBUTE EXTENSION LABEL
104 %token REALPART IMAGPART VA_ARG
105
106 /* Used in c-lex.c for parsing pragmas.  */
107 %token END_OF_LINE
108
109 /* Add precedence rules to solve dangling else s/r conflict */
110 %nonassoc IF
111 %nonassoc ELSE
112
113 /* Define the operator tokens and their precedences.
114    The value is an integer because, if used, it is the tree code
115    to use in the expression made from the operator.  */
116
117 %right <code> ASSIGN '='
118 %right <code> '?' ':'
119 %left <code> OROR
120 %left <code> ANDAND
121 %left <code> '|'
122 %left <code> '^'
123 %left <code> '&'
124 %left <code> EQCOMPARE
125 %left <code> ARITHCOMPARE
126 %left <code> LSHIFT RSHIFT
127 %left <code> '+' '-'
128 %left <code> '*' '/' '%'
129 %right <code> UNARY PLUSPLUS MINUSMINUS
130 %left HYPERUNARY
131 %left <code> POINTSAT '.' '(' '['
132
133 /* The Objective-C keywords.  These are included in C and in
134    Objective C, so that the token codes are the same in both.  */
135 %token INTERFACE IMPLEMENTATION END SELECTOR DEFS ENCODE
136 %token CLASSNAME PUBLIC PRIVATE PROTECTED PROTOCOL OBJECTNAME CLASS ALIAS
137
138 /* Objective-C string constants in raw form.
139    yylval is an OBJC_STRING_CST node.  */
140 %token OBJC_STRING
141
142
143 %type <code> unop
144
145 %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist
146 %type <ttype> expr_no_commas cast_expr unary_expr primary string STRING
147 %type <ttype> typed_declspecs reserved_declspecs
148 %type <ttype> typed_typespecs reserved_typespecquals
149 %type <ttype> declmods typespec typespecqual_reserved
150 %type <ttype> typed_declspecs_no_prefix_attr reserved_declspecs_no_prefix_attr
151 %type <ttype> declmods_no_prefix_attr
152 %type <ttype> SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual
153 %type <ttype> initdecls notype_initdecls initdcl notype_initdcl
154 %type <ttype> init maybeasm
155 %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
156 %type <ttype> maybe_attribute attributes attribute attribute_list attrib
157 %type <ttype> any_word
158
159 %type <ttype> compstmt compstmt_nostart compstmt_primary_start
160
161 %type <ttype> declarator
162 %type <ttype> notype_declarator after_type_declarator
163 %type <ttype> parm_declarator
164
165 %type <ttype> structsp component_decl_list component_decl_list2
166 %type <ttype> component_decl components component_declarator
167 %type <ttype> enumlist enumerator
168 %type <ttype> struct_head union_head enum_head
169 %type <ttype> typename absdcl absdcl1 type_quals
170 %type <ttype> xexpr parms parm identifiers
171
172 %type <ttype> parmlist parmlist_1 parmlist_2
173 %type <ttype> parmlist_or_identifiers parmlist_or_identifiers_1
174 %type <ttype> identifiers_or_typenames
175
176 %type <itype> extension
177
178 %type <itype> setspecs
179
180 %type <ends_in_label> lineno_stmt_or_label lineno_stmt_or_labels stmt_or_label
181
182 %type <filename> save_filename
183 %type <lineno> save_lineno
184 \f
185 \f
186 %{
187 /* Number of statements (loosely speaking) and compound statements 
188    seen so far.  */
189 static int stmt_count;
190 static int compstmt_count;
191   
192 /* Input file and line number of the end of the body of last simple_if;
193    used by the stmt-rule immediately after simple_if returns.  */
194 static char *if_stmt_file;
195 static int if_stmt_line;
196
197 /* List of types and structure classes of the current declaration.  */
198 static tree current_declspecs = NULL_TREE;
199 static tree prefix_attributes = NULL_TREE;
200
201 /* Stack of saved values of current_declspecs and prefix_attributes.  */
202 static tree declspec_stack;
203
204 /* 1 if we explained undeclared var errors.  */
205 static int undeclared_variable_notice;
206
207 /* For __extension__, save/restore the warning flags which are
208    controlled by __extension__.  */
209 #define SAVE_WARN_FLAGS() (pedantic | (warn_pointer_arith << 1))
210 #define RESTORE_WARN_FLAGS(val) \
211   do {                                     \
212     pedantic = val & 1;                    \
213     warn_pointer_arith = (val >> 1) & 1;   \
214   } while (0)
215
216
217 /* Tell yyparse how to print a token's value, if yydebug is set.  */
218
219 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
220 extern void yyprint                     PROTO ((FILE *, int, YYSTYPE));
221
222 /* Add GC roots for variables local to this file.  */
223 void
224 c_parse_init ()
225 {
226   ggc_add_tree_root (&declspec_stack, 1);
227   ggc_add_tree_root (&current_declspecs, 1);
228   ggc_add_tree_root (&prefix_attributes, 1);
229 }
230
231 %}
232 \f
233 %%
234 program: /* empty */
235                 { if (pedantic)
236                     pedwarn ("ANSI C forbids an empty source file");
237                   finish_file ();
238                 }
239         | extdefs
240                 {
241                   /* In case there were missing closebraces,
242                      get us back to the global binding level.  */
243                   while (! global_bindings_p ())
244                     poplevel (0, 0, 0);
245                   finish_file ();
246                 }
247         ;
248
249 /* the reason for the strange actions in this rule
250  is so that notype_initdecls when reached via datadef
251  can find a valid list of type and sc specs in $0. */
252
253 extdefs:
254         {$<ttype>$ = NULL_TREE; } extdef
255         | extdefs {$<ttype>$ = NULL_TREE; } extdef
256         ;
257
258 extdef:
259         fndef
260         | datadef
261         | ASM_KEYWORD '(' expr ')' ';'
262                 { STRIP_NOPS ($3);
263                   if ((TREE_CODE ($3) == ADDR_EXPR
264                        && TREE_CODE (TREE_OPERAND ($3, 0)) == STRING_CST)
265                       || TREE_CODE ($3) == STRING_CST)
266                     assemble_asm ($3);
267                   else
268                     error ("argument of `asm' is not a constant string"); }
269         | extension extdef
270                 { RESTORE_WARN_FLAGS ($1); }
271         ;
272
273 datadef:
274           setspecs notype_initdecls ';'
275                 { if (pedantic)
276                     error ("ANSI C forbids data definition with no type or storage class");
277                   else if (!flag_traditional)
278                     warning ("data definition has no type or storage class"); 
279
280                   current_declspecs = TREE_VALUE (declspec_stack);
281                   prefix_attributes = TREE_PURPOSE (declspec_stack);
282                   declspec_stack = TREE_CHAIN (declspec_stack);
283                   resume_momentary ($1); }
284         | declmods setspecs notype_initdecls ';'
285                 { current_declspecs = TREE_VALUE (declspec_stack);
286                   prefix_attributes = TREE_PURPOSE (declspec_stack);
287                   declspec_stack = TREE_CHAIN (declspec_stack);
288                   resume_momentary ($2); }
289         | typed_declspecs setspecs initdecls ';'
290                 { current_declspecs = TREE_VALUE (declspec_stack);
291                   prefix_attributes = TREE_PURPOSE (declspec_stack);
292                   declspec_stack = TREE_CHAIN (declspec_stack);
293                   resume_momentary ($2);  }
294         | declmods ';'
295           { pedwarn ("empty declaration"); }
296         | typed_declspecs ';'
297           { shadow_tag ($1); }
298         | error ';'
299         | error '}'
300         | ';'
301                 { if (pedantic)
302                     pedwarn ("ANSI C does not allow extra `;' outside of a function"); }
303         ;
304 \f
305 fndef:
306           typed_declspecs setspecs declarator
307                 { if (! start_function (current_declspecs, $3,
308                                         prefix_attributes, NULL_TREE, 0))
309                     YYERROR1;
310                   reinit_parse_for_function (); }
311           old_style_parm_decls
312                 { store_parm_decls (); }
313           compstmt_or_error
314                 { finish_function (0); 
315                   current_declspecs = TREE_VALUE (declspec_stack);
316                   prefix_attributes = TREE_PURPOSE (declspec_stack);
317                   declspec_stack = TREE_CHAIN (declspec_stack);
318                   resume_momentary ($2); }
319         | typed_declspecs setspecs declarator error
320                 { current_declspecs = TREE_VALUE (declspec_stack);
321                   prefix_attributes = TREE_PURPOSE (declspec_stack);
322                   declspec_stack = TREE_CHAIN (declspec_stack);
323                   resume_momentary ($2); }
324         | declmods setspecs notype_declarator
325                 { if (! start_function (current_declspecs, $3,
326                                         prefix_attributes, NULL_TREE, 0))
327                     YYERROR1;
328                   reinit_parse_for_function (); }
329           old_style_parm_decls
330                 { store_parm_decls (); }
331           compstmt_or_error
332                 { finish_function (0); 
333                   current_declspecs = TREE_VALUE (declspec_stack);
334                   prefix_attributes = TREE_PURPOSE (declspec_stack);
335                   declspec_stack = TREE_CHAIN (declspec_stack);
336                   resume_momentary ($2); }
337         | declmods setspecs notype_declarator error
338                 { current_declspecs = TREE_VALUE (declspec_stack);
339                   prefix_attributes = TREE_PURPOSE (declspec_stack);
340                   declspec_stack = TREE_CHAIN (declspec_stack);
341                   resume_momentary ($2); }
342         | setspecs notype_declarator
343                 { if (! start_function (NULL_TREE, $2,
344                                         prefix_attributes, NULL_TREE, 0))
345                     YYERROR1;
346                   reinit_parse_for_function (); }
347           old_style_parm_decls
348                 { store_parm_decls (); }
349           compstmt_or_error
350                 { finish_function (0); 
351                   current_declspecs = TREE_VALUE (declspec_stack);
352                   prefix_attributes = TREE_PURPOSE (declspec_stack);
353                   declspec_stack = TREE_CHAIN (declspec_stack);
354                   resume_momentary ($1); }
355         | setspecs notype_declarator error
356                 { current_declspecs = TREE_VALUE (declspec_stack);
357                   prefix_attributes = TREE_PURPOSE (declspec_stack);
358                   declspec_stack = TREE_CHAIN (declspec_stack);
359                   resume_momentary ($1); }
360         ;
361
362 identifier:
363         IDENTIFIER
364         | TYPENAME
365         ;
366
367 unop:     '&'
368                 { $$ = ADDR_EXPR; }
369         | '-'
370                 { $$ = NEGATE_EXPR; }
371         | '+'
372                 { $$ = CONVERT_EXPR; }
373         | PLUSPLUS
374                 { $$ = PREINCREMENT_EXPR; }
375         | MINUSMINUS
376                 { $$ = PREDECREMENT_EXPR; }
377         | '~'
378                 { $$ = BIT_NOT_EXPR; }
379         | '!'
380                 { $$ = TRUTH_NOT_EXPR; }
381         ;
382
383 expr:   nonnull_exprlist
384                 { $$ = build_compound_expr ($1); }
385         ;
386
387 exprlist:
388           /* empty */
389                 { $$ = NULL_TREE; }
390         | nonnull_exprlist
391         ;
392
393 nonnull_exprlist:
394         expr_no_commas
395                 { $$ = build_tree_list (NULL_TREE, $1); }
396         | nonnull_exprlist ',' expr_no_commas
397                 { chainon ($1, build_tree_list (NULL_TREE, $3)); }
398         ;
399
400 unary_expr:
401         primary
402         | '*' cast_expr   %prec UNARY
403                 { $$ = build_indirect_ref ($2, "unary *"); }
404         /* __extension__ turns off -pedantic for following primary.  */
405         | extension cast_expr     %prec UNARY
406                 { $$ = $2;
407                   RESTORE_WARN_FLAGS ($1); }
408         | unop cast_expr  %prec UNARY
409                 { $$ = build_unary_op ($1, $2, 0);
410                   overflow_warning ($$); }
411         /* Refer to the address of a label as a pointer.  */
412         | ANDAND identifier
413                 { tree label = lookup_label ($2);
414                   if (pedantic)
415                     pedwarn ("ANSI C forbids `&&'");
416                   if (label == 0)
417                     $$ = null_pointer_node;
418                   else
419                     {
420                       TREE_USED (label) = 1;
421                       $$ = build1 (ADDR_EXPR, ptr_type_node, label);
422                       TREE_CONSTANT ($$) = 1;
423                     }
424                 }
425 /* This seems to be impossible on some machines, so let's turn it off.
426    You can use __builtin_next_arg to find the anonymous stack args.
427         | '&' ELLIPSIS
428                 { tree types = TYPE_ARG_TYPES (TREE_TYPE (current_function_decl));
429                   $$ = error_mark_node;
430                   if (TREE_VALUE (tree_last (types)) == void_type_node)
431                     error ("`&...' used in function with fixed number of arguments");
432                   else
433                     {
434                       if (pedantic)
435                         pedwarn ("ANSI C forbids `&...'");
436                       $$ = tree_last (DECL_ARGUMENTS (current_function_decl));
437                       $$ = build_unary_op (ADDR_EXPR, $$, 0);
438                     } }
439 */
440         | sizeof unary_expr  %prec UNARY
441                 { skip_evaluation--;
442                   if (TREE_CODE ($2) == COMPONENT_REF
443                       && DECL_C_BIT_FIELD (TREE_OPERAND ($2, 1)))
444                     error ("`sizeof' applied to a bit-field");
445                   $$ = c_sizeof (TREE_TYPE ($2)); }
446         | sizeof '(' typename ')'  %prec HYPERUNARY
447                 { skip_evaluation--;
448                   $$ = c_sizeof (groktypename ($3)); }
449         | alignof unary_expr  %prec UNARY
450                 { skip_evaluation--;
451                   $$ = c_alignof_expr ($2); }
452         | alignof '(' typename ')'  %prec HYPERUNARY
453                 { skip_evaluation--;
454                   $$ = c_alignof (groktypename ($3)); }
455         | REALPART cast_expr %prec UNARY
456                 { $$ = build_unary_op (REALPART_EXPR, $2, 0); }
457         | IMAGPART cast_expr %prec UNARY
458                 { $$ = build_unary_op (IMAGPART_EXPR, $2, 0); }
459         | VA_ARG '(' expr_no_commas ',' typename ')'
460                 { $$ = build_va_arg ($3, groktypename ($5)); }
461         ;
462
463 sizeof:
464         SIZEOF { skip_evaluation++; }
465         ;
466
467 alignof:
468         ALIGNOF { skip_evaluation++; }
469         ;
470
471 cast_expr:
472         unary_expr
473         | '(' typename ')' cast_expr  %prec UNARY
474                 { tree type = groktypename ($2);
475                   $$ = build_c_cast (type, $4); }
476         | '(' typename ')' '{' 
477                 { start_init (NULL_TREE, NULL, 0);
478                   $2 = groktypename ($2);
479                   really_start_incremental_init ($2); }
480           initlist_maybe_comma '}'  %prec UNARY
481                 { const char *name;
482                   tree result = pop_init_level (0);
483                   tree type = $2;
484                   finish_init ();
485
486                   if (pedantic && ! flag_isoc9x)
487                     pedwarn ("ANSI C forbids constructor expressions");
488                   if (TYPE_NAME (type) != 0)
489                     {
490                       if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
491                         name = IDENTIFIER_POINTER (TYPE_NAME (type));
492                       else
493                         name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
494                     }
495                   else
496                     name = "";
497                   $$ = result;
498                   if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
499                     {
500                       int failure = complete_array_type (type, $$, 1);
501                       if (failure)
502                         abort ();
503                     }
504                 }
505         ;
506
507 expr_no_commas:
508           cast_expr
509         | expr_no_commas '+' expr_no_commas
510                 { $$ = parser_build_binary_op ($2, $1, $3); }
511         | expr_no_commas '-' expr_no_commas
512                 { $$ = parser_build_binary_op ($2, $1, $3); }
513         | expr_no_commas '*' expr_no_commas
514                 { $$ = parser_build_binary_op ($2, $1, $3); }
515         | expr_no_commas '/' expr_no_commas
516                 { $$ = parser_build_binary_op ($2, $1, $3); }
517         | expr_no_commas '%' expr_no_commas
518                 { $$ = parser_build_binary_op ($2, $1, $3); }
519         | expr_no_commas LSHIFT expr_no_commas
520                 { $$ = parser_build_binary_op ($2, $1, $3); }
521         | expr_no_commas RSHIFT expr_no_commas
522                 { $$ = parser_build_binary_op ($2, $1, $3); }
523         | expr_no_commas ARITHCOMPARE expr_no_commas
524                 { $$ = parser_build_binary_op ($2, $1, $3); }
525         | expr_no_commas EQCOMPARE expr_no_commas
526                 { $$ = parser_build_binary_op ($2, $1, $3); }
527         | expr_no_commas '&' expr_no_commas
528                 { $$ = parser_build_binary_op ($2, $1, $3); }
529         | expr_no_commas '|' expr_no_commas
530                 { $$ = parser_build_binary_op ($2, $1, $3); }
531         | expr_no_commas '^' expr_no_commas
532                 { $$ = parser_build_binary_op ($2, $1, $3); }
533         | expr_no_commas ANDAND
534                 { $1 = truthvalue_conversion (default_conversion ($1));
535                   skip_evaluation += $1 == boolean_false_node; }
536           expr_no_commas
537                 { skip_evaluation -= $1 == boolean_false_node;
538                   $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $4); }
539         | expr_no_commas OROR
540                 { $1 = truthvalue_conversion (default_conversion ($1));
541                   skip_evaluation += $1 == boolean_true_node; }
542           expr_no_commas
543                 { skip_evaluation -= $1 == boolean_true_node;
544                   $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $4); }
545         | expr_no_commas '?'
546                 { $1 = truthvalue_conversion (default_conversion ($1));
547                   skip_evaluation += $1 == boolean_false_node; }
548           expr ':'
549                 { skip_evaluation += (($1 == boolean_true_node)
550                                       - ($1 == boolean_false_node)); }
551           expr_no_commas
552                 { skip_evaluation -= $1 == boolean_true_node;
553                   $$ = build_conditional_expr ($1, $4, $7); }
554         | expr_no_commas '?'
555                 { if (pedantic)
556                     pedwarn ("ANSI C forbids omitting the middle term of a ?: expression");
557                   /* Make sure first operand is calculated only once.  */
558                   $<ttype>2 = save_expr ($1);
559                   $1 = truthvalue_conversion (default_conversion ($<ttype>2));
560                   skip_evaluation += $1 == boolean_true_node; }
561           ':' expr_no_commas
562                 { skip_evaluation -= $1 == boolean_true_node;
563                   $$ = build_conditional_expr ($1, $<ttype>2, $5); }
564         | expr_no_commas '=' expr_no_commas
565                 { char class;
566                   $$ = build_modify_expr ($1, NOP_EXPR, $3);
567                   class = TREE_CODE_CLASS (TREE_CODE ($$));
568                   if (class == 'e' || class == '1'
569                       || class == '2' || class == '<')
570                     C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR);
571                 }
572         | expr_no_commas ASSIGN expr_no_commas
573                 { char class;
574                   $$ = build_modify_expr ($1, $2, $3);
575                   /* This inhibits warnings in truthvalue_conversion.  */
576                   class = TREE_CODE_CLASS (TREE_CODE ($$));
577                   if (class == 'e' || class == '1'
578                       || class == '2' || class == '<')
579                     C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK);
580                 }
581         ;
582
583 primary:
584         IDENTIFIER
585                 {
586                   $$ = lastiddecl;
587                   if (!$$ || $$ == error_mark_node)
588                     {
589                       if (yychar == YYEMPTY)
590                         yychar = YYLEX;
591                       if (yychar == '(')
592                         {
593                             {
594                               /* Ordinary implicit function declaration.  */
595                               $$ = implicitly_declare ($1);
596                               assemble_external ($$);
597                               TREE_USED ($$) = 1;
598                             }
599                         }
600                       else if (current_function_decl == 0)
601                         {
602                           error ("`%s' undeclared here (not in a function)",
603                                  IDENTIFIER_POINTER ($1));
604                           $$ = error_mark_node;
605                         }
606                       else
607                         {
608                             {
609                               if (IDENTIFIER_GLOBAL_VALUE ($1) != error_mark_node
610                                   || IDENTIFIER_ERROR_LOCUS ($1) != current_function_decl)
611                                 {
612                                   error ("`%s' undeclared (first use in this function)",
613                                          IDENTIFIER_POINTER ($1));
614
615                                   if (! undeclared_variable_notice)
616                                     {
617                                       error ("(Each undeclared identifier is reported only once");
618                                       error ("for each function it appears in.)");
619                                       undeclared_variable_notice = 1;
620                                     }
621                                 }
622                               $$ = error_mark_node;
623                               /* Prevent repeated error messages.  */
624                               IDENTIFIER_GLOBAL_VALUE ($1) = error_mark_node;
625                               IDENTIFIER_ERROR_LOCUS ($1) = current_function_decl;
626                             }
627                         }
628                     }
629                   else if (TREE_TYPE ($$) == error_mark_node)
630                     $$ = error_mark_node;
631                   else if (C_DECL_ANTICIPATED ($$))
632                     {
633                       /* The first time we see a build-in function used,
634                          if it has not been declared.  */
635                       C_DECL_ANTICIPATED ($$) = 0;
636                       if (yychar == YYEMPTY)
637                         yychar = YYLEX;
638                       if (yychar == '(')
639                         {
640                           /* Omit the implicit declaration we
641                              would ordinarily do, so we don't lose
642                              the actual built in type.
643                              But print a diagnostic for the mismatch.  */
644                             if (TREE_CODE ($$) != FUNCTION_DECL)
645                               error ("`%s' implicitly declared as function",
646                                      IDENTIFIER_POINTER (DECL_NAME ($$)));
647                           else if ((TYPE_MODE (TREE_TYPE (TREE_TYPE ($$)))
648                                     != TYPE_MODE (integer_type_node))
649                                    && (TREE_TYPE (TREE_TYPE ($$))
650                                        != void_type_node))
651                             pedwarn ("type mismatch in implicit declaration for built-in function `%s'",
652                                      IDENTIFIER_POINTER (DECL_NAME ($$)));
653                           /* If it really returns void, change that to int.  */
654                           if (TREE_TYPE (TREE_TYPE ($$)) == void_type_node)
655                             TREE_TYPE ($$)
656                               = build_function_type (integer_type_node,
657                                                      TYPE_ARG_TYPES (TREE_TYPE ($$)));
658                         }
659                       else
660                         pedwarn ("built-in function `%s' used without declaration",
661                                  IDENTIFIER_POINTER (DECL_NAME ($$)));
662
663                       /* Do what we would ordinarily do when a fn is used.  */
664                       assemble_external ($$);
665                       TREE_USED ($$) = 1;
666                     }
667                   else
668                     {
669                       assemble_external ($$);
670                       TREE_USED ($$) = 1;
671                     }
672
673                   if (TREE_CODE ($$) == CONST_DECL)
674                     {
675                       $$ = DECL_INITIAL ($$);
676                       /* This is to prevent an enum whose value is 0
677                          from being considered a null pointer constant.  */
678                       $$ = build1 (NOP_EXPR, TREE_TYPE ($$), $$);
679                       TREE_CONSTANT ($$) = 1;
680                     }
681                 }
682         | CONSTANT
683         | string
684                 { $$ = combine_strings ($1); }
685         | '(' expr ')'
686                 { char class = TREE_CODE_CLASS (TREE_CODE ($2));
687                   if (class == 'e' || class == '1'
688                       || class == '2' || class == '<')
689                     C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK);
690                   $$ = $2; }
691         | '(' error ')'
692                 { $$ = error_mark_node; }
693         | compstmt_primary_start compstmt_nostart ')'
694                 { tree rtl_exp;
695                   if (pedantic)
696                     pedwarn ("ANSI C forbids braced-groups within expressions");
697                   pop_iterator_stack ();
698                   pop_label_level ();
699                   rtl_exp = expand_end_stmt_expr ($1);
700                   /* The statements have side effects, so the group does.  */
701                   TREE_SIDE_EFFECTS (rtl_exp) = 1;
702
703                   if (TREE_CODE ($2) == BLOCK)
704                     {
705                       /* Make a BIND_EXPR for the BLOCK already made.  */
706                       $$ = build (BIND_EXPR, TREE_TYPE (rtl_exp),
707                                   NULL_TREE, rtl_exp, $2);
708                       /* Remove the block from the tree at this point.
709                          It gets put back at the proper place
710                          when the BIND_EXPR is expanded.  */
711                       delete_block ($2);
712                     }
713                   else
714                     $$ = $2;
715                 }
716         | compstmt_primary_start error ')'
717                 {
718                   /* Make sure we call expand_end_stmt_expr.  Otherwise
719                      we are likely to lose sequences and crash later.  */
720                   pop_iterator_stack ();
721                   pop_label_level ();
722                   expand_end_stmt_expr ($1);
723                   $$ = error_mark_node;
724                 }
725         | primary '(' exprlist ')'   %prec '.'
726                 { $$ = build_function_call ($1, $3); }
727         | primary '[' expr ']'   %prec '.'
728                 { $$ = build_array_ref ($1, $3); }
729         | primary '.' identifier
730                 {
731                     $$ = build_component_ref ($1, $3);
732                 }
733         | primary POINTSAT identifier
734                 {
735                   tree expr = build_indirect_ref ($1, "->");
736
737                     $$ = build_component_ref (expr, $3);
738                 }
739         | primary PLUSPLUS
740                 { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
741         | primary MINUSMINUS
742                 { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
743         ;
744
745 /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it.  */
746 string:
747           STRING
748         | string STRING
749                 { $$ = chainon ($1, $2);
750                   if (warn_traditional && !in_system_header)
751                     warning ("Use of ANSI string concatenation");
752                 }
753         ;
754
755
756 old_style_parm_decls:
757         /* empty */
758         | datadecls
759         | datadecls ELLIPSIS
760                 /* ... is used here to indicate a varargs function.  */
761                 { c_mark_varargs ();
762                   if (pedantic)
763                     pedwarn ("ANSI C does not permit use of `varargs.h'"); }
764         ;
765
766 /* The following are analogous to lineno_decl, decls and decl
767    except that they do not allow nested functions.
768    They are used for old-style parm decls.  */
769 lineno_datadecl:
770           save_filename save_lineno datadecl
771                 { }
772         ;
773
774 datadecls:
775         lineno_datadecl
776         | errstmt
777         | datadecls lineno_datadecl
778         | lineno_datadecl errstmt
779         ;
780
781 /* We don't allow prefix attributes here because they cause reduce/reduce
782    conflicts: we can't know whether we're parsing a function decl with
783    attribute suffix, or function defn with attribute prefix on first old
784    style parm.  */
785 datadecl:
786         typed_declspecs_no_prefix_attr setspecs initdecls ';'
787                 { current_declspecs = TREE_VALUE (declspec_stack);
788                   prefix_attributes = TREE_PURPOSE (declspec_stack);
789                   declspec_stack = TREE_CHAIN (declspec_stack);
790                   resume_momentary ($2); }
791         | declmods_no_prefix_attr setspecs notype_initdecls ';'
792                 { current_declspecs = TREE_VALUE (declspec_stack);      
793                   prefix_attributes = TREE_PURPOSE (declspec_stack);
794                   declspec_stack = TREE_CHAIN (declspec_stack);
795                   resume_momentary ($2); }
796         | typed_declspecs_no_prefix_attr ';'
797                 { shadow_tag_warned ($1, 1);
798                   pedwarn ("empty declaration"); }
799         | declmods_no_prefix_attr ';'
800                 { pedwarn ("empty declaration"); }
801         ;
802
803 /* This combination which saves a lineno before a decl
804    is the normal thing to use, rather than decl itself.
805    This is to avoid shift/reduce conflicts in contexts
806    where statement labels are allowed.  */
807 lineno_decl:
808           save_filename save_lineno decl
809                 { }
810         ;
811
812 decls:
813         lineno_decl
814         | errstmt
815         | decls lineno_decl
816         | lineno_decl errstmt
817         ;
818
819 /* records the type and storage class specs to use for processing
820    the declarators that follow.
821    Maintains a stack of outer-level values of current_declspecs,
822    for the sake of parm declarations nested in function declarators.  */
823 setspecs: /* empty */
824                 { $$ = suspend_momentary ();
825                   pending_xref_error ();
826                   declspec_stack = tree_cons (prefix_attributes,
827                                               current_declspecs,
828                                               declspec_stack);
829                   split_specs_attrs ($<ttype>0,
830                                      &current_declspecs, &prefix_attributes); }
831         ;
832
833 /* ??? Yuck.  See after_type_declarator.  */
834 setattrs: /* empty */
835                 { prefix_attributes = chainon (prefix_attributes, $<ttype>0); }
836         ;
837
838 decl:
839         typed_declspecs setspecs initdecls ';'
840                 { current_declspecs = TREE_VALUE (declspec_stack);
841                   prefix_attributes = TREE_PURPOSE (declspec_stack);
842                   declspec_stack = TREE_CHAIN (declspec_stack);
843                   resume_momentary ($2); }
844         | declmods setspecs notype_initdecls ';'
845                 { current_declspecs = TREE_VALUE (declspec_stack);
846                   prefix_attributes = TREE_PURPOSE (declspec_stack);
847                   declspec_stack = TREE_CHAIN (declspec_stack);
848                   resume_momentary ($2); }
849         | typed_declspecs setspecs nested_function
850                 { current_declspecs = TREE_VALUE (declspec_stack);
851                   prefix_attributes = TREE_PURPOSE (declspec_stack);
852                   declspec_stack = TREE_CHAIN (declspec_stack);
853                   resume_momentary ($2); }
854         | declmods setspecs notype_nested_function
855                 { current_declspecs = TREE_VALUE (declspec_stack);
856                   prefix_attributes = TREE_PURPOSE (declspec_stack);
857                   declspec_stack = TREE_CHAIN (declspec_stack);
858                   resume_momentary ($2); }
859         | typed_declspecs ';'
860                 { shadow_tag ($1); }
861         | declmods ';'
862                 { pedwarn ("empty declaration"); }
863         | extension decl
864                 { RESTORE_WARN_FLAGS ($1); }
865         ;
866
867 /* Declspecs which contain at least one type specifier or typedef name.
868    (Just `const' or `volatile' is not enough.)
869    A typedef'd name following these is taken as a name to be declared.
870    Declspecs have a non-NULL TREE_VALUE, attributes do not.  */
871
872 typed_declspecs:
873           typespec reserved_declspecs
874                 { $$ = tree_cons (NULL_TREE, $1, $2); }
875         | declmods typespec reserved_declspecs
876                 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
877         ;
878
879 reserved_declspecs:  /* empty */
880                 { $$ = NULL_TREE; }
881         | reserved_declspecs typespecqual_reserved
882                 { $$ = tree_cons (NULL_TREE, $2, $1); }
883         | reserved_declspecs SCSPEC
884                 { if (extra_warnings)
885                     warning ("`%s' is not at beginning of declaration",
886                              IDENTIFIER_POINTER ($2));
887                   $$ = tree_cons (NULL_TREE, $2, $1); }
888         | reserved_declspecs attributes
889                 { $$ = tree_cons ($2, NULL_TREE, $1); }
890         ;
891
892 typed_declspecs_no_prefix_attr:
893           typespec reserved_declspecs_no_prefix_attr
894                 { $$ = tree_cons (NULL_TREE, $1, $2); }
895         | declmods_no_prefix_attr typespec reserved_declspecs_no_prefix_attr
896                 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
897         ;
898
899 reserved_declspecs_no_prefix_attr:
900           /* empty */
901                 { $$ = NULL_TREE; }
902         | reserved_declspecs_no_prefix_attr typespecqual_reserved
903                 { $$ = tree_cons (NULL_TREE, $2, $1); }
904         | reserved_declspecs_no_prefix_attr SCSPEC
905                 { if (extra_warnings)
906                     warning ("`%s' is not at beginning of declaration",
907                              IDENTIFIER_POINTER ($2));
908                   $$ = tree_cons (NULL_TREE, $2, $1); }
909         ;
910
911 /* List of just storage classes, type modifiers, and prefix attributes.
912    A declaration can start with just this, but then it cannot be used
913    to redeclare a typedef-name.
914    Declspecs have a non-NULL TREE_VALUE, attributes do not.  */
915
916 declmods:
917           declmods_no_prefix_attr
918                 { $$ = $1; }
919         | attributes
920                 { $$ = tree_cons ($1, NULL_TREE, NULL_TREE); }
921         | declmods declmods_no_prefix_attr
922                 { $$ = chainon ($2, $1); }
923         | declmods attributes
924                 { $$ = tree_cons ($2, NULL_TREE, $1); }
925         ;
926
927 declmods_no_prefix_attr:
928           TYPE_QUAL
929                 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
930                   TREE_STATIC ($$) = 1; }
931         | SCSPEC
932                 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
933         | declmods_no_prefix_attr TYPE_QUAL
934                 { $$ = tree_cons (NULL_TREE, $2, $1);
935                   TREE_STATIC ($$) = 1; }
936         | declmods_no_prefix_attr SCSPEC
937                 { if (extra_warnings && TREE_STATIC ($1))
938                     warning ("`%s' is not at beginning of declaration",
939                              IDENTIFIER_POINTER ($2));
940                   $$ = tree_cons (NULL_TREE, $2, $1);
941                   TREE_STATIC ($$) = TREE_STATIC ($1); }
942         ;
943
944
945 /* Used instead of declspecs where storage classes are not allowed
946    (that is, for typenames and structure components).
947    Don't accept a typedef-name if anything but a modifier precedes it.  */
948
949 typed_typespecs:
950           typespec reserved_typespecquals
951                 { $$ = tree_cons (NULL_TREE, $1, $2); }
952         | nonempty_type_quals typespec reserved_typespecquals
953                 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
954         ;
955
956 reserved_typespecquals:  /* empty */
957                 { $$ = NULL_TREE; }
958         | reserved_typespecquals typespecqual_reserved
959                 { $$ = tree_cons (NULL_TREE, $2, $1); }
960         ;
961
962 /* A typespec (but not a type qualifier).
963    Once we have seen one of these in a declaration,
964    if a typedef name appears then it is being redeclared.  */
965
966 typespec: TYPESPEC
967         | structsp
968         | TYPENAME
969                 { /* For a typedef name, record the meaning, not the name.
970                      In case of `foo foo, bar;'.  */
971                   $$ = lookup_name ($1); }
972         | TYPEOF '(' expr ')'
973                 { $$ = TREE_TYPE ($3); }
974         | TYPEOF '(' typename ')'
975                 { $$ = groktypename ($3); }
976         ;
977
978 /* A typespec that is a reserved word, or a type qualifier.  */
979
980 typespecqual_reserved: TYPESPEC
981         | TYPE_QUAL
982         | structsp
983         ;
984
985 initdecls:
986         initdcl
987         | initdecls ',' initdcl
988         ;
989
990 notype_initdecls:
991         notype_initdcl
992         | notype_initdecls ',' initdcl
993         ;
994
995 maybeasm:
996           /* empty */
997                 { $$ = NULL_TREE; }
998         | ASM_KEYWORD '(' string ')'
999                 { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
1000                   $$ = $3;
1001                 }
1002         ;
1003
1004 initdcl:
1005           declarator maybeasm maybe_attribute '='
1006                 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1007                                           $3, prefix_attributes);
1008                   start_init ($<ttype>$, $2, global_bindings_p ()); }
1009           init
1010 /* Note how the declaration of the variable is in effect while its init is parsed! */
1011                 { finish_init ();
1012                   finish_decl ($<ttype>5, $6, $2); }
1013         | declarator maybeasm maybe_attribute
1014                 { tree d = start_decl ($1, current_declspecs, 0,
1015                                        $3, prefix_attributes);
1016                   finish_decl (d, NULL_TREE, $2); 
1017                 }
1018         ;
1019
1020 notype_initdcl:
1021           notype_declarator maybeasm maybe_attribute '='
1022                 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1023                                           $3, prefix_attributes);
1024                   start_init ($<ttype>$, $2, global_bindings_p ()); }
1025           init
1026 /* Note how the declaration of the variable is in effect while its init is parsed! */
1027                 { finish_init ();
1028                   decl_attributes ($<ttype>5, $3, prefix_attributes);
1029                   finish_decl ($<ttype>5, $6, $2); }
1030         | notype_declarator maybeasm maybe_attribute
1031                 { tree d = start_decl ($1, current_declspecs, 0,
1032                                        $3, prefix_attributes);
1033                   finish_decl (d, NULL_TREE, $2); }
1034         ;
1035 /* the * rules are dummies to accept the Apollo extended syntax
1036    so that the header files compile. */
1037 maybe_attribute:
1038       /* empty */
1039                 { $$ = NULL_TREE; }
1040         | attributes
1041                 { $$ = $1; }
1042         ;
1043  
1044 attributes:
1045       attribute
1046                 { $$ = $1; }
1047         | attributes attribute
1048                 { $$ = chainon ($1, $2); }
1049         ;
1050
1051 attribute:
1052       ATTRIBUTE '(' '(' attribute_list ')' ')'
1053                 { $$ = $4; }
1054         ;
1055
1056 attribute_list:
1057       attrib
1058                 { $$ = $1; }
1059         | attribute_list ',' attrib
1060                 { $$ = chainon ($1, $3); }
1061         ;
1062  
1063 attrib:
1064     /* empty */
1065                 { $$ = NULL_TREE; }
1066         | any_word
1067                 { $$ = build_tree_list ($1, NULL_TREE); }
1068         | any_word '(' IDENTIFIER ')'
1069                 { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
1070         | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
1071                 { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
1072         | any_word '(' exprlist ')'
1073                 { $$ = build_tree_list ($1, $3); }
1074         ;
1075
1076 /* This still leaves out most reserved keywords,
1077    shouldn't we include them?  */
1078
1079 any_word:
1080           identifier
1081         | SCSPEC
1082         | TYPESPEC
1083         | TYPE_QUAL
1084         ;
1085 \f
1086 /* Initializers.  `init' is the entry point.  */
1087
1088 init:
1089         expr_no_commas
1090         | '{'
1091                 { really_start_incremental_init (NULL_TREE);
1092                   /* Note that the call to clear_momentary
1093                      is in process_init_element.  */
1094                   push_momentary (); }
1095           initlist_maybe_comma '}'
1096                 { $$ = pop_init_level (0);
1097                   if ($$ == error_mark_node
1098                       && ! (yychar == STRING || yychar == CONSTANT))
1099                     pop_momentary ();
1100                   else
1101                     pop_momentary_nofree (); }
1102
1103         | error
1104                 { $$ = error_mark_node; }
1105         ;
1106
1107 /* `initlist_maybe_comma' is the guts of an initializer in braces.  */
1108 initlist_maybe_comma:
1109           /* empty */
1110                 { if (pedantic)
1111                     pedwarn ("ANSI C forbids empty initializer braces"); }
1112         | initlist1 maybecomma
1113         ;
1114
1115 initlist1:
1116           initelt
1117         | initlist1 ',' initelt
1118         ;
1119
1120 /* `initelt' is a single element of an initializer.
1121    It may use braces.  */
1122 initelt:
1123           designator_list '=' initval
1124         | designator initval
1125         | identifier ':'
1126                 { set_init_label ($1); }
1127           initval
1128         | initval
1129         ;
1130
1131 initval:
1132           '{'
1133                 { push_init_level (0); }
1134           initlist_maybe_comma '}'
1135                 { process_init_element (pop_init_level (0)); }
1136         | expr_no_commas
1137                 { process_init_element ($1); }
1138         | error
1139         ;
1140
1141 designator_list:
1142           designator
1143         | designator_list designator
1144         ;
1145
1146 designator:
1147           '.' identifier
1148                 { set_init_label ($2); }
1149         /* These are for labeled elements.  The syntax for an array element
1150            initializer conflicts with the syntax for an Objective-C message,
1151            so don't include these productions in the Objective-C grammar.  */
1152         | '[' expr_no_commas ELLIPSIS expr_no_commas ']'
1153                 { set_init_index ($2, $4); }
1154         | '[' expr_no_commas ']'
1155                 { set_init_index ($2, NULL_TREE); }
1156         ;
1157 \f
1158 nested_function:
1159           declarator
1160                 { if (pedantic)
1161                     pedwarn ("ANSI C forbids nested functions");
1162
1163                   push_function_context ();
1164                   if (! start_function (current_declspecs, $1,
1165                                         prefix_attributes, NULL_TREE, 1))
1166                     {
1167                       pop_function_context ();
1168                       YYERROR1;
1169                     }
1170                   reinit_parse_for_function (); }
1171            old_style_parm_decls
1172                 { store_parm_decls (); }
1173 /* This used to use compstmt_or_error.
1174    That caused a bug with input `f(g) int g {}',
1175    where the use of YYERROR1 above caused an error
1176    which then was handled by compstmt_or_error.
1177    There followed a repeated execution of that same rule,
1178    which called YYERROR1 again, and so on.  */
1179           compstmt
1180                 { finish_function (1);
1181                   pop_function_context (); }
1182         ;
1183
1184 notype_nested_function:
1185           notype_declarator
1186                 { if (pedantic)
1187                     pedwarn ("ANSI C forbids nested functions");
1188
1189                   push_function_context ();
1190                   if (! start_function (current_declspecs, $1,
1191                                         prefix_attributes, NULL_TREE, 1))
1192                     {
1193                       pop_function_context ();
1194                       YYERROR1;
1195                     }
1196                   reinit_parse_for_function (); }
1197           old_style_parm_decls
1198                 { store_parm_decls (); }
1199 /* This used to use compstmt_or_error.
1200    That caused a bug with input `f(g) int g {}',
1201    where the use of YYERROR1 above caused an error
1202    which then was handled by compstmt_or_error.
1203    There followed a repeated execution of that same rule,
1204    which called YYERROR1 again, and so on.  */
1205           compstmt
1206                 { finish_function (1);
1207                   pop_function_context (); }
1208         ;
1209
1210 /* Any kind of declarator (thus, all declarators allowed
1211    after an explicit typespec).  */
1212
1213 declarator:
1214           after_type_declarator
1215         | notype_declarator
1216         ;
1217
1218 /* A declarator that is allowed only after an explicit typespec.  */
1219
1220 after_type_declarator:
1221           '(' after_type_declarator ')'
1222                 { $$ = $2; }
1223         | after_type_declarator '(' parmlist_or_identifiers  %prec '.'
1224                 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1225 /*      | after_type_declarator '(' error ')'  %prec '.'
1226                 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1227                   poplevel (0, 0, 0); }  */
1228         | after_type_declarator '[' expr ']'  %prec '.'
1229                 { $$ = build_nt (ARRAY_REF, $1, $3); }
1230         | after_type_declarator '[' ']'  %prec '.'
1231                 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1232         | '*' type_quals after_type_declarator  %prec UNARY
1233                 { $$ = make_pointer_declarator ($2, $3); }
1234         /* ??? Yuck.  setattrs is a quick hack.  We can't use
1235            prefix_attributes because $1 only applies to this
1236            declarator.  We assume setspecs has already been done.
1237            setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1238            attributes could be recognized here or in `attributes').  */
1239         | attributes setattrs after_type_declarator
1240                 { $$ = $3; }
1241         | TYPENAME
1242         ;
1243
1244 /* Kinds of declarator that can appear in a parameter list
1245    in addition to notype_declarator.  This is like after_type_declarator
1246    but does not allow a typedef name in parentheses as an identifier
1247    (because it would conflict with a function with that typedef as arg).  */
1248
1249 parm_declarator:
1250           parm_declarator '(' parmlist_or_identifiers  %prec '.'
1251                 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1252 /*      | parm_declarator '(' error ')'  %prec '.'
1253                 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1254                   poplevel (0, 0, 0); }  */
1255         | parm_declarator '[' '*' ']'  %prec '.'
1256                 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE);
1257                   if (! flag_isoc9x)
1258                     error ("`[*]' in parameter declaration only allowed in ISO C 9x");
1259                 }
1260         | parm_declarator '[' expr ']'  %prec '.'
1261                 { $$ = build_nt (ARRAY_REF, $1, $3); }
1262         | parm_declarator '[' ']'  %prec '.'
1263                 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1264         | '*' type_quals parm_declarator  %prec UNARY
1265                 { $$ = make_pointer_declarator ($2, $3); }
1266         /* ??? Yuck.  setattrs is a quick hack.  We can't use
1267            prefix_attributes because $1 only applies to this
1268            declarator.  We assume setspecs has already been done.
1269            setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1270            attributes could be recognized here or in `attributes').  */
1271         | attributes setattrs parm_declarator
1272                 { $$ = $3; }
1273         | TYPENAME
1274         ;
1275
1276 /* A declarator allowed whether or not there has been
1277    an explicit typespec.  These cannot redeclare a typedef-name.  */
1278
1279 notype_declarator:
1280           notype_declarator '(' parmlist_or_identifiers  %prec '.'
1281                 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1282 /*      | notype_declarator '(' error ')'  %prec '.'
1283                 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1284                   poplevel (0, 0, 0); }  */
1285         | '(' notype_declarator ')'
1286                 { $$ = $2; }
1287         | '*' type_quals notype_declarator  %prec UNARY
1288                 { $$ = make_pointer_declarator ($2, $3); }
1289         | notype_declarator '[' '*' ']'  %prec '.'
1290                 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE);
1291                   if (! flag_isoc9x)
1292                     error ("`[*]' in parameter declaration only allowed in ISO C 9x");
1293                 }
1294         | notype_declarator '[' expr ']'  %prec '.'
1295                 { $$ = build_nt (ARRAY_REF, $1, $3); }
1296         | notype_declarator '[' ']'  %prec '.'
1297                 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1298         /* ??? Yuck.  setattrs is a quick hack.  We can't use
1299            prefix_attributes because $1 only applies to this
1300            declarator.  We assume setspecs has already been done.
1301            setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1302            attributes could be recognized here or in `attributes').  */
1303         | attributes setattrs notype_declarator
1304                 { $$ = $3; }
1305         | IDENTIFIER
1306         ;
1307
1308 struct_head:
1309           STRUCT
1310                 { $$ = NULL_TREE; }
1311         | STRUCT attributes
1312                 { $$ = $2; }
1313         ;
1314
1315 union_head:
1316           UNION
1317                 { $$ = NULL_TREE; }
1318         | UNION attributes
1319                 { $$ = $2; }
1320         ;
1321
1322 enum_head:
1323           ENUM
1324                 { $$ = NULL_TREE; }
1325         | ENUM attributes
1326                 { $$ = $2; }
1327         ;
1328
1329 structsp:
1330           struct_head identifier '{'
1331                 { $$ = start_struct (RECORD_TYPE, $2);
1332                   /* Start scope of tag before parsing components.  */
1333                 }
1334           component_decl_list '}' maybe_attribute 
1335                 { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
1336         | struct_head '{' component_decl_list '}' maybe_attribute
1337                 { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
1338                                       $3, chainon ($1, $5));
1339                 }
1340         | struct_head identifier
1341                 { $$ = xref_tag (RECORD_TYPE, $2); }
1342         | union_head identifier '{'
1343                 { $$ = start_struct (UNION_TYPE, $2); }
1344           component_decl_list '}' maybe_attribute
1345                 { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
1346         | union_head '{' component_decl_list '}' maybe_attribute
1347                 { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
1348                                       $3, chainon ($1, $5));
1349                 }
1350         | union_head identifier
1351                 { $$ = xref_tag (UNION_TYPE, $2); }
1352         | enum_head identifier '{'
1353                 { $<itype>3 = suspend_momentary ();
1354                   $$ = start_enum ($2); }
1355           enumlist maybecomma_warn '}' maybe_attribute
1356                 { $$= finish_enum ($<ttype>4, nreverse ($5), chainon ($1, $8));
1357                   resume_momentary ($<itype>3); }
1358         | enum_head '{'
1359                 { $<itype>2 = suspend_momentary ();
1360                   $$ = start_enum (NULL_TREE); }
1361           enumlist maybecomma_warn '}' maybe_attribute
1362                 { $$= finish_enum ($<ttype>3, nreverse ($4), chainon ($1, $7));
1363                   resume_momentary ($<itype>2); }
1364         | enum_head identifier
1365                 { $$ = xref_tag (ENUMERAL_TYPE, $2); }
1366         ;
1367
1368 maybecomma:
1369           /* empty */
1370         | ','
1371         ;
1372
1373 maybecomma_warn:
1374           /* empty */
1375         | ','
1376                 { if (pedantic && ! flag_isoc9x)
1377                     pedwarn ("comma at end of enumerator list"); }
1378         ;
1379
1380 component_decl_list:
1381           component_decl_list2
1382                 { $$ = $1; }
1383         | component_decl_list2 component_decl
1384                 { $$ = chainon ($1, $2);
1385                   pedwarn ("no semicolon at end of struct or union"); }
1386         ;
1387
1388 component_decl_list2:   /* empty */
1389                 { $$ = NULL_TREE; }
1390         | component_decl_list2 component_decl ';'
1391                 { $$ = chainon ($1, $2); }
1392         | component_decl_list2 ';'
1393                 { if (pedantic)
1394                     pedwarn ("extra semicolon in struct or union specified"); }
1395         ;
1396
1397 /* There is a shift-reduce conflict here, because `components' may
1398    start with a `typename'.  It happens that shifting (the default resolution)
1399    does the right thing, because it treats the `typename' as part of
1400    a `typed_typespecs'.
1401
1402    It is possible that this same technique would allow the distinction
1403    between `notype_initdecls' and `initdecls' to be eliminated.
1404    But I am being cautious and not trying it.  */
1405
1406 component_decl:
1407           typed_typespecs setspecs components
1408                 { $$ = $3;
1409                   current_declspecs = TREE_VALUE (declspec_stack);
1410                   prefix_attributes = TREE_PURPOSE (declspec_stack);
1411                   declspec_stack = TREE_CHAIN (declspec_stack);
1412                   resume_momentary ($2); }
1413         | typed_typespecs setspecs save_filename save_lineno maybe_attribute
1414                 {
1415                   /* Support for unnamed structs or unions as members of 
1416                      structs or unions (which is [a] useful and [b] supports 
1417                      MS P-SDK).  */
1418                   if (pedantic)
1419                     pedwarn ("ANSI C doesn't support unnamed structs/unions");
1420
1421                   $$ = grokfield($3, $4, NULL, current_declspecs, NULL_TREE);
1422                   current_declspecs = TREE_VALUE (declspec_stack);
1423                   prefix_attributes = TREE_PURPOSE (declspec_stack);
1424                   declspec_stack = TREE_CHAIN (declspec_stack);
1425                   resume_momentary ($2);
1426                 }
1427     | nonempty_type_quals setspecs components
1428                 { $$ = $3;
1429                   current_declspecs = TREE_VALUE (declspec_stack);
1430                   prefix_attributes = TREE_PURPOSE (declspec_stack);
1431                   declspec_stack = TREE_CHAIN (declspec_stack);
1432                   resume_momentary ($2); }
1433         | nonempty_type_quals
1434                 { if (pedantic)
1435                     pedwarn ("ANSI C forbids member declarations with no members");
1436                   shadow_tag($1);
1437                   $$ = NULL_TREE; }
1438         | error
1439                 { $$ = NULL_TREE; }
1440         | extension component_decl
1441                 { $$ = $2;
1442                   RESTORE_WARN_FLAGS ($1); }
1443         ;
1444
1445 components:
1446           component_declarator
1447         | components ',' component_declarator
1448                 { $$ = chainon ($1, $3); }
1449         ;
1450
1451 component_declarator:
1452           save_filename save_lineno declarator maybe_attribute
1453                 { $$ = grokfield ($1, $2, $3, current_declspecs, NULL_TREE);
1454                   decl_attributes ($$, $4, prefix_attributes); }
1455         | save_filename save_lineno
1456           declarator ':' expr_no_commas maybe_attribute
1457                 { $$ = grokfield ($1, $2, $3, current_declspecs, $5);
1458                   decl_attributes ($$, $6, prefix_attributes); }
1459         | save_filename save_lineno ':' expr_no_commas maybe_attribute
1460                 { $$ = grokfield ($1, $2, NULL_TREE, current_declspecs, $4);
1461                   decl_attributes ($$, $5, prefix_attributes); }
1462         ;
1463
1464 /* We chain the enumerators in reverse order.
1465    They are put in forward order where enumlist is used.
1466    (The order used to be significant, but no longer is so.
1467    However, we still maintain the order, just to be clean.)  */
1468
1469 enumlist:
1470           enumerator
1471         | enumlist ',' enumerator
1472                 { if ($1 == error_mark_node)
1473                     $$ = $1;
1474                   else
1475                     $$ = chainon ($3, $1); }
1476         | error
1477                 { $$ = error_mark_node; }
1478         ;
1479
1480
1481 enumerator:
1482           identifier
1483                 { $$ = build_enumerator ($1, NULL_TREE); }
1484         | identifier '=' expr_no_commas
1485                 { $$ = build_enumerator ($1, $3); }
1486         ;
1487
1488 typename:
1489         typed_typespecs absdcl
1490                 { $$ = build_tree_list ($1, $2); }
1491         | nonempty_type_quals absdcl
1492                 { $$ = build_tree_list ($1, $2); }
1493         ;
1494
1495 absdcl:   /* an absolute declarator */
1496         /* empty */
1497                 { $$ = NULL_TREE; }
1498         | absdcl1
1499         ;
1500
1501 nonempty_type_quals:
1502           TYPE_QUAL
1503                 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1504         | nonempty_type_quals TYPE_QUAL
1505                 { $$ = tree_cons (NULL_TREE, $2, $1); }
1506         ;
1507
1508 type_quals:
1509           /* empty */
1510                 { $$ = NULL_TREE; }
1511         | type_quals TYPE_QUAL
1512                 { $$ = tree_cons (NULL_TREE, $2, $1); }
1513         ;
1514
1515 absdcl1:  /* a nonempty absolute declarator */
1516           '(' absdcl1 ')'
1517                 { $$ = $2; }
1518           /* `(typedef)1' is `int'.  */
1519         | '*' type_quals absdcl1  %prec UNARY
1520                 { $$ = make_pointer_declarator ($2, $3); }
1521         | '*' type_quals  %prec UNARY
1522                 { $$ = make_pointer_declarator ($2, NULL_TREE); }
1523         | absdcl1 '(' parmlist  %prec '.'
1524                 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1525         | absdcl1 '[' expr ']'  %prec '.'
1526                 { $$ = build_nt (ARRAY_REF, $1, $3); }
1527         | absdcl1 '[' ']'  %prec '.'
1528                 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1529         | '(' parmlist  %prec '.'
1530                 { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
1531         | '[' expr ']'  %prec '.'
1532                 { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); }
1533         | '[' ']'  %prec '.'
1534                 { $$ = build_nt (ARRAY_REF, NULL_TREE, NULL_TREE); }
1535         /* ??? It appears we have to support attributes here, however
1536            using prefix_attributes is wrong.  */
1537         | attributes setattrs absdcl1
1538                 { $$ = $3; }
1539         ;
1540
1541 /* at least one statement, the first of which parses without error.  */
1542 /* stmts is used only after decls, so an invalid first statement
1543    is actually regarded as an invalid decl and part of the decls.  */
1544
1545 stmts:
1546         lineno_stmt_or_labels
1547                 {
1548                   if (pedantic && $1)
1549                     pedwarn ("ANSI C forbids label at end of compound statement");
1550                 }
1551         ;
1552
1553 lineno_stmt_or_labels:
1554           lineno_stmt_or_label
1555         | lineno_stmt_or_labels lineno_stmt_or_label
1556                 { $$ = $2; }
1557         | lineno_stmt_or_labels errstmt
1558                 { $$ = 0; }
1559         ;
1560
1561 xstmts:
1562         /* empty */
1563         | stmts
1564         ;
1565
1566 errstmt:  error ';'
1567         ;
1568
1569 pushlevel:  /* empty */
1570                 { emit_line_note (input_filename, lineno);
1571                   pushlevel (0);
1572                   clear_last_expr ();
1573                   push_momentary ();
1574                   expand_start_bindings (0);
1575                 }
1576         ;
1577
1578 /* Read zero or more forward-declarations for labels
1579    that nested functions can jump to.  */
1580 maybe_label_decls:
1581           /* empty */
1582         | label_decls
1583                 { if (pedantic)
1584                     pedwarn ("ANSI C forbids label declarations"); }
1585         ;
1586
1587 label_decls:
1588           label_decl
1589         | label_decls label_decl
1590         ;
1591
1592 label_decl:
1593           LABEL identifiers_or_typenames ';'
1594                 { tree link;
1595                   for (link = $2; link; link = TREE_CHAIN (link))
1596                     {
1597                       tree label = shadow_label (TREE_VALUE (link));
1598                       C_DECLARED_LABEL_FLAG (label) = 1;
1599                       declare_nonlocal_label (label);
1600                     }
1601                 }
1602         ;
1603
1604 /* This is the body of a function definition.
1605    It causes syntax errors to ignore to the next openbrace.  */
1606 compstmt_or_error:
1607           compstmt
1608                 {}
1609         | error compstmt
1610         ;
1611
1612 compstmt_start: '{' { compstmt_count++; }
1613
1614 compstmt_nostart: '}'
1615                 { $$ = convert (void_type_node, integer_zero_node); }
1616         | pushlevel maybe_label_decls decls xstmts '}'
1617                 { emit_line_note (input_filename, lineno);
1618                   expand_end_bindings (getdecls (), 1, 0);
1619                   $$ = poplevel (1, 1, 0);
1620                   if (yychar == CONSTANT || yychar == STRING)
1621                     pop_momentary_nofree ();
1622                   else
1623                     pop_momentary (); }
1624         | pushlevel maybe_label_decls error '}'
1625                 { emit_line_note (input_filename, lineno);
1626                   expand_end_bindings (getdecls (), kept_level_p (), 0);
1627                   $$ = poplevel (kept_level_p (), 0, 0);
1628                   if (yychar == CONSTANT || yychar == STRING)
1629                     pop_momentary_nofree ();
1630                   else
1631                     pop_momentary (); }
1632         | pushlevel maybe_label_decls stmts '}'
1633                 { emit_line_note (input_filename, lineno);
1634                   expand_end_bindings (getdecls (), kept_level_p (), 0);
1635                   $$ = poplevel (kept_level_p (), 0, 0);
1636                   if (yychar == CONSTANT || yychar == STRING)
1637                     pop_momentary_nofree ();
1638                   else
1639                     pop_momentary (); }
1640         ;
1641
1642 compstmt_primary_start:
1643         '(' '{'
1644                 { if (current_function_decl == 0)
1645                     {
1646                       error ("braced-group within expression allowed only inside a function");
1647                       YYERROR;
1648                     }
1649                   /* We must force a BLOCK for this level
1650                      so that, if it is not expanded later,
1651                      there is a way to turn off the entire subtree of blocks
1652                      that are contained in it.  */
1653                   keep_next_level ();
1654                   push_iterator_stack ();
1655                   push_label_level ();
1656                   $$ = expand_start_stmt_expr ();
1657                   compstmt_count++;
1658                 }
1659
1660 compstmt: compstmt_start compstmt_nostart
1661                 { $$ = $2; }
1662         ;
1663
1664 /* Value is number of statements counted as of the closeparen.  */
1665 simple_if:
1666           if_prefix lineno_labeled_stmt
1667 /* Make sure c_expand_end_cond is run once
1668    for each call to c_expand_start_cond.
1669    Otherwise a crash is likely.  */
1670         | if_prefix error
1671         ;
1672
1673 if_prefix:
1674           IF '(' expr ')'
1675                 { emit_line_note ($<filename>-1, $<lineno>0);
1676                   c_expand_start_cond (truthvalue_conversion ($3), 0, 
1677                                        compstmt_count);
1678                   $<itype>$ = stmt_count;
1679                   if_stmt_file = $<filename>-1;
1680                   if_stmt_line = $<lineno>0;
1681                   position_after_white_space (); }
1682         ;
1683
1684 /* This is a subroutine of stmt.
1685    It is used twice, once for valid DO statements
1686    and once for catching errors in parsing the end test.  */
1687 do_stmt_start:
1688           DO
1689                 { stmt_count++;
1690                   compstmt_count++;
1691                   emit_line_note ($<filename>-1, $<lineno>0);
1692                   /* See comment in `while' alternative, above.  */
1693                   emit_nop ();
1694                   expand_start_loop_continue_elsewhere (1);
1695                   position_after_white_space (); }
1696           lineno_labeled_stmt WHILE
1697                 { expand_loop_continue_here (); }
1698         ;
1699
1700 save_filename:
1701                 { $$ = input_filename; }
1702         ;
1703
1704 save_lineno:
1705                 { $$ = lineno; }
1706         ;
1707
1708 lineno_labeled_stmt:
1709           save_filename save_lineno stmt
1710                 { }
1711 /*      | save_filename save_lineno error
1712                 { }
1713 */
1714         | save_filename save_lineno label lineno_labeled_stmt
1715                 { }
1716         ;
1717
1718 lineno_stmt_or_label:
1719           save_filename save_lineno stmt_or_label
1720                 { $$ = $3; }
1721         ;
1722
1723 stmt_or_label:
1724           stmt
1725                 { $$ = 0; }
1726         | label
1727                 { $$ = 1; }
1728         ;
1729
1730 /* Parse a single real statement, not including any labels.  */
1731 stmt:
1732           compstmt
1733                 { stmt_count++; }
1734         | all_iter_stmt 
1735         | expr ';'
1736                 { stmt_count++;
1737                   emit_line_note ($<filename>-1, $<lineno>0);
1738 /* It appears that this should not be done--that a non-lvalue array
1739    shouldn't get an error if the value isn't used.
1740    Section 3.2.2.1 says that an array lvalue gets converted to a pointer
1741    if it appears as a top-level expression,
1742    but says nothing about non-lvalue arrays.  */
1743 #if 0
1744                   /* Call default_conversion to get an error
1745                      on referring to a register array if pedantic.  */
1746                   if (TREE_CODE (TREE_TYPE ($1)) == ARRAY_TYPE
1747                       || TREE_CODE (TREE_TYPE ($1)) == FUNCTION_TYPE)
1748                     $1 = default_conversion ($1);
1749 #endif
1750                   iterator_expand ($1);
1751                   clear_momentary (); }
1752         | simple_if ELSE
1753                 { c_expand_start_else ();
1754                   $<itype>1 = stmt_count;
1755                   position_after_white_space (); }
1756           lineno_labeled_stmt
1757                 { c_expand_end_cond ();
1758                   if (extra_warnings && stmt_count == $<itype>1)
1759                     warning ("empty body in an else-statement"); }
1760         | simple_if %prec IF
1761                 { c_expand_end_cond ();
1762                   /* This warning is here instead of in simple_if, because we
1763                      do not want a warning if an empty if is followed by an
1764                      else statement.  Increment stmt_count so we don't
1765                      give a second error if this is a nested `if'.  */
1766                   if (extra_warnings && stmt_count++ == $<itype>1)
1767                     warning_with_file_and_line (if_stmt_file, if_stmt_line,
1768                                                 "empty body in an if-statement"); }
1769 /* Make sure c_expand_end_cond is run once
1770    for each call to c_expand_start_cond.
1771    Otherwise a crash is likely.  */
1772         | simple_if ELSE error
1773                 { c_expand_end_cond (); }
1774         | WHILE
1775                 { stmt_count++;
1776                   emit_line_note ($<filename>-1, $<lineno>0);
1777                   /* The emit_nop used to come before emit_line_note,
1778                      but that made the nop seem like part of the preceding line.
1779                      And that was confusing when the preceding line was
1780                      inside of an if statement and was not really executed.
1781                      I think it ought to work to put the nop after the line number.
1782                      We will see.  --rms, July 15, 1991.  */
1783                   emit_nop (); }
1784           '(' expr ')'
1785                 { /* Don't start the loop till we have succeeded
1786                      in parsing the end test.  This is to make sure
1787                      that we end every loop we start.  */
1788                   expand_start_loop (1);
1789                   emit_line_note (input_filename, lineno);
1790                   expand_exit_loop_if_false (NULL_PTR,
1791                                              truthvalue_conversion ($4));
1792                   position_after_white_space (); }
1793           lineno_labeled_stmt
1794                 { expand_end_loop (); }
1795         | do_stmt_start
1796           '(' expr ')' ';'
1797                 { emit_line_note (input_filename, lineno);
1798                   expand_exit_loop_if_false (NULL_PTR,
1799                                              truthvalue_conversion ($3));
1800                   expand_end_loop ();
1801                   clear_momentary (); }
1802 /* This rule is needed to make sure we end every loop we start.  */
1803         | do_stmt_start error
1804                 { expand_end_loop ();
1805                   clear_momentary (); }
1806         | FOR
1807           '(' xexpr ';'
1808                 { stmt_count++;
1809                   emit_line_note ($<filename>-1, $<lineno>0);
1810                   /* See comment in `while' alternative, above.  */
1811                   emit_nop ();
1812                   if ($3) c_expand_expr_stmt ($3);
1813                   /* Next step is to call expand_start_loop_continue_elsewhere,
1814                      but wait till after we parse the entire for (...).
1815                      Otherwise, invalid input might cause us to call that
1816                      fn without calling expand_end_loop.  */
1817                 }
1818           xexpr ';'
1819                 /* Can't emit now; wait till after expand_start_loop...  */
1820                 { $<lineno>7 = lineno;
1821                   $<filename>$ = input_filename; }
1822           xexpr ')'
1823                 { 
1824                   /* Start the loop.  Doing this after parsing
1825                      all the expressions ensures we will end the loop.  */
1826                   expand_start_loop_continue_elsewhere (1);
1827                   /* Emit the end-test, with a line number.  */
1828                   emit_line_note ($<filename>8, $<lineno>7);
1829                   if ($6)
1830                     expand_exit_loop_if_false (NULL_PTR,
1831                                                truthvalue_conversion ($6));
1832                   /* Don't let the tree nodes for $9 be discarded by
1833                      clear_momentary during the parsing of the next stmt.  */
1834                   push_momentary ();
1835                   $<lineno>7 = lineno;
1836                   $<filename>8 = input_filename;
1837                   position_after_white_space (); }
1838           lineno_labeled_stmt
1839                 { /* Emit the increment expression, with a line number.  */
1840                   emit_line_note ($<filename>8, $<lineno>7);
1841                   expand_loop_continue_here ();
1842                   if ($9)
1843                     c_expand_expr_stmt ($9);
1844                   if (yychar == CONSTANT || yychar == STRING)
1845                     pop_momentary_nofree ();
1846                   else
1847                     pop_momentary ();
1848                   expand_end_loop (); }
1849         | SWITCH '(' expr ')'
1850                 { stmt_count++;
1851                   emit_line_note ($<filename>-1, $<lineno>0);
1852                   c_expand_start_case ($3);
1853                   /* Don't let the tree nodes for $3 be discarded by
1854                      clear_momentary during the parsing of the next stmt.  */
1855                   push_momentary ();
1856                   position_after_white_space (); }
1857           lineno_labeled_stmt
1858                 { expand_end_case ($3);
1859                   if (yychar == CONSTANT || yychar == STRING)
1860                     pop_momentary_nofree ();
1861                   else
1862                     pop_momentary (); }
1863         | BREAK ';'
1864                 { stmt_count++;
1865                   emit_line_note ($<filename>-1, $<lineno>0);
1866                   if ( ! expand_exit_something ())
1867                     error ("break statement not within loop or switch"); }
1868         | CONTINUE ';'
1869                 { stmt_count++;
1870                   emit_line_note ($<filename>-1, $<lineno>0);
1871                   if (! expand_continue_loop (NULL_PTR))
1872                     error ("continue statement not within a loop"); }
1873         | RETURN ';'
1874                 { stmt_count++;
1875                   emit_line_note ($<filename>-1, $<lineno>0);
1876                   c_expand_return (NULL_TREE); }
1877         | RETURN expr ';'
1878                 { stmt_count++;
1879                   emit_line_note ($<filename>-1, $<lineno>0);
1880                   c_expand_return ($2); }
1881         | ASM_KEYWORD maybe_type_qual '(' expr ')' ';'
1882                 { stmt_count++;
1883                   emit_line_note ($<filename>-1, $<lineno>0);
1884                   STRIP_NOPS ($4);
1885                   if ((TREE_CODE ($4) == ADDR_EXPR
1886                        && TREE_CODE (TREE_OPERAND ($4, 0)) == STRING_CST)
1887                       || TREE_CODE ($4) == STRING_CST)
1888                     expand_asm ($4);
1889                   else
1890                     error ("argument of `asm' is not a constant string"); }
1891         /* This is the case with just output operands.  */
1892         | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';'
1893                 { stmt_count++;
1894                   emit_line_note ($<filename>-1, $<lineno>0);
1895                   c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
1896                                          $2 == ridpointers[(int)RID_VOLATILE],
1897                                          input_filename, lineno); }
1898         /* This is the case with input operands as well.  */
1899         | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':' asm_operands ')' ';'
1900                 { stmt_count++;
1901                   emit_line_note ($<filename>-1, $<lineno>0);
1902                   c_expand_asm_operands ($4, $6, $8, NULL_TREE,
1903                                          $2 == ridpointers[(int)RID_VOLATILE],
1904                                          input_filename, lineno); }
1905         /* This is the case with clobbered registers as well.  */
1906         | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
1907           asm_operands ':' asm_clobbers ')' ';'
1908                 { stmt_count++;
1909                   emit_line_note ($<filename>-1, $<lineno>0);
1910                   c_expand_asm_operands ($4, $6, $8, $10,
1911                                          $2 == ridpointers[(int)RID_VOLATILE],
1912                                          input_filename, lineno); }
1913         | GOTO identifier ';'
1914                 { tree decl;
1915                   stmt_count++;
1916                   emit_line_note ($<filename>-1, $<lineno>0);
1917                   decl = lookup_label ($2);
1918                   if (decl != 0)
1919                     {
1920                       TREE_USED (decl) = 1;
1921                       expand_goto (decl);
1922                     }
1923                 }
1924         | GOTO '*' expr ';'
1925                 { if (pedantic)
1926                     pedwarn ("ANSI C forbids `goto *expr;'");
1927                   stmt_count++;
1928                   emit_line_note ($<filename>-1, $<lineno>0);
1929                   expand_computed_goto (convert (ptr_type_node, $3)); }
1930         | ';'
1931         ;
1932
1933 all_iter_stmt:
1934           all_iter_stmt_simple
1935 /*      | all_iter_stmt_with_decl */
1936         ;
1937
1938 all_iter_stmt_simple:
1939           FOR '(' primary ')' 
1940           {
1941             /* The value returned by this action is  */
1942             /*      1 if everything is OK */ 
1943             /*      0 in case of error or already bound iterator */
1944
1945             $<itype>$ = 0;
1946             if (TREE_CODE ($3) != VAR_DECL)
1947               error ("invalid `for (ITERATOR)' syntax");
1948             else if (! ITERATOR_P ($3))
1949               error ("`%s' is not an iterator",
1950                      IDENTIFIER_POINTER (DECL_NAME ($3)));
1951             else if (ITERATOR_BOUND_P ($3))
1952               error ("`for (%s)' inside expansion of same iterator",
1953                      IDENTIFIER_POINTER (DECL_NAME ($3)));
1954             else
1955               {
1956                 $<itype>$ = 1;
1957                 iterator_for_loop_start ($3);
1958               }
1959           }
1960           lineno_labeled_stmt
1961           {
1962             if ($<itype>5)
1963               iterator_for_loop_end ($3);
1964           }
1965
1966 /*  This really should allow any kind of declaration,
1967     for generality.  Fix it before turning it back on.
1968
1969 all_iter_stmt_with_decl:
1970           FOR '(' ITERATOR pushlevel setspecs iterator_spec ')' 
1971           {
1972 */          /* The value returned by this action is  */
1973             /*      1 if everything is OK */ 
1974             /*      0 in case of error or already bound iterator */
1975 /*
1976             iterator_for_loop_start ($6);
1977           }
1978           lineno_labeled_stmt
1979           {
1980             iterator_for_loop_end ($6);
1981             emit_line_note (input_filename, lineno);
1982             expand_end_bindings (getdecls (), 1, 0);
1983             $<ttype>$ = poplevel (1, 1, 0);
1984             if (yychar == CONSTANT || yychar == STRING)
1985               pop_momentary_nofree ();
1986             else
1987               pop_momentary ();     
1988           }
1989 */
1990
1991 /* Any kind of label, including jump labels and case labels.
1992    ANSI C accepts labels only before statements, but we allow them
1993    also at the end of a compound statement.  */
1994
1995 label:    CASE expr_no_commas ':'
1996                 { register tree value = check_case_value ($2);
1997                   register tree label
1998                     = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
1999
2000                   stmt_count++;
2001
2002                   if (value != error_mark_node)
2003                     {
2004                       tree duplicate;
2005                       int success;
2006
2007                       if (pedantic && ! INTEGRAL_TYPE_P (TREE_TYPE (value)))
2008                         pedwarn ("label must have integral type in ANSI C");
2009
2010                       success = pushcase (value, convert_and_check,
2011                                           label, &duplicate);
2012
2013                       if (success == 1)
2014                         error ("case label not within a switch statement");
2015                       else if (success == 2)
2016                         {
2017                           error ("duplicate case value");
2018                           error_with_decl (duplicate, "this is the first entry for that value");
2019                         }
2020                       else if (success == 3)
2021                         warning ("case value out of range");
2022                       else if (success == 5)
2023                         error ("case label within scope of cleanup or variable array");
2024                     }
2025                   position_after_white_space (); }
2026         | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
2027                 { register tree value1 = check_case_value ($2);
2028                   register tree value2 = check_case_value ($4);
2029                   register tree label
2030                     = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2031
2032                   if (pedantic)
2033                     pedwarn ("ANSI C forbids case ranges");
2034                   stmt_count++;
2035
2036                   if (value1 != error_mark_node && value2 != error_mark_node)
2037                     {
2038                       tree duplicate;
2039                       int success = pushcase_range (value1, value2,
2040                                                     convert_and_check, label,
2041                                                     &duplicate);
2042                       if (success == 1)
2043                         error ("case label not within a switch statement");
2044                       else if (success == 2)
2045                         {
2046                           error ("duplicate case value");
2047                           error_with_decl (duplicate, "this is the first entry for that value");
2048                         }
2049                       else if (success == 3)
2050                         warning ("case value out of range");
2051                       else if (success == 4)
2052                         warning ("empty case range");
2053                       else if (success == 5)
2054                         error ("case label within scope of cleanup or variable array");
2055                     }
2056                   position_after_white_space (); }
2057         | DEFAULT ':'
2058                 {
2059                   tree duplicate;
2060                   register tree label
2061                     = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2062                   int success = pushcase (NULL_TREE, 0, label, &duplicate);
2063                   stmt_count++;
2064                   if (success == 1)
2065                     error ("default label not within a switch statement");
2066                   else if (success == 2)
2067                     {
2068                       error ("multiple default labels in one switch");
2069                       error_with_decl (duplicate, "this is the first default label");
2070                     }
2071                   position_after_white_space (); }
2072         | identifier ':' maybe_attribute
2073                 { tree label = define_label (input_filename, lineno, $1);
2074                   stmt_count++;
2075                   emit_nop ();
2076                   if (label)
2077                     {
2078                       expand_label (label);
2079                       decl_attributes (label, $3, NULL_TREE);
2080                     }
2081                   position_after_white_space (); }
2082         ;
2083
2084 /* Either a type-qualifier or nothing.  First thing in an `asm' statement.  */
2085
2086 maybe_type_qual:
2087         /* empty */
2088                 { emit_line_note (input_filename, lineno);
2089                   $$ = NULL_TREE; }
2090         | TYPE_QUAL
2091                 { emit_line_note (input_filename, lineno); }
2092         ;
2093
2094 xexpr:
2095         /* empty */
2096                 { $$ = NULL_TREE; }
2097         | expr
2098         ;
2099
2100 /* These are the operands other than the first string and colon
2101    in  asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x))  */
2102 asm_operands: /* empty */
2103                 { $$ = NULL_TREE; }
2104         | nonnull_asm_operands
2105         ;
2106
2107 nonnull_asm_operands:
2108           asm_operand
2109         | nonnull_asm_operands ',' asm_operand
2110                 { $$ = chainon ($1, $3); }
2111         ;
2112
2113 asm_operand:
2114           STRING '(' expr ')'
2115                 { $$ = build_tree_list ($1, $3); }
2116         ;
2117
2118 asm_clobbers:
2119           string
2120                 { $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE); }
2121         | asm_clobbers ',' string
2122                 { $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); }
2123         ;
2124 \f
2125 /* This is what appears inside the parens in a function declarator.
2126    Its value is a list of ..._TYPE nodes.  */
2127 parmlist:
2128                 { pushlevel (0);
2129                   clear_parm_order ();
2130                   declare_parm_level (0); }
2131           parmlist_1
2132                 { $$ = $2;
2133                   parmlist_tags_warning ();
2134                   poplevel (0, 0, 0); }
2135         ;
2136
2137 parmlist_1:
2138           parmlist_2 ')'
2139         | parms ';'
2140                 { tree parm;
2141                   if (pedantic)
2142                     pedwarn ("ANSI C forbids forward parameter declarations");
2143                   /* Mark the forward decls as such.  */
2144                   for (parm = getdecls (); parm; parm = TREE_CHAIN (parm))
2145                     TREE_ASM_WRITTEN (parm) = 1;
2146                   clear_parm_order (); }
2147           parmlist_1
2148                 { $$ = $4; }
2149         | error ')'
2150                 { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
2151         ;
2152
2153 /* This is what appears inside the parens in a function declarator.
2154    Is value is represented in the format that grokdeclarator expects.  */
2155 parmlist_2:  /* empty */
2156                 { $$ = get_parm_info (0); }
2157         | ELLIPSIS
2158                 { $$ = get_parm_info (0);
2159                   /* Gcc used to allow this as an extension.  However, it does
2160                      not work for all targets, and thus has been disabled.
2161                      Also, since func (...) and func () are indistinguishable,
2162                      it caused problems with the code in expand_builtin which
2163                      tries to verify that BUILT_IN_NEXT_ARG is being used
2164                      correctly.  */
2165                   error ("ANSI C requires a named argument before `...'");
2166                 }
2167         | parms
2168                 { $$ = get_parm_info (1); }
2169         | parms ',' ELLIPSIS
2170                 { $$ = get_parm_info (0); }
2171         ;
2172
2173 parms:
2174         parm
2175                 { push_parm_decl ($1); }
2176         | parms ',' parm
2177                 { push_parm_decl ($3); }
2178         ;
2179
2180 /* A single parameter declaration or parameter type name,
2181    as found in a parmlist.  */
2182 parm:
2183           typed_declspecs setspecs parm_declarator maybe_attribute
2184                 { $$ = build_tree_list (build_tree_list (current_declspecs,
2185                                                          $3),
2186                                         build_tree_list (prefix_attributes,
2187                                                          $4));
2188                   current_declspecs = TREE_VALUE (declspec_stack);
2189                   prefix_attributes = TREE_PURPOSE (declspec_stack);
2190                   declspec_stack = TREE_CHAIN (declspec_stack);
2191                   resume_momentary ($2); }
2192         | typed_declspecs setspecs notype_declarator maybe_attribute
2193                 { $$ = build_tree_list (build_tree_list (current_declspecs,
2194                                                          $3),
2195                                         build_tree_list (prefix_attributes,
2196                                                          $4)); 
2197                   current_declspecs = TREE_VALUE (declspec_stack);
2198                   prefix_attributes = TREE_PURPOSE (declspec_stack);
2199                   declspec_stack = TREE_CHAIN (declspec_stack);
2200                   resume_momentary ($2); }
2201         | typed_declspecs setspecs absdcl maybe_attribute
2202                 { $$ = build_tree_list (build_tree_list (current_declspecs,
2203                                                          $3),
2204                                         build_tree_list (prefix_attributes,
2205                                                          $4));
2206                   current_declspecs = TREE_VALUE (declspec_stack);
2207                   prefix_attributes = TREE_PURPOSE (declspec_stack);
2208                   declspec_stack = TREE_CHAIN (declspec_stack);
2209                   resume_momentary ($2); }
2210         | declmods setspecs notype_declarator maybe_attribute
2211                 { $$ = build_tree_list (build_tree_list (current_declspecs,
2212                                                          $3),
2213                                         build_tree_list (prefix_attributes,
2214                                                          $4));
2215                   current_declspecs = TREE_VALUE (declspec_stack);
2216                   prefix_attributes = TREE_PURPOSE (declspec_stack);
2217                   declspec_stack = TREE_CHAIN (declspec_stack);
2218                   resume_momentary ($2);  }
2219
2220         | declmods setspecs absdcl maybe_attribute
2221                 { $$ = build_tree_list (build_tree_list (current_declspecs,
2222                                                          $3),
2223                                         build_tree_list (prefix_attributes,
2224                                                          $4));
2225                   current_declspecs = TREE_VALUE (declspec_stack);
2226                   prefix_attributes = TREE_PURPOSE (declspec_stack);
2227                   declspec_stack = TREE_CHAIN (declspec_stack);
2228                   resume_momentary ($2);  }
2229         ;
2230
2231 /* This is used in a function definition
2232    where either a parmlist or an identifier list is ok.
2233    Its value is a list of ..._TYPE nodes or a list of identifiers.  */
2234 parmlist_or_identifiers:
2235                 { pushlevel (0);
2236                   clear_parm_order ();
2237                   declare_parm_level (1); }
2238           parmlist_or_identifiers_1
2239                 { $$ = $2;
2240                   parmlist_tags_warning ();
2241                   poplevel (0, 0, 0); }
2242         ;
2243
2244 parmlist_or_identifiers_1:
2245           parmlist_1
2246         | identifiers ')'
2247                 { tree t;
2248                   for (t = $1; t; t = TREE_CHAIN (t))
2249                     if (TREE_VALUE (t) == NULL_TREE)
2250                       error ("`...' in old-style identifier list");
2251                   $$ = tree_cons (NULL_TREE, NULL_TREE, $1); }
2252         ;
2253
2254 /* A nonempty list of identifiers.  */
2255 identifiers:
2256         IDENTIFIER
2257                 { $$ = build_tree_list (NULL_TREE, $1); }
2258         | identifiers ',' IDENTIFIER
2259                 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2260         ;
2261
2262 /* A nonempty list of identifiers, including typenames.  */
2263 identifiers_or_typenames:
2264         identifier
2265                 { $$ = build_tree_list (NULL_TREE, $1); }
2266         | identifiers_or_typenames ',' identifier
2267                 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2268         ;
2269
2270 extension:
2271         EXTENSION
2272                 { $$ = SAVE_WARN_FLAGS();
2273                   pedantic = 0;
2274                   warn_pointer_arith = 0; }
2275         ;
2276 \f
2277 %%