PageRenderTime 83ms CodeModel.GetById 39ms app.highlight 24ms RepoModel.GetById 2ms app.codeStats 1ms

/src/c-parse.y

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

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