PageRenderTime 114ms CodeModel.GetById 67ms app.highlight 25ms RepoModel.GetById 2ms app.codeStats 0ms

/cyclone/banshee/cparser/c-parse.y

https://bitbucket.org/mirrorbot/cyclone-full
Happy | 1739 lines | 1559 code | 180 blank | 0 comment | 0 complexity | 10a9145da0712168e405db87832b82e2 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1/* This file was modified in 2000-2001 by David Gay for the RC compiler.
   2   The changes are 
   3   Copyright (c) 2000-2001 The Regents of the University of California.
   4
   5   This file is distributed under the terms of the GNU General Public License
   6   (see below).
   7*/
   8
   9/* YACC parser for C syntax and for Objective C.  -*-c-*-
  10   Copyright (C) 1987, 88, 89, 92-97, 1998 Free Software Foundation, Inc.
  11
  12This file is part of GNU CC.
  13
  14GNU CC is free software; you can redistribute it and/or modify
  15it under the terms of the GNU General Public License as published by
  16the Free Software Foundation; either version 2, or (at your option)
  17any later version.
  18
  19GNU CC is distributed in the hope that it will be useful,
  20but WITHOUT ANY WARRANTY; without even the implied warranty of
  21MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22GNU General Public License for more details.
  23
  24You should have received a copy of the GNU General Public License
  25along with GNU CC; see the file COPYING.  If not, write to
  26the Free Software Foundation, 59 Temple Place - Suite 330,
  27Boston, MA 02111-1307, USA.  */
  28
  29/* This file defines the grammar of C */
  30/* To whomever it may concern: I have heard that such a thing was once
  31   written by AT&T, but I have never seen it.  */
  32
  33%expect 46
  34
  35/* These are the 23 conflicts you should get in parse.output;
  36   the state numbers may vary if minor changes in the grammar are made.
  37
  38State 42 contains 1 shift/reduce conflict.  (Two ways to parse ATTRIBUTE.)
  39State 44 contains 1 shift/reduce conflict.  (Two ways to recover from error.)
  40State 103 contains 1 shift/reduce conflict.  (Two ways to recover from error.)
  41State 110 contains 1 shift/reduce conflict.  (Two ways to parse ATTRIBUTE.)
  42State 111 contains 1 shift/reduce conflict.  (Two ways to recover from error.)
  43State 115 contains 1 shift/reduce conflict.  (Two ways to recover from error.)
  44State 132 contains 1 shift/reduce conflict.  (See comment at component_decl.)
  45State 180 contains 1 shift/reduce conflict.  (Two ways to parse ATTRIBUTE.)
  46State 194 contains 2 shift/reduce conflict.  (Four ways to parse this.)
  47State 202 contains 1 shift/reduce conflict.  (Two ways to recover from error.)
  48State 214 contains 1 shift/reduce conflict.  (Two ways to recover from error.)
  49State 220 contains 1 shift/reduce conflict.  (Two ways to recover from error.)
  50State 304 contains 2 shift/reduce conflicts.  (Four ways to parse this.)
  51State 335 contains 2 shift/reduce conflicts.  (Four ways to parse this.)
  52State 347 contains 1 shift/reduce conflict.  (Two ways to parse ATTRIBUTES.)
  53State 352 contains 1 shift/reduce conflict.  (Two ways to parse ATTRIBUTES.)
  54State 383 contains 2 shift/reduce conflicts.  (Four ways to parse this.)
  55State 434 contains 2 shift/reduce conflicts.  (Four ways to parse this.)  */
  56
  57
  58%{
  59#include <stdio.h>
  60#include <errno.h>
  61#include <setjmp.h>
  62
  63#include "parser.h"
  64#include "c-parse.h"
  65#include "c-lex.h"
  66#include "semantics.h"
  67#include "input.h"
  68#include "expr.h"
  69#include "stmt.h"
  70
  71int yyparse(void) deletes;
  72
  73void yyerror();
  74
  75/* Like YYERROR but do call yyerror.  */
  76#define YYERROR1 { yyerror ("syntax error"); YYERROR; }
  77
  78/* Cause the `yydebug' variable to be defined.  */
  79#define YYDEBUG 1
  80%}
  81
  82%start program
  83
  84/* All identifiers that are not reserved words
  85   and are not declared typedefs in the current block */
  86%token IDENTIFIER
  87
  88/* All identifiers that are declared typedefs in the current block.
  89   In some contexts, they are treated just like IDENTIFIER,
  90   but they can also serve as typespecs in declarations.  */
  91%token TYPENAME
  92
  93/* Reserved words that specify storage class.
  94   yylval contains an IDENTIFIER_NODE which indicates which one.  */
  95%token <u.itoken> SCSPEC
  96
  97/* Reserved words that specify type.
  98   yylval contains an IDENTIFIER_NODE which indicates which one.  */
  99%token <u.itoken> TYPESPEC
 100
 101/* Reserved words that qualify types/functions: "const" or "volatile", 
 102   "deletes".
 103   yylval contains an IDENTIFIER_NODE which indicates which one.  */
 104%token <u.itoken> TYPE_QUAL FN_QUAL
 105
 106/* Character or numeric constants.
 107   yylval is the node for the constant.  */
 108%token CONSTANT
 109
 110/* String constants in raw form.
 111   yylval is a STRING_CST node.  */
 112%token STRING MAGIC_STRING
 113
 114/* "...", used for functions with variable arglists.  */
 115%token <u.itoken> ELLIPSIS
 116
 117/* the reserved words */
 118/* SCO include files test "ASM", so use something else. */
 119%token <u.itoken> SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
 120%token <u.itoken> BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF
 121%token <u.itoken> ATTRIBUTE EXTENSION LABEL
 122%token <u.itoken> REALPART IMAGPART VA_ARG
 123
 124/* Add precedence rules to solve dangling else s/r conflict */
 125%nonassoc IF
 126%nonassoc ELSE
 127
 128/* Define the operator tokens and their precedences.
 129   The value is an integer because, if used, it is the tree code
 130   to use in the expression made from the operator.  */
 131
 132%right <u.itoken> ASSIGN '='
 133%right <u.itoken> '?' ':'
 134%left <u.itoken> OROR
 135%left <u.itoken> ANDAND
 136%left <u.itoken> '|'
 137%left <u.itoken> '^'
 138%left <u.itoken> '&'
 139%left <u.itoken> EQCOMPARE
 140%left <u.itoken> ARITHCOMPARE
 141%left <u.itoken> LSHIFT RSHIFT
 142%left <u.itoken> '+' '-'
 143%left <u.itoken> '*' '/' '%'
 144%right <u.itoken> UNARY PLUSPLUS MINUSMINUS
 145%left HYPERUNARY
 146%left <u.itoken> POINTSAT '.' '(' '['
 147
 148%type <u.asm_operand> asm_operand asm_operands nonnull_asm_operands
 149%type <u.asm_stmt> maybeasm
 150%type <u.attribute> maybe_attribute attributes attribute attribute_list attrib
 151%type <u.constant> CONSTANT
 152%type <u.decl> datadecl datadecls datadef decl decls extdef extdefs fndef
 153%type <u.decl> initdecls nested_function notype_nested_function notype_initdecls
 154%type <u.decl> old_style_parm_decls initdcl
 155%type <u.decl> component_decl_list component_decl_list2 component_decl
 156%type <u.decl> components component_declarator enumerator enumlist
 157%type <u.decl> parmlist parmlist_1 parmlist_2 parms parm
 158%type <u.decl> parmlist_or_identifiers identifiers notype_initdcl
 159%type <u.decl> parmlist_or_identifiers_1 old_parameter
 160%type <u.declarator> declarator after_type_declarator notype_declarator
 161%type <u.declarator> absdcl absdcl1 parm_declarator
 162%type <u.expr> cast_expr expr expr_no_commas exprlist init initlist_maybe_comma initlist1 initelt nonnull_exprlist primary string_component STRING string_list
 163%type <u.expr> unary_expr xexpr
 164%type <u.id_label> id_label maybe_label_decls label_decls label_decl
 165%type <u.id_label> identifiers_or_typenames
 166%type <idtoken> identifier IDENTIFIER TYPENAME MAGIC_STRING
 167%type <u.iexpr> if_prefix
 168%type <u.istmt> stmt_or_labels simple_if stmt_or_label
 169%type <u.itoken> unop extension '~' '!' compstmt_start '{' ';'
 170%type <u.itoken> sizeof alignof
 171%type <u.label> label
 172%type <u.stmt> stmts xstmts compstmt_or_error compstmt
 173%type <u.stmt> labeled_stmt stmt
 174%type <u.cstmt> do_stmt_start
 175%type <u.string> asm_clobbers string
 176%type <u.telement> scspec type_qual type_spec
 177%type <u.telement> declmods declmods_no_prefix_attr 
 178%type <u.telement> reserved_declspecs reserved_declspecs_no_prefix_attr 
 179%type <u.telement> typed_declspecs typed_declspecs_no_prefix_attr
 180%type <u.telement> typed_typespecs reserved_typespecquals 
 181%type <u.telement> typespec typespecqual_reserved structsp
 182%type <u.telement> nonempty_type_quals type_quals
 183%type <u.telement> maybe_type_qual fn_qual fn_quals
 184%type <u.type> typename
 185%type <u.word> idword any_word tag
 186
 187%{
 188/* Region in which to allocate parse structures. Idea: the AST user can set
 189   this to different regions at appropriate junctures depending on what's
 190   being done with the AST */
 191region parse_region;
 192/* We'll see this a LOT below */
 193#define pr parse_region
 194
 195/* Number of statements (loosely speaking) and compound statements 
 196   seen so far.  */
 197static int stmt_count;
 198static int compstmt_count;
 199  
 200/* List of types and structure classes of the current declaration.  */
 201static type_element current_declspecs = NULL;
 202static attribute prefix_attributes = NULL;
 203
 204/* >0 if currently parsing an expression that will not be evaluated (argument
 205   to alignof, sizeof. Currently not typeof though that could be considered
 206   a bug) */
 207int unevaluated_expression;
 208
 209#ifdef RC_ADJUST
 210static size_t rc_adjust_yystype(void *x, int by) 
 211{
 212  struct yystype *p = x;
 213  RC_ADJUST_PREAMBLE;
 214
 215  RC_ADJUST(p->u.ptr, by);
 216  RC_ADJUST(p->idtoken.location.filename, by);
 217  RC_ADJUST(p->idtoken.id.data, by);
 218  RC_ADJUST(p->idtoken.decl, by);
 219
 220  return sizeof *p;
 221}
 222
 223static void rc_update_yystype(struct yystype *old, struct yystype *new)
 224{
 225  regionid base = regionidof(old);
 226
 227  RC_UPDATE(base, old->u.ptr, new->u.ptr);
 228  RC_UPDATE(base, old->idtoken.location.filename, new->idtoken.location.filename);
 229  RC_UPDATE(base, old->idtoken.id.data, new->idtoken.id.data);
 230  RC_UPDATE(base, old->idtoken.decl, new->idtoken.decl);
 231}
 232#endif
 233
 234/* A stack of declspecs and attributes for use during parsing */
 235typedef struct spec_stack *spec_stack;
 236struct spec_stack { 
 237  type_element parentptr declspecs;
 238  attribute parentptr attributes;
 239  spec_stack sameregion next;
 240};
 241
 242/* Stack of saved values of current_declspecs and prefix_attributes.  */
 243/* In an ideal world, we would be able to eliminate most rc ops for
 244   declspec_stack and ds_region assignments. Seems tricky though. */
 245static spec_stack declspec_stack;
 246static region ds_region;
 247
 248/* Pop top entry of declspec_stack back into current_declspecs,
 249   prefix_attributes */
 250static void pop_declspec_stack(void) deletes
 251{
 252  current_declspecs = declspec_stack->declspecs;
 253  prefix_attributes = declspec_stack->attributes;
 254  declspec_stack = declspec_stack->next;
 255  if (!declspec_stack)
 256    deleteregion_ptr(&ds_region);
 257}
 258
 259static void push_declspec_stack(void)
 260{
 261  spec_stack news;
 262
 263  if (!ds_region) ds_region = newsubregion(parse_region);
 264  news = ralloc(ds_region, struct spec_stack);
 265  news->declspecs = current_declspecs;
 266  news->attributes = prefix_attributes;
 267  news->next = declspec_stack;
 268  declspec_stack = news;
 269}
 270
 271/* Tell yyparse how to print a token's value, if yydebug is set.  */
 272
 273#define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
 274void yyprint();
 275%}
 276
 277%%
 278program: /* empty */
 279		{ if (pedantic)
 280		    pedwarn("ANSI C forbids an empty source file");
 281		  the_program = NULL;
 282		}
 283	| extdefs
 284		{
 285		  the_program = $1;
 286		}
 287	;
 288
 289/* the reason for the strange actions in this rule
 290 is so that notype_initdecls when reached via datadef
 291 can find a valid list of type and sc specs in $0. */
 292
 293extdefs:
 294	{ $<u.telement>$ = NULL; } extdef { $$ = $2; }
 295	| extdefs { $<u.telement>$ = NULL; } extdef
 296		{ $$ = declaration_chain($1, $3); }	  
 297	;
 298
 299extdef:
 300	fndef
 301	| datadef
 302	| ASM_KEYWORD '(' expr ')' ';'
 303		{ 
 304		  $$ = CAST(declaration, new_asm_decl
 305		    (pr, $1.location,
 306		     new_asm_stmt(pr, $1.location, $3, NULL, NULL, NULL, NULL))); }
 307	| extension extdef
 308		{ pedantic = $1.i; 
 309		  $$ = CAST(declaration, new_extension_decl(pr, $1.location, $2)); }
 310	;
 311
 312datadef:
 313	  setspecs notype_initdecls ';'
 314		{ if (pedantic)
 315		    error("ANSI C forbids data definition with no type or storage class");
 316		  else if (!flag_traditional)
 317		    warning("data definition has no type or storage class"); 
 318
 319		  $$ = CAST(declaration, new_data_decl(pr, $2->location, NULL, NULL, $2));
 320		  pop_declspec_stack(); }
 321        | declmods setspecs notype_initdecls ';'
 322		{ $$ = CAST(declaration, new_data_decl(pr, $1->location, current_declspecs, prefix_attributes, $3));
 323		  pop_declspec_stack(); }
 324	| typed_declspecs setspecs initdecls ';'
 325		{ $$ = CAST(declaration, new_data_decl(pr, $1->location, current_declspecs, prefix_attributes, $3));
 326		  pop_declspec_stack(); }
 327        | declmods ';'
 328	  { pedwarn("empty declaration"); }
 329	| typed_declspecs setspecs ';'
 330	  { shadow_tag($1); 
 331	    $$ = CAST(declaration, new_data_decl(pr, $1->location, current_declspecs, prefix_attributes, NULL));
 332	    pop_declspec_stack(); }
 333	| error ';' { $$ = new_error_decl(pr, last_location); }
 334	| error '}' { $$ = new_error_decl(pr, last_location); }
 335	| ';'
 336		{ if (pedantic)
 337		    pedwarn("ANSI C does not allow extra `;' outside of a function");
 338		  $$ = NULL; }
 339	;
 340
 341fndef:
 342	  typed_declspecs setspecs declarator
 343		{ if (!start_function(current_declspecs, $3,
 344				      prefix_attributes, 0))
 345		    YYERROR1; }
 346	  old_style_parm_decls
 347		{ store_parm_decls($5); }
 348	  compstmt_or_error
 349		{ $$ = finish_function($7);
 350		  pop_declspec_stack(); }
 351	| typed_declspecs setspecs declarator error
 352		{ $$ = new_error_decl(pr, last_location);
 353		  pop_declspec_stack(); }
 354	| declmods setspecs notype_declarator
 355		{ if (!start_function(current_declspecs, $3,
 356				      prefix_attributes, 0))
 357		    YYERROR1; }
 358	  old_style_parm_decls
 359		{ store_parm_decls($5); }
 360	  compstmt_or_error
 361		{ $$ = finish_function($7); 
 362		  pop_declspec_stack(); }
 363	| declmods setspecs notype_declarator error
 364		{ $$ = new_error_decl(pr, last_location);
 365		  pop_declspec_stack(); }
 366	| setspecs notype_declarator
 367		{ if (!start_function(NULL, $2,
 368				      prefix_attributes, 0))
 369		    YYERROR1; }
 370	  old_style_parm_decls
 371		{ store_parm_decls($4); }
 372	  compstmt_or_error
 373		{ $$ = finish_function($6); 
 374		  pop_declspec_stack(); }
 375	| setspecs notype_declarator error
 376		{ $$ = new_error_decl(pr, last_location);
 377		  pop_declspec_stack(); }
 378	;
 379
 380identifier:
 381	IDENTIFIER
 382	| TYPENAME
 383	;
 384
 385id_label:
 386	identifier { $$ = new_id_label(pr, $1.location, $1.id); }
 387	;
 388
 389idword:
 390	identifier { $$ = new_word(pr, $1.location, $1.id); }
 391
 392unop:     '&'
 393		{ $$ = $1; $$.i = kind_address_of; }
 394	| '-'
 395		{ $$ = $1; $$.i = kind_unary_minus; }
 396	| '+'
 397		{ $$ = $1; $$.i = kind_unary_plus; }
 398	| PLUSPLUS
 399		{ $$ = $1; $$.i = kind_preincrement; }
 400	| MINUSMINUS
 401		{ $$ = $1; $$.i = kind_predecrement; }
 402	| '~'
 403		{ $$ = $1; $$.i = kind_bitnot; }
 404	| '!'
 405		{ $$ = $1; $$.i = kind_not; }
 406	| REALPART
 407		{ $$ = $1; $$.i = kind_realpart; }
 408	| IMAGPART
 409		{ $$ = $1; $$.i = kind_imagpart; }
 410	;
 411
 412expr:	nonnull_exprlist
 413		{ if ($1->next)
 414		    $$ = make_comma($1->location, $1);
 415		  else
 416		    $$ = $1; }
 417	;
 418
 419exprlist:
 420	  /* empty */
 421		{ $$ = NULL; }
 422	| nonnull_exprlist
 423	;
 424
 425nonnull_exprlist:
 426	expr_no_commas
 427		{ $$ = $1; }
 428	| nonnull_exprlist ',' expr_no_commas
 429		{ $$ = expression_chain($1, $3); }
 430	;
 431
 432unary_expr:
 433	primary
 434	| '*' cast_expr   %prec UNARY
 435		{ $$ = make_dereference($1.location, $2); }
 436	/* __extension__ turns off -pedantic for following primary.  */
 437	| extension cast_expr	  %prec UNARY
 438		{ $$ = make_extension_expr($1.location, $2);
 439		  pedantic = $1.i; }
 440	| unop cast_expr  %prec UNARY
 441		{ $$ = make_unary($1.location, $1.i, $2);
 442#if 0
 443		  overflow_warning($$); 
 444#endif
 445		}
 446	/* Refer to the address of a label as a pointer.  */
 447	| ANDAND id_label
 448		{
 449		  $$ = CAST(expression, make_label_address($1.location, $2));
 450		  use_label($2);
 451		}
 452	| sizeof unary_expr  %prec UNARY
 453		{ 
 454#if 0
 455		  if (TREE_CODE ($2) == COMPONENT_REF
 456		      && DECL_C_BIT_FIELD (TREE_OPERAND ($2, 1)))
 457		    error("`sizeof' applied to a bit-field");
 458		  $$ = c_sizeof (TREE_TYPE ($2)); 
 459#endif
 460		  $$ = make_sizeof_expr($1.location, $2);
 461		  unevaluated_expression--; }
 462	| sizeof '(' typename ')'  %prec HYPERUNARY
 463		{ $$ = make_sizeof_type($1.location, $3);
 464		  unevaluated_expression--; }
 465	| alignof unary_expr  %prec UNARY
 466		{ $$ = make_alignof_expr($1.location, $2);
 467		  unevaluated_expression--; }
 468	| alignof '(' typename ')'  %prec HYPERUNARY
 469		{ $$ = make_alignof_type($1.location, $3); 
 470		  unevaluated_expression--; }
 471	;
 472
 473sizeof:
 474	SIZEOF { unevaluated_expression++; $$ = $1; }
 475	;
 476
 477alignof:
 478	ALIGNOF { unevaluated_expression++; $$ = $1; }
 479	;
 480
 481cast_expr:
 482	unary_expr
 483	| '(' typename ')' cast_expr  %prec UNARY
 484	  	{ $$ = make_cast($1.location, $2, $4); }
 485	| '(' typename ')' '{' 
 486		{ 
 487#if 0
 488		  start_init (NULL, NULL, 0);
 489		  $2 = groktypename ($2);
 490		  really_start_incremental_init ($2); 
 491#endif
 492		}
 493	  initlist_maybe_comma '}'  %prec UNARY
 494		{ 
 495		  $$ = CAST(expression, new_cast_list(pr, $1.location, $2, CAST(expression, new_init_list(pr, $6->location, $6))));
 496		  $$->type = $2->type;
 497		  /* XXX: Evil hack for foo((int[5]) {1, 2, 3}) */
 498		  /* XXX: what does gcc do ? */
 499		  if (type_array($$->type))
 500		    $$->lvalue = TRUE;
 501
 502		  if (pedantic)
 503		    pedwarn("ANSI C forbids constructor expressions");
 504#if 0
 505		  char *name;
 506		  tree result = pop_init_level (0);
 507		  tree type = $2;
 508		  finish_init ();
 509
 510		  if (TYPE_NAME (type) != 0)
 511		    {
 512		      if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
 513			name = IDENTIFIER_POINTER (TYPE_NAME (type));
 514		      else
 515			name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
 516		    }
 517		  else
 518		    name = "";
 519		  $$ = result;
 520		  if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
 521		    {
 522		      int failure = complete_array_type (type, $$, 1);
 523		      if (failure)
 524			abort ();
 525		    }
 526#endif
 527		}
 528	;
 529
 530expr_no_commas:
 531	  cast_expr
 532	| expr_no_commas '+' expr_no_commas
 533	    	{ $$ = make_binary($2.location, kind_plus, $1, $3); }
 534	| expr_no_commas '-' expr_no_commas
 535	    	{ $$ = make_binary($2.location, kind_minus, $1, $3); }
 536	| expr_no_commas '*' expr_no_commas
 537	    	{ $$ = make_binary($2.location, kind_times, $1, $3); }
 538	| expr_no_commas '/' expr_no_commas
 539	    	{ $$ = make_binary($2.location, kind_divide, $1, $3); }
 540	| expr_no_commas '%' expr_no_commas
 541	    	{ $$ = make_binary($2.location, kind_modulo, $1, $3); }
 542	| expr_no_commas LSHIFT expr_no_commas
 543	    	{ $$ = make_binary($2.location, kind_lshift, $1, $3); }
 544	| expr_no_commas RSHIFT expr_no_commas
 545	    	{ $$ = make_binary($2.location, kind_rshift, $1, $3); }
 546	| expr_no_commas ARITHCOMPARE expr_no_commas
 547	    	{ $$ = make_binary($2.location, $2.i, $1, $3); }
 548	| expr_no_commas EQCOMPARE expr_no_commas
 549	    	{ $$ = make_binary($2.location, $2.i, $1, $3); }
 550	| expr_no_commas '&' expr_no_commas
 551	    	{ $$ = make_binary($2.location, kind_bitand, $1, $3); }
 552	| expr_no_commas '|' expr_no_commas
 553	    	{ $$ = make_binary($2.location, kind_bitor, $1, $3); }
 554	| expr_no_commas '^' expr_no_commas
 555	    	{ $$ = make_binary($2.location, kind_bitxor, $1, $3); }
 556	| expr_no_commas ANDAND expr_no_commas
 557	    	{ $$ = make_binary($2.location, kind_andand, $1, $3); }
 558	| expr_no_commas OROR expr_no_commas
 559	    	{ $$ = make_binary($2.location, kind_oror, $1, $3); }
 560	| expr_no_commas '?' expr ':' expr_no_commas
 561	  	{ $$ = make_conditional($2.location, $1, $3, $5); }
 562	| expr_no_commas '?'
 563		{ if (pedantic)
 564		    pedwarn("ANSI C forbids omitting the middle term of a ?: expression"); 
 565		}
 566	  ':' expr_no_commas
 567	  	{ $$ = make_conditional($2.location, $1, NULL, $5); }
 568	| expr_no_commas '=' expr_no_commas
 569	    	{ $$ = make_assign($2.location, kind_assign, $1, $3); }
 570	| expr_no_commas ASSIGN expr_no_commas
 571	    	{ $$ = make_assign($2.location, $2.i, $1, $3); }
 572	;
 573
 574primary:
 575	IDENTIFIER
 576		{ 
 577		  if (yychar == YYEMPTY)
 578		    yychar = YYLEX;
 579		  $$ = make_identifier($1.location, $1.id, yychar == '('); 
 580		}
 581	| CONSTANT { $$ = CAST(expression, $1); }
 582	| string { $$ = CAST(expression, $1); }
 583	| '(' expr ')'
 584		{ $$ = $2; }
 585	| '(' error ')'
 586		{ $$ = make_error_expr(last_location); }
 587	| '('
 588		{ if (current_function_decl == 0)
 589		    {
 590		      error("braced-group within expression allowed only inside a function");
 591		      YYERROR;
 592		    }
 593		    push_label_level();
 594		}
 595	  compstmt ')'
 596		{ 
 597		  pop_label_level();
 598		  if (pedantic)
 599		    pedwarn("ANSI C forbids braced-groups within expressions");
 600		  $$ = make_compound_expr($1.location, $3);
 601		}
 602	| primary '(' exprlist ')'   %prec '.'
 603	  	{ $$ = make_function_call($2.location, $1, $3); }
 604	| VA_ARG '(' expr_no_commas ',' typename ')'
 605		{ $$ = make_va_arg($1.location, $3, $5); }
 606	| primary '[' expr ']'   %prec '.'
 607		{ $$ = make_array_ref($2.location, $1, $3); }
 608	| primary '.' identifier
 609		{ $$ = make_field_ref($2.location, $1, $3.id); }
 610	| primary POINTSAT identifier
 611		{ $$ = make_field_ref($2.location, make_dereference($2.location, $1),
 612				      $3.id); }
 613	| primary PLUSPLUS
 614		{ $$ = make_postincrement($2.location, $1); }
 615	| primary MINUSMINUS
 616		{ $$ = make_postdecrement($2.location, $1); }
 617	;
 618
 619/* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it.  */
 620string:
 621	string_list { $$ = make_string($1->location, $1); }
 622
 623string_list:
 624	string_component { $$ = $1; }
 625	| string_list string_component
 626		{ $$ = expression_chain($1, $2); }
 627	;
 628
 629string_component:
 630	STRING { $$ = CAST(expression, $1); }
 631	| MAGIC_STRING
 632	  { $$ = make_identifier($1.location, $1.id, FALSE);
 633	  }
 634	;
 635
 636
 637old_style_parm_decls:
 638	/* empty */ { $$ = NULL; }
 639	| datadecls
 640	| datadecls ELLIPSIS
 641		/* ... is used here to indicate a varargs function.  */
 642		{ if (pedantic)
 643		    pedwarn("ANSI C does not permit use of `varargs.h'"); 
 644		  $$ = declaration_chain($1, CAST(declaration, new_ellipsis_decl(pr, $2.location)));
 645		}
 646	;
 647
 648/* The following are analogous to decls and decl
 649   except that they do not allow nested functions.
 650   They are used for old-style parm decls.  */
 651datadecls:
 652	datadecl
 653	| errstmt { $$ = new_error_decl(pr, last_location); }
 654	| datadecls datadecl { $$ = declaration_chain($1, $2); }
 655	| datadecl errstmt { $$ = new_error_decl(pr, last_location); }
 656	;
 657
 658/* We don't allow prefix attributes here because they cause reduce/reduce
 659   conflicts: we can't know whether we're parsing a function decl with
 660   attribute suffix, or function defn with attribute prefix on first old
 661   style parm.  */
 662datadecl:
 663	typed_declspecs_no_prefix_attr setspecs initdecls ';'
 664		{ $$ = CAST(declaration, new_data_decl(pr, $1->location, current_declspecs, prefix_attributes, $3));
 665		  pop_declspec_stack(); }
 666	| declmods_no_prefix_attr setspecs notype_initdecls ';'
 667		{ $$ = CAST(declaration, new_data_decl(pr, $1->location, current_declspecs, prefix_attributes, $3));
 668		  pop_declspec_stack(); }
 669	| typed_declspecs_no_prefix_attr setspecs ';'
 670		{ shadow_tag_warned($1, 1);
 671		  $$ = CAST(declaration, new_data_decl(pr, $1->location, current_declspecs, prefix_attributes, NULL));
 672		  pop_declspec_stack();
 673		  pedwarn("empty declaration"); }
 674	| declmods_no_prefix_attr ';'
 675		{ pedwarn("empty declaration"); 
 676		  $$ = NULL; }
 677	;
 678
 679/* This combination which saves a lineno before a decl
 680   is the normal thing to use, rather than decl itself.
 681   This is to avoid shift/reduce conflicts in contexts
 682   where statement labels are allowed.  */
 683decls:
 684	decl
 685	| errstmt { $$ = new_error_decl(pr, last_location); }
 686	| decls decl { $$ = declaration_chain($1, $2); }
 687	| decl errstmt { $$ = new_error_decl(pr, last_location); }
 688	;
 689
 690/* records the type and storage class specs to use for processing
 691   the declarators that follow.
 692   Maintains a stack of outer-level values of current_declspecs,
 693   for the sake of parm declarations nested in function declarators.  */
 694setspecs: /* empty */
 695		{ 
 696		  push_declspec_stack();
 697		  pending_xref_error();
 698		  split_type_elements($<u.telement>0,
 699				      &current_declspecs, &prefix_attributes);
 700		}
 701	;
 702
 703/* ??? Yuck.  See after_type_declarator.  */
 704setattrs: /* empty */
 705		{ prefix_attributes = attribute_chain(prefix_attributes,
 706						      $<u.attribute>0); 
 707		/* This syntax is broken as it will apply to all remaining
 708		   declarations, not just the current declarator 
 709		   (this is broken in base GCC too) */
 710		/* XXX: Used extensively in the linux kernel. YUCK. */
 711		/*error("Unsupported attribute syntax");*/ }
 712	;
 713
 714decl:
 715	typed_declspecs setspecs initdecls ';'
 716		{ $$ = CAST(declaration, new_data_decl(pr, $1->location, current_declspecs, prefix_attributes, $3));
 717		  pop_declspec_stack(); }
 718	| declmods setspecs notype_initdecls ';'
 719		{ $$ = CAST(declaration, new_data_decl(pr, $1->location, current_declspecs, prefix_attributes, $3));
 720		  pop_declspec_stack(); }
 721	| typed_declspecs setspecs nested_function
 722		{ $$ = $3;
 723		  pop_declspec_stack(); }
 724	| declmods setspecs notype_nested_function
 725		{ $$ = $3;
 726		  pop_declspec_stack(); }
 727	| typed_declspecs setspecs ';'
 728		{ shadow_tag($1);
 729		  $$ = CAST(declaration, new_data_decl(pr, $1->location, current_declspecs, prefix_attributes, NULL));
 730		  pop_declspec_stack(); }
 731	| declmods ';'
 732		{ pedwarn("empty declaration"); }
 733	| extension decl
 734		{ pedantic = $1.i; 
 735		  $$ = CAST(declaration, new_extension_decl(pr, $1.location, $2)); }
 736	;
 737
 738/* Declspecs which contain at least one type specifier or typedef name.
 739   (Just `const' or `volatile' is not enough.)
 740   A typedef'd name following these is taken as a name to be declared. */
 741
 742typed_declspecs:
 743	  typespec reserved_declspecs
 744		{ $$ = $1; $1->next = CAST(node, $2); }
 745	| declmods typespec reserved_declspecs
 746		{ $$ = type_element_chain($1, $2); $2->next = CAST(node, $3); }
 747	;
 748
 749reserved_declspecs:  /* empty */
 750		{ $$ = NULL; }
 751	| reserved_declspecs typespecqual_reserved
 752		{ $$ = type_element_chain($1, $2); }
 753	| reserved_declspecs scspec
 754		{ if (extra_warnings)
 755		    warning("`%s' is not at beginning of declaration",
 756			    rid_name(CAST(rid, $2)));
 757		  $$ = type_element_chain($1, $2); }
 758	| reserved_declspecs attributes
 759		{ $$ = type_element_chain($1, CAST(type_element, $2)); }
 760	;
 761
 762typed_declspecs_no_prefix_attr:
 763	  typespec reserved_declspecs_no_prefix_attr
 764		{ $$ = $1; $1->next = CAST(node, $2); }
 765	| declmods_no_prefix_attr typespec reserved_declspecs_no_prefix_attr
 766		{ $$ = type_element_chain($1, $2); $2->next = CAST(node, $3); }
 767	;
 768
 769reserved_declspecs_no_prefix_attr:
 770	  /* empty */
 771		{ $$ = NULL; }
 772	| reserved_declspecs_no_prefix_attr typespecqual_reserved
 773		{ $$ = type_element_chain($1, $2); }
 774	| reserved_declspecs_no_prefix_attr scspec
 775		{ if (extra_warnings)
 776		    warning("`%s' is not at beginning of declaration",
 777			    rid_name(CAST(rid, $2)));
 778		  $$ = type_element_chain($1, $2); }
 779	;
 780
 781/* List of just storage classes, type modifiers, and prefix attributes.
 782   A declaration can start with just this, but then it cannot be used
 783   to redeclare a typedef-name.
 784   Declspecs have a non-NULL TREE_VALUE, attributes do not.  */
 785
 786declmods:
 787	  declmods_no_prefix_attr
 788	| attributes { $$ = CAST(type_element, $1); }
 789	| declmods declmods_no_prefix_attr
 790		{ $$ = type_element_chain($1, $2); }
 791	| declmods attributes
 792		{ $$ = type_element_chain($1, CAST(type_element, $2)); }
 793	;
 794
 795declmods_no_prefix_attr:
 796	  type_qual
 797	| scspec
 798	| declmods_no_prefix_attr type_qual
 799		{ $$ = type_element_chain($1, $2); }
 800	| declmods_no_prefix_attr scspec
 801		{ if (extra_warnings /*&& TREE_STATIC ($1)*/)
 802		    warning("`%s' is not at beginning of declaration",
 803			    rid_name(CAST(rid, $2)));
 804		  $$ = type_element_chain($1, $2); }
 805	;
 806
 807
 808/* Used instead of declspecs where storage classes are not allowed
 809   (that is, for typenames and structure components).
 810   Don't accept a typedef-name if anything but a modifier precedes it.  */
 811
 812typed_typespecs:
 813	  typespec reserved_typespecquals
 814		{ $$ = $1; $1->next = CAST(node, $2); }
 815	| nonempty_type_quals typespec reserved_typespecquals
 816		{ $$ = type_element_chain($1, $2); $2->next = CAST(node, $3); }
 817	;
 818
 819reserved_typespecquals:  /* empty */
 820		{ $$ = NULL; }
 821	| reserved_typespecquals typespecqual_reserved
 822		{ $$ = type_element_chain($1, $2); }
 823	;
 824
 825/* A typespec (but not a type qualifier).
 826   Once we have seen one of these in a declaration,
 827   if a typedef name appears then it is being redeclared.  */
 828
 829typespec: type_spec
 830	| structsp
 831	| TYPENAME
 832		{ /* For a typedef name, record the meaning, not the name.
 833		     In case of `foo foo, bar;'.  */
 834		  $$ = CAST(type_element, new_typename(pr, $1.location, $1.decl)); }
 835	| TYPEOF '(' expr ')'
 836		{ $$ = CAST(type_element, new_typeof_expr(pr, $1.location, $3)); }
 837	| TYPEOF '(' typename ')'
 838		{ $$ = CAST(type_element, new_typeof_type(pr, $1.location, $3)); }
 839	;
 840
 841/* A typespec that is a reserved word, or a type qualifier.  */
 842
 843typespecqual_reserved: type_spec
 844	| type_qual
 845	| structsp
 846	;
 847
 848initdecls:
 849	initdcl
 850	| initdecls ',' initdcl { $$ = declaration_chain($1, $3); }
 851	;
 852
 853notype_initdecls:
 854	notype_initdcl { $$ = $1; }
 855	| notype_initdecls ',' initdcl { $$ = declaration_chain($1, $3); }
 856	;
 857
 858maybeasm:
 859	  /* empty */
 860		{ $$ = NULL; }
 861	| ASM_KEYWORD '(' string ')'
 862		{ $$ = new_asm_stmt(pr, $1.location, CAST(expression, $3),
 863				    NULL, NULL, NULL, NULL); }
 864	;
 865
 866initdcl:
 867	  declarator maybeasm maybe_attribute '='
 868		{ $<u.decl>$ = start_decl($1, $2, current_declspecs, 1,
 869					$3, prefix_attributes); }
 870	  init
 871/* Note how the declaration of the variable is in effect while its init is parsed! */
 872		{ $$ = finish_decl($<u.decl>5, $6); }
 873	| declarator maybeasm maybe_attribute
 874		{ declaration d = start_decl($1, $2, current_declspecs, 0,
 875					     $3, prefix_attributes);
 876		  $$ = finish_decl(d, NULL); }
 877	;
 878
 879notype_initdcl:
 880	  notype_declarator maybeasm maybe_attribute '='
 881		{ $<u.decl>$ = start_decl($1, $2, current_declspecs, 1,
 882					 $3, prefix_attributes); }
 883	  init
 884/* Note how the declaration of the variable is in effect while its init is parsed! */
 885		{ $$ = finish_decl($<u.decl>5, $6); }
 886	| notype_declarator maybeasm maybe_attribute
 887		{ declaration d = start_decl($1, $2, current_declspecs, 0,
 888					     $3, prefix_attributes);
 889		  $$ = finish_decl(d, NULL); }
 890	;
 891maybe_attribute:
 892      /* empty */
 893  		{ $$ = NULL; }
 894	| attributes
 895		{ $$ = $1; }
 896	;
 897 
 898attributes:
 899      attribute
 900		{ $$ = $1; }
 901	| attributes attribute
 902		{ $$ = attribute_chain($1, $2); }
 903	;
 904
 905attribute:
 906      ATTRIBUTE '(' '(' attribute_list ')' ')'
 907		{ $$ = $4; }
 908	;
 909
 910attribute_list:
 911      attrib
 912		{ $$ = $1; }
 913	| attribute_list ',' attrib
 914		{ $$ = attribute_chain($1, $3); }
 915	;
 916 
 917attrib:
 918    /* empty */
 919		{ $$ = NULL; }
 920	| any_word
 921		{ $$ = new_attribute(pr, $1->location, $1, NULL, NULL); }
 922	| any_word '(' IDENTIFIER ')'
 923		{ $$ = new_attribute
 924		    (pr, $1->location, $1, new_word(pr, $3.location, $3.id), NULL); }
 925	| any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
 926		{ $$ = new_attribute
 927		    (pr, $2.location, $1, new_word(pr, $3.location, $3.id), $5);
 928		}
 929	| any_word '(' exprlist ')'
 930		{ $$ = new_attribute(pr, $2.location, $1, NULL, $3); }
 931	;
 932
 933/* This still leaves out most reserved keywords,
 934   shouldn't we include them?  */
 935
 936any_word:
 937	  idword
 938	| scspec { $$ = new_word(pr, $1->location, str2cstring(pr, rid_name(CAST(rid, $1)))); }
 939	| type_spec { $$ = new_word(pr, $1->location, str2cstring(pr, rid_name(CAST(rid, $1)))); }
 940	| type_qual { $$ = new_word(pr, $1->location, str2cstring(pr, qualifier_name(CAST(qualifier, $1)->id))); }
 941	;
 942
 943/* Initializers.  `init' is the entry point.  */
 944
 945init:
 946	expr_no_commas
 947	| '{'
 948	  initlist_maybe_comma '}'
 949		{ $$ = CAST(expression, new_init_list(pr, $1.location, $2)); 
 950		  $$->type = error_type; }
 951	| error
 952		{ $$ = make_error_expr(last_location); }
 953	;
 954
 955/* `initlist_maybe_comma' is the guts of an initializer in braces.  */
 956initlist_maybe_comma:
 957	  /* empty */
 958		{ if (pedantic)
 959		    pedwarn("ANSI C forbids empty initializer braces"); 
 960		  $$ = NULL; }
 961	| initlist1 maybecomma { $$ = $1; }
 962	;
 963
 964initlist1:
 965	  initelt
 966	| initlist1 ',' initelt { $$ = expression_chain($1, $3); }
 967	;
 968
 969/* `initelt' is a single element of an initializer.
 970   It may use braces.  */
 971initelt:
 972	expr_no_commas { $$ = $1; }
 973	| '{' initlist_maybe_comma '}'
 974		{ $$ = CAST(expression, new_init_list(pr, $1.location, $2)); }
 975	| error { $$ = make_error_expr(last_location); }
 976	/* These are for labeled elements.  The syntax for an array element
 977	   initializer conflicts with the syntax for an Objective-C message,
 978	   so don't include these productions in the Objective-C grammar.  */
 979	| '[' expr_no_commas ELLIPSIS expr_no_commas ']' '=' initelt
 980	    	{ $$ = CAST(expression, new_init_index(pr, $1.location, $2, $4, $7)); }
 981	| '[' expr_no_commas ']' '=' initelt
 982	    	{ $$ = CAST(expression, new_init_index(pr, $1.location, $2, NULL, $5)); }
 983	| '[' expr_no_commas ']' initelt
 984	    	{ $$ = CAST(expression, new_init_index(pr, $1.location, $2, NULL, $4)); }
 985	| idword ':' initelt
 986	    	{ $$ = CAST(expression, new_init_field(pr, $1->location, $1, $3)); }
 987	| '.' idword '=' initelt
 988	    	{ $$ = CAST(expression, new_init_field(pr, $1.location, $2, $4)); }
 989	;
 990
 991nested_function:
 992	  declarator
 993		{ if (!start_function(current_declspecs, $1,
 994				      prefix_attributes, 1))
 995		    {
 996		      YYERROR1;
 997		    }
 998		  }
 999	   old_style_parm_decls
1000		{ store_parm_decls($3); }
1001/* This used to use compstmt_or_error.
1002   That caused a bug with input `f(g) int g {}',
1003   where the use of YYERROR1 above caused an error
1004   which then was handled by compstmt_or_error.
1005   There followed a repeated execution of that same rule,
1006   which called YYERROR1 again, and so on.  */
1007	  compstmt
1008		{ $$ = finish_function($5); }
1009	;
1010
1011notype_nested_function:
1012	  notype_declarator
1013		{ if (!start_function(current_declspecs, $1,
1014				      prefix_attributes, 1))
1015		    {
1016		      YYERROR1;
1017		    }
1018		}
1019	  old_style_parm_decls
1020		{ store_parm_decls($3); }
1021/* This used to use compstmt_or_error.
1022   That caused a bug with input `f(g) int g {}',
1023   where the use of YYERROR1 above caused an error
1024   which then was handled by compstmt_or_error.
1025   There followed a repeated execution of that same rule,
1026   which called YYERROR1 again, and so on.  */
1027	  compstmt
1028		{ $$ = finish_function($5); }
1029	;
1030
1031/* Any kind of declarator (thus, all declarators allowed
1032   after an explicit typespec).  */
1033
1034declarator:
1035	  after_type_declarator
1036	| notype_declarator
1037	;
1038
1039/* A declarator that is allowed only after an explicit typespec.  */
1040
1041after_type_declarator:
1042	  '(' after_type_declarator ')'
1043		{ $$ = $2; }
1044	| after_type_declarator '(' parmlist_or_identifiers fn_quals %prec '.'
1045		{ $$ = make_function_declarator($2.location, $1, $3, $4); }
1046	| after_type_declarator '[' expr ']'  %prec '.'
1047		{ $$ = CAST(declarator, new_array_declarator(pr, $2.location, $1, $3)); }
1048	| after_type_declarator '[' ']'  %prec '.'
1049		{ $$ = CAST(declarator, new_array_declarator(pr, $2.location, $1, NULL)); }
1050	| '*' type_quals after_type_declarator  %prec UNARY
1051		{ $$ = CAST(declarator, new_pointer_declarator(pr, $1.location, $3, $2)); }
1052	/* ??? Yuck.  setattrs is a quick hack.  We can't use
1053	   prefix_attributes because $1 only applies to this
1054	   declarator.  We assume setspecs has already been done.
1055	   setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1056	   attributes could be recognized here or in `attributes').  */
1057	| attributes setattrs after_type_declarator
1058		{ $$ = $3; }
1059	| TYPENAME { $$ = CAST(declarator, new_identifier_declarator(pr, $1.location, $1.id)); }
1060	;
1061
1062/* Kinds of declarator that can appear in a parameter list
1063   in addition to notype_declarator.  This is like after_type_declarator
1064   but does not allow a typedef name in parentheses as an identifier
1065   (because it would conflict with a function with that typedef as arg).  */
1066
1067parm_declarator:
1068	  parm_declarator '(' parmlist_or_identifiers fn_quals  %prec '.'
1069		{ $$ = make_function_declarator($2.location, $1, $3, $4); }
1070	| parm_declarator '[' expr ']'  %prec '.'
1071		{ $$ = CAST(declarator, new_array_declarator(pr, $2.location, $1, $3)); }
1072	| parm_declarator '[' ']'  %prec '.'
1073		{ $$ = CAST(declarator, new_array_declarator(pr, $2.location, $1, NULL)); }
1074	| '*' type_quals parm_declarator  %prec UNARY
1075		{ $$ = CAST(declarator, new_pointer_declarator(pr, $1.location, $3, $2)); }
1076	/* ??? Yuck.  setattrs is a quick hack.  We can't use
1077	   prefix_attributes because $1 only applies to this
1078	   declarator.  We assume setspecs has already been done.
1079	   setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1080	   attributes could be recognized here or in `attributes').  */
1081	| attributes setattrs parm_declarator
1082		{ $$ = $3; }
1083	| TYPENAME { $$ = CAST(declarator, new_identifier_declarator(pr, $1.location, $1.id)); }
1084	;
1085
1086/* A declarator allowed whether or not there has been
1087   an explicit typespec.  These cannot redeclare a typedef-name.  */
1088
1089notype_declarator:
1090	  notype_declarator '(' parmlist_or_identifiers fn_quals  %prec '.'
1091		{ $$ = make_function_declarator($2.location, $1, $3, $4); }
1092	| '(' notype_declarator ')'
1093		{ $$ = $2; }
1094	| '*' type_quals notype_declarator  %prec UNARY
1095		{ $$ = CAST(declarator, new_pointer_declarator(pr, $1.location, $3, $2)); }
1096	| notype_declarator '[' expr ']'  %prec '.'
1097		{ $$ = CAST(declarator, new_array_declarator(pr, $2.location, $1, $3)); }
1098	| notype_declarator '[' ']'  %prec '.'
1099		{ $$ = CAST(declarator, new_array_declarator(pr, $2.location, $1, NULL)); }
1100	/* ??? Yuck.  setattrs is a quick hack.  We can't use
1101	   prefix_attributes because $1 only applies to this
1102	   declarator.  We assume setspecs has already been done.
1103	   setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1104	   attributes could be recognized here or in `attributes').  */
1105	| attributes setattrs notype_declarator
1106		{ $$ = $3; }
1107	| IDENTIFIER { $$ = CAST(declarator, new_identifier_declarator(pr, $1.location, $1.id)); }
1108	;
1109
1110tag:
1111	identifier { $$ = new_word(pr, $1.location, $1.id); }
1112	;
1113
1114structsp:
1115	  STRUCT tag '{'
1116		{ $$ = start_struct($1.location, kind_struct_ref, $2);
1117		  /* Start scope of tag before parsing components.  */
1118		}
1119	  component_decl_list '}' maybe_attribute 
1120		{ $$ = finish_struct($<u.telement>4, $5, $7); }
1121	| STRUCT '{' component_decl_list '}' maybe_attribute
1122		{ $$ = finish_struct(start_struct($1.location, kind_struct_ref, NULL),
1123				     $3, $5);
1124		}
1125	| STRUCT tag
1126		{ $$ = xref_tag($1.location, kind_struct_ref, $2); }
1127	| UNION tag '{'
1128		{ $$ = start_struct ($1.location, kind_union_ref, $2); }
1129	  component_decl_list '}' maybe_attribute
1130		{ $$ = finish_struct($<u.telement>4, $5, $7); }
1131	| UNION '{' component_decl_list '}' maybe_attribute
1132		{ $$ = finish_struct(start_struct($1.location, kind_union_ref, NULL),
1133				     $3, $5);
1134		}
1135	| UNION tag
1136		{ $$ = xref_tag($1.location, kind_union_ref, $2); }
1137	| ENUM tag '{'
1138		{ $$ = start_enum($1.location, $2); }
1139	  enumlist maybecomma_warn '}' maybe_attribute
1140		{ $$ = finish_enum($<u.telement>4, $5, $8); }
1141	| ENUM '{'
1142		{ $$ = start_enum($1.location, NULL); }
1143	  enumlist maybecomma_warn '}' maybe_attribute
1144		{ $$ = finish_enum($<u.telement>3, $4, $7); }
1145	| ENUM tag
1146		{ $$ = xref_tag($1.location, kind_enum_ref, $2); }
1147	;
1148
1149maybecomma:
1150	  /* empty */
1151	| ','
1152	;
1153
1154maybecomma_warn:
1155	  /* empty */
1156	| ','
1157		{ if (pedantic) pedwarn("comma at end of enumerator list"); }
1158	;
1159
1160component_decl_list:
1161	  component_decl_list2
1162		{ $$ = $1; }
1163	| component_decl_list2 component_decl
1164		{ $$ = declaration_chain($1, $2);
1165		  pedwarn("no semicolon at end of struct or union"); }
1166	;
1167
1168component_decl_list2:	/* empty */
1169		{ $$ = NULL; }
1170	| component_decl_list2 component_decl ';'
1171		{ $$ = declaration_chain($1, $2); }
1172	| component_decl_list2 ';'
1173		{ if (pedantic)
1174		    pedwarn("extra semicolon in struct or union specified"); 
1175		   $$ = $1; }
1176	;
1177
1178/* There is a shift-reduce conflict here, because `components' may
1179   start with a `typename'.  It happens that shifting (the default resolution)
1180   does the right thing, because it treats the `typename' as part of
1181   a `typed_typespecs'.
1182
1183   It is possible that this same technique would allow the distinction
1184   between `notype_initdecls' and `initdecls' to be eliminated.
1185   But I am being cautious and not trying it.  */
1186
1187component_decl:
1188	  typed_typespecs setspecs components
1189		{ $$ = CAST(declaration, new_data_decl(pr, $1->location, current_declspecs, prefix_attributes, $3));
1190		  pop_declspec_stack(); }
1191	| typed_typespecs setspecs
1192		{ if (pedantic)
1193		    pedwarn("ANSI C forbids member declarations with no members");
1194		  shadow_tag($1);
1195		  $$ = CAST(declaration, new_data_decl(pr, $1->location, current_declspecs, prefix_attributes, NULL));
1196		  pop_declspec_stack(); }
1197	| nonempty_type_quals setspecs components
1198		{ $$ = CAST(declaration, new_data_decl(pr, $1->location, current_declspecs, prefix_attributes, $3));
1199		  pop_declspec_stack(); }
1200	| nonempty_type_quals setspecs
1201		{ if (pedantic)
1202		    pedwarn("ANSI C forbids member declarations with no members");
1203		  shadow_tag($1);
1204		  $$ = CAST(declaration, new_data_decl(pr, $1->location, current_declspecs, prefix_attributes, NULL));	
1205		  pop_declspec_stack(); }
1206	| error
1207		{ $$ = new_error_decl(pr, last_location); }
1208	| extension component_decl
1209		{ pedantic = $<u.itoken>1.i;
1210		  $$ = CAST(declaration, new_extension_decl(pr, $1.location, $2)); }
1211	;
1212
1213components:
1214	  component_declarator
1215	| components ',' component_declarator
1216		{ $$ = declaration_chain($1, $3); }
1217	;
1218
1219component_declarator:
1220	  declarator maybe_attribute
1221		{ $$ = make_field($1, NULL, current_declspecs,
1222				  $2, prefix_attributes); }
1223	| declarator ':' expr_no_commas maybe_attribute
1224		{ $$ = make_field($1, $3, current_declspecs,
1225				  $4, prefix_attributes); }
1226	| ':' expr_no_commas maybe_attribute
1227		{ $$ = make_field(NULL, $2, current_declspecs,
1228				  $3, prefix_attributes); }
1229	;
1230
1231enumlist:
1232	  enumerator
1233	| enumlist ',' enumerator
1234		{ $$ = declaration_chain($1, $3); }
1235	| error
1236		{ $$ = NULL; }
1237	;
1238
1239
1240enumerator:
1241	  identifier
1242	  	{ $$ = make_enumerator($1.location, $1.id, NULL); }
1243	| identifier '=' expr_no_commas
1244	  	{ $$ = make_enumerator($1.location, $1.id, $3); }
1245	;
1246
1247typename:
1248	typed_typespecs absdcl
1249		{ $$ = make_type($1, $2); }
1250	| nonempty_type_quals absdcl
1251		{ $$ = make_type($1, $2); }
1252	;
1253
1254absdcl:   /* an abstract declarator */
1255	/* empty */
1256		{ $$ = NULL; }
1257	| absdcl1
1258	;
1259
1260nonempty_type_quals:
1261	  type_qual
1262	| nonempty_type_quals type_qual
1263		{ $$ = type_element_chain($1, $2); }
1264	;
1265
1266type_quals:
1267	  /* empty */
1268		{ $$ = NULL; }
1269	| type_quals type_qual
1270		{ $$ = type_element_chain($1, $2); }
1271	;
1272
1273absdcl1:  /* a nonempty abstract declarator */
1274	  '(' absdcl1 ')'
1275		{ $$ = $2; }
1276	  /* `(typedef)1' is `int'.  */
1277	| '*' type_quals absdcl1  %prec UNARY
1278		{ $$ = CAST(declarator, new_pointer_declarator(pr, $1.location, $3, $2)); }
1279	| '*' type_quals  %prec UNARY
1280		{ $$ = CAST(declarator, new_pointer_declarator(pr, $1.location, NULL, $2)); }
1281	| absdcl1 '(' parmlist fn_quals  %prec '.'
1282		{ $$ = make_function_declarator($2.location, $1, $3, $4); }
1283	| absdcl1 '[' expr ']'  %prec '.'
1284		{ $$ = CAST(declarator, new_array_declarator(pr, $2.location, $1, $3)); }
1285	| absdcl1 '[' ']'  %prec '.'
1286		{ $$ = CAST(declarator, new_array_declarator(pr, $2.location, $1, NULL)); }
1287	| '(' parmlist fn_quals  %prec '.'
1288		{ $$ = make_function_declarator($1.location, NULL, $2, $3); }
1289	| '[' expr ']'  %prec '.'
1290		{ $$ = CAST(declarator, new_array_declarator(pr, $1.location, NULL, $2)); }
1291	| '[' ']'  %prec '.'
1292		{ $$ = CAST(declarator, new_array_declarator(pr, $1.location, NULL, NULL)); }
1293	/* ??? It appears we have to support attributes here, however
1294	   using prefix_attributes is wrong.  */
1295	;
1296
1297/* at least one statement, the first of which parses without error.  */
1298/* stmts is used only after decls, so an invalid first statement
1299   is actually regarded as an invalid decl and part of the decls.  */
1300
1301stmts:
1302	stmt_or_labels
1303		{
1304		  if (pedantic && $1.i)
1305		    pedwarn("ANSI C forbids label at end of compound statement");
1306		  /* Add an empty statement to last label if stand-alone */
1307		  if ($1.i)
1308		    {
1309		      statement last_label = CAST(statement, last_node(CAST(node, $1.stmt)));
1310
1311		      chain_with_labels(last_label, CAST(statement, new_empty_stmt(pr, last_label->location)));
1312		    }
1313		  $$ = $1.stmt;
1314		}
1315	;
1316
1317stmt_or_labels:
1318	  stmt_or_label
1319	| stmt_or_labels stmt_or_label
1320		{ $$.i = $2.i; $$.stmt = chain_with_labels($1.stmt, $2.stmt); }
1321	| stmt_or_labels errstmt
1322		{ $$.i = 0; $$.stmt = new_error_stmt(pr, last_location); }
1323	;
1324
1325xstmts:
1326	/* empty */ { $$ = NULL; }
1327	| stmts
1328	;
1329
1330errstmt:  error ';'
1331	;
1332
1333pushlevel:  /* empty */
1334		{ pushlevel(FALSE); }
1335	;
1336
1337/* Read zero or more forward-declarations for labels
1338   that nested functions can jump to.  */
1339maybe_label_decls:
1340	  /* empty */ { $$ = NULL; }
1341	| label_decls
1342		{ if (pedantic)
1343		    pedwarn("ANSI C forbids label declarations"); 
1344		  $$ = $1; }
1345	;
1346
1347label_decls:
1348	  label_decl
1349	| label_decls label_decl { $$ = id_label_chain($1, $2); }
1350	;
1351
1352label_decl:
1353	  LABEL identifiers_or_typenames ';'
1354		{ $$ = $2; }
1355	;
1356
1357/* This is the body of a function definition.
1358   It causes syntax errors to ignore to the next openbrace.  */
1359compstmt_or_error:
1360	  compstmt
1361	| error compstmt { $$ = $2; }
1362	;
1363
1364compstmt_start: '{' { $$ = $1; compstmt_count++; }
1365
1366compstmt: compstmt_start pushlevel '}'
1367		{ $$ = CAST(statement, new_compound_stmt(pr, $1.location, NULL, NULL, NULL, poplevel())); }
1368	| compstmt_start pushlevel maybe_label_decls decls xstmts '}'
1369		{ $$ = CAST(statement, new_compound_stmt(pr, $1.location, $3, $4, $5, poplevel())); }
1370	| compstmt_start pushlevel maybe_label_decls error '}'
1371		{ poplevel();
1372		  $$ = new_error_stmt(pr, last_location); }
1373	| compstmt_start pushlevel maybe_label_decls stmts '}'
1374		{ $$ = CAST(statement, new_compound_stmt(pr, $1.location, $3, NULL, $4, poplevel())); }
1375	;
1376
1377/* Value is number of statements counted as of the closeparen.  */
1378simple_if:
1379	  if_prefix labeled_stmt
1380		{ $$.stmt = CAST(statement, new_if_stmt(pr, $1.expr->location, $1.expr, $2, NULL));
1381		  $$.i = $1.i; }
1382	| if_prefix error { $$.i = $1.i; $$.stmt = new_error_stmt(pr, last_location); }
1383	;
1384
1385if_prefix:
1386	  IF '(' expr ')'
1387		{ $$.i = stmt_count;
1388		  $$.expr = $3;
1389		  check_condition("if", $3); }
1390	;
1391
1392/* This is a subroutine of stmt.
1393   It is used twice, once for valid DO statements
1394   and once for catching errors in parsing the end test.  */
1395do_stmt_start:
1396	  DO
1397		{ stmt_count++;
1398		  compstmt_count++; 
1399		  $<u.cstmt>$ = CAST(conditional_stmt,
1400				   new_dowhile_stmt(pr, $1.location, NULL, NULL));
1401		 push_loop(CAST(statement, $<u.cstmt>$)); }
1402	  labeled_stmt WHILE
1403		{ $$ = $<u.cstmt>2; 
1404		  $$->stmt = $3; }
1405	;
1406
1407labeled_stmt:
1408	  stmt
1409		{ $$ = $1; }
1410	| label labeled_stmt
1411		{ $$ = CAST(statement, new_labeled_stmt(pr, $1->location, $1, $2)); }
1412	;
1413
1414stmt_or_label:
1415	  stmt
1416		{ $$.i = 0; $$.stmt = $1; }
1417	| label
1418		{ $$.i = 1; $$.stmt = CAST(statement, new_labeled_stmt(pr, $1->location, $1, NULL)); }
1419	;
1420
1421/* Parse a single real statement, not including any labels.  */
1422stmt:
1423	  compstmt
1424		{ stmt_count++; $$ = $1; }
1425	| expr ';'
1426		{ stmt_count++;
1427		  $$ = CAST(statement, new_expression_stmt(pr, $1->location, $1)); }
1428	| simple_if ELSE
1429		{ $1.i = stmt_count; }
1430	  labeled_stmt
1431		{ if (extra_warnings && stmt_count == $1.i)
1432		    warning("empty body in an else-statement");
1433		  $$ = $1.stmt;
1434		  CAST(if_stmt, $$)->stmt2 = $4;
1435		}
1436	| simple_if %prec IF
1437		{ /* This warning is here instead of in simple_if, because we
1438		     do not want a warning if an empty if is followed by an
1439		     else statement.  Increment stmt_count so we don't
1440		     give a second error if this is a nested `if'.  */
1441		  if (extra_warnings && stmt_count++ == $1.i)
1442		    warning_with_location ($1.stmt->location,
1443					   "empty body in an if-statement");
1444		  $$ = $1.stmt; }
1445	| simple_if ELSE error
1446		{ $$ = new_error_stmt(pr, last_location); }
1447	| WHILE
1448		{ stmt_count++; }
1449	  '(' expr ')' 
1450	        { check_condition("while", $4); 
1451		  $<u.cstmt>$ = CAST(conditional_stmt,
1452			           new_while_stmt(pr, $1.location, $4, NULL));
1453		  /* The condition is not "in the loop" for break or continue */
1454		  push_loop(CAST(statement, $<u.cstmt>$)); }
1455	  labeled_stmt
1456		{ $$ = CAST(statement, $<u.cstmt>6);
1457		  $<u.cstmt>6->stmt = $7; 
1458		  pop_loop(); }
1459	| do_stmt_start '(' expr ')' ';'
1460		{ $$ = CAST(statement, $1);
1461		  $1->condition = $3;
1462		  check_condition("do-while", $3); 
1463		  /* Note that pop_loop should be before the expr to be consistent
1464		     with while, but GCC is inconsistent. See loop1.c */
1465		  pop_loop(); }
1466	| do_stmt_start error
1467		{ $$ = new_error_stmt(pr, last_location); 
1468		  pop_loop(); }
1469	| FOR '(' xexpr ';' { stmt_count++; }
1470		xexpr ';' { if ($6) check_condition("for", $6); }
1471		xexpr ')' 
1472		{ $<u.for_stmt>$ = new_for_stmt(pr, $1.location, $3, $6, $9, NULL);
1473		  push_loop(CAST(statement, $<u.for_stmt>$)); }
1474		labeled_stmt
1475		{ $$ = CAST(statement, $<u.for_stmt>11);
1476		  $<u.for_stmt>11->stmt = $12; 
1477		  pop_loop(); }
1478	| SWITCH '(' expr ')'
1479	        { stmt_count++; check_switch($3); 
1480		  $<u.cstmt>$ = CAST(conditional_stmt,
1481			           new_switch_stmt(pr, $1.location, $3, NULL)); 
1482		  push_loop(CAST(statement, $<u.cstmt>$)); } 
1483	  labeled_stmt
1484		{ $$ = CAST(statement, $<u.cstmt>5); 
1485		  $<u.cstmt>5->stmt = $6;
1486		  pop_loop(); }
1487	| BREAK ';'
1488		{ stmt_count++;
1489		  $$ = CAST(statement, new_break_stmt(pr, $1.location));
1490		  check_break($$);
1491		}
1492	| CONTINUE ';'
1493		{ stmt_count++;
1494		  $$ = CAST(statement, new_continue_stmt(pr, $1.location));
1495		  check_continue($$);
1496		}
1497	| RETURN ';'
1498		{ stmt_count++;
1499		  $$ = CAST(statement, new_return_stmt(pr, $1.location, NULL)); 
1500		  check_void_return(); }
1501	| RETURN expr ';'
1502		{ stmt_count++;
1503		  $$ = CAST(statement, new_return_stmt(pr, $1.location, $2)); 
1504		  check_return($2); }
1505	| ASM_KEYWORD maybe_type_qual '(' expr ')' ';'
1506		{ stmt_count++;
1507		  $$ = CAST(statement, new_asm_stmt(pr, $1.location, $4, NULL,
1508					       NULL, NULL, $2)); }
1509	/* This is the case with just output operands.  */
1510	| ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';'
1511		{ stmt_count++;
1512		  $$ = CAST(statement, new_asm_stmt(pr, $1.location, $4, $6, NULL,
1513					       NULL, $2)); }
1514	/* This is the case with input operands as well.  */
1515	| ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':' asm_operands ')' ';'
1516		{ stmt_count++;
1517		  $$ = CAST(statement, new_asm_stmt(pr, $1.location, $4, $6, $8, NULL, $2)); }
1518	/* This is the case with clobbered registers as well.  */
1519	| ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
1520  	  asm_operands ':' asm_clobbers ')' ';'
1521		{ stmt_count++;
1522		  $$ = CAST(statement, new_asm_stmt(pr, $1.location, $4, $6, $8, $10, $2)); }
1523	| GOTO id_label ';'
1524		{ stmt_count++;
1525		  $$ = CAST(statement, new_goto_stmt(pr, $1.location, $2));
1526		  use_label($2);
1527		}
1528	| GOTO '*' expr ';'
1529		{ if (pedantic)
1530		    pedwarn("ANSI C forbids `goto *expr;'");
1531		  stmt_count++;
1532		  $$ = CAST(statement, new_computed_goto_stmt(pr, $1.location, $3)); 
1533		  check_computed_goto($3); }
1534	| ';' { $$ = CAST(statement, new_empty_stmt(pr, $1.location)); }
1535	;
1536
1537/* Any kind of label, including jump labels and case labels.
1538   ANSI C accepts labels only before statements, but we allow them
1539   also at the end of a compound statement.  */
1540
1541label:	  CASE expr_no_commas ':'
1542		{ $$ = CAST(label, new_case_label(pr, $1.location, $2, NULL)); 
1543		  check_case($$); }
1544	| CASE expr_no_commas ELLIPSIS expr_no_commas ':'
1545		{ $$ = CAST(label, new_case_label(pr, $1.location, $2, $4)); 
1546		  check_case($$); }
1547	| DEFAULT ':'
1548		{ $$ = CAST(label, new_default_label(pr, $1.location…

Large files files are truncated, but you can click here to view the full file