Home | History | Annotate | Line # | Download | only in lint1
cgram.y revision 1.54
      1 %{
      2 /* $NetBSD: cgram.y,v 1.54 2012/03/27 19:24:03 christos Exp $ */
      3 
      4 /*
      5  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
      6  * Copyright (c) 1994, 1995 Jochen Pohl
      7  * All Rights Reserved.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *      This product includes software developed by Jochen Pohl for
     20  *	The NetBSD Project.
     21  * 4. The name of the author may not be used to endorse or promote products
     22  *    derived from this software without specific prior written permission.
     23  *
     24  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     25  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     26  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     27  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     29  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     33  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     34  */
     35 
     36 #include <sys/cdefs.h>
     37 #if defined(__RCSID) && !defined(lint)
     38 __RCSID("$NetBSD: cgram.y,v 1.54 2012/03/27 19:24:03 christos Exp $");
     39 #endif
     40 
     41 #include <stdlib.h>
     42 #include <string.h>
     43 #include <limits.h>
     44 
     45 #include "lint1.h"
     46 
     47 extern char *yytext;
     48 /*
     49  * Contains the level of current declaration. 0 is extern.
     50  * Used for symbol table entries.
     51  */
     52 int	blklev;
     53 
     54 /*
     55  * level for memory allocation. Normaly the same as blklev.
     56  * An exception is the declaration of arguments in prototypes. Memory
     57  * for these can't be freed after the declaration, but symbols must
     58  * be removed from the symbol table after the declaration.
     59  */
     60 int	mblklev;
     61 
     62 /*
     63  * Save the no-warns state and restore it to avoid the problem where
     64  * if (expr) { stmt } / * NOLINT * / stmt;
     65  */
     66 static int onowarn = -1;
     67 
     68 static	int	toicon(tnode_t *, int);
     69 static	void	idecl(sym_t *, int, sbuf_t *);
     70 static	void	ignuptorp(void);
     71 
     72 #ifdef DEBUG
     73 static inline void CLRWFLGS(const char *file, size_t line);
     74 static inline void CLRWFLGS(const char *file, size_t line)
     75 {
     76 	printf("%s, %d: clear flags %s %zu\n", curr_pos.p_file,
     77 	    curr_pos.p_line, file, line);
     78 	clrwflgs();
     79 	onowarn = -1;
     80 }
     81 
     82 static inline void SAVE(const char *file, size_t line);
     83 static inline void SAVE(const char *file, size_t line)
     84 {
     85 	if (onowarn != -1)
     86 		abort();
     87 	printf("%s, %d: save flags %s %zu = %d\n", curr_pos.p_file,
     88 	    curr_pos.p_line, file, line, nowarn);
     89 	onowarn = nowarn;
     90 }
     91 
     92 static inline void RESTORE(const char *file, size_t line);
     93 static inline void RESTORE(const char *file, size_t line)
     94 {
     95 	if (onowarn != -1) {
     96 		nowarn = onowarn;
     97 		printf("%s, %d: restore flags %s %zu = %d\n", curr_pos.p_file,
     98 		    curr_pos.p_line, file, line, nowarn);
     99 		onowarn = -1;
    100 	} else
    101 		CLRWFLGS(file, line);
    102 }
    103 #else
    104 #define CLRWFLGS(f, l) clrwflgs(), onowarn = -1
    105 #define SAVE(f, l)	onowarn = nowarn
    106 #define RESTORE(f, l) (void)(onowarn == -1 ? (clrwflgs(), 0) : (nowarn = onowarn))
    107 #endif
    108 %}
    109 
    110 %expect 5
    111 
    112 %union {
    113 	int	y_int;
    114 	val_t	*y_val;
    115 	sbuf_t	*y_sb;
    116 	sym_t	*y_sym;
    117 	op_t	y_op;
    118 	scl_t	y_scl;
    119 	tspec_t	y_tspec;
    120 	tqual_t	y_tqual;
    121 	type_t	*y_type;
    122 	tnode_t	*y_tnode;
    123 	range_t	y_range;
    124 	strg_t	*y_strg;
    125 	pqinf_t	*y_pqinf;
    126 };
    127 
    128 %token			T_LBRACE T_RBRACE T_LBRACK T_RBRACK T_LPARN T_RPARN
    129 %token	<y_op>		T_STROP
    130 %token	<y_op>		T_UNOP
    131 %token	<y_op>		T_INCDEC
    132 %token			T_SIZEOF
    133 %token			T_ALIGNOF
    134 %token	<y_op>		T_MULT
    135 %token	<y_op>		T_DIVOP
    136 %token	<y_op>		T_ADDOP
    137 %token	<y_op>		T_SHFTOP
    138 %token	<y_op>		T_RELOP
    139 %token	<y_op>		T_EQOP
    140 %token	<y_op>		T_AND
    141 %token	<y_op>		T_XOR
    142 %token	<y_op>		T_OR
    143 %token	<y_op>		T_LOGAND
    144 %token	<y_op>		T_LOGOR
    145 %token			T_QUEST
    146 %token			T_COLON
    147 %token	<y_op>		T_ASSIGN
    148 %token	<y_op>		T_OPASS
    149 %token			T_COMMA
    150 %token			T_SEMI
    151 %token			T_ELLIPSE
    152 %token			T_REAL
    153 %token			T_IMAG
    154 
    155 /* storage classes (extern, static, auto, register and typedef) */
    156 %token	<y_scl>		T_SCLASS
    157 
    158 /* types (char, int, short, long, unsigned, signed, float, double, void) */
    159 %token	<y_tspec>	T_TYPE
    160 
    161 /* qualifiers (const, volatile) */
    162 %token	<y_tqual>	T_QUAL
    163 
    164 /* struct or union */
    165 %token	<y_tspec>	T_SOU
    166 
    167 /* enum */
    168 %token			T_ENUM
    169 
    170 /* remaining keywords */
    171 %token			T_CASE
    172 %token			T_DEFAULT
    173 %token			T_IF
    174 %token			T_ELSE
    175 %token			T_SWITCH
    176 %token			T_DO
    177 %token			T_WHILE
    178 %token			T_FOR
    179 %token			T_GOTO
    180 %token			T_CONTINUE
    181 %token			T_BREAK
    182 %token			T_RETURN
    183 %token			T_ASM
    184 %token			T_SYMBOLRENAME
    185 %token			T_PACKED
    186 /* Type Attributes */
    187 %token <y_type>		T_ATTRIBUTE
    188 %token <y_type>		T_AT_ALIGNED
    189 %token <y_type>		T_AT_DEPRECATED
    190 %token <y_type>		T_AT_MAY_ALIAS
    191 %token <y_type>		T_AT_PACKED
    192 %token <y_type>		T_AT_TUINION
    193 %token <y_type>		T_AT_TUNION
    194 %token <y_type>		T_AT_UNUSED
    195 
    196 
    197 
    198 %left	T_COMMA
    199 %right	T_ASSIGN T_OPASS
    200 %right	T_QUEST T_COLON
    201 %left	T_LOGOR
    202 %left	T_LOGAND
    203 %left	T_OR
    204 %left	T_XOR
    205 %left	T_AND
    206 %left	T_EQOP
    207 %left	T_RELOP
    208 %left	T_SHFTOP
    209 %left	T_ADDOP
    210 %left	T_MULT T_DIVOP
    211 %right	T_UNOP T_INCDEC T_SIZEOF T_ALIGNOF T_REAL T_IMAG
    212 %left	T_LPARN T_LBRACK T_STROP
    213 
    214 %token	<y_sb>		T_NAME
    215 %token	<y_sb>		T_TYPENAME
    216 %token	<y_val>		T_CON
    217 %token	<y_strg>	T_STRING
    218 
    219 %type	<y_sym>		func_decl
    220 %type	<y_sym>		notype_decl
    221 %type	<y_sym>		type_decl
    222 %type	<y_type>	typespec
    223 %type	<y_type>	clrtyp_typespec
    224 %type	<y_type>	notype_typespec
    225 %type	<y_type>	struct_spec
    226 %type	<y_type>	enum_spec
    227 %type	<y_type>	type_attribute
    228 %type	<y_type>	type_attribute_spec
    229 %type	<y_sym>		struct_tag
    230 %type	<y_sym>		enum_tag
    231 %type	<y_tspec>	struct
    232 %type	<y_sym>		struct_declaration
    233 %type	<y_sb>		identifier
    234 %type	<y_sym>		member_declaration_list_with_rbrace
    235 %type	<y_sym>		member_declaration_list
    236 %type	<y_sym>		member_declaration
    237 %type	<y_sym>		notype_member_decls
    238 %type	<y_sym>		type_member_decls
    239 %type	<y_sym>		notype_member_decl
    240 %type	<y_sym>		type_member_decl
    241 %type	<y_tnode>	constant
    242 %type	<y_sym>		enum_declaration
    243 %type	<y_sym>		enums_with_opt_comma
    244 %type	<y_sym>		enums
    245 %type	<y_sym>		enumerator
    246 %type	<y_sym>		ename
    247 %type	<y_sym>		notype_direct_decl
    248 %type	<y_sym>		type_direct_decl
    249 %type	<y_pqinf>	pointer
    250 %type	<y_pqinf>	asterisk
    251 %type	<y_sym>		param_decl
    252 %type	<y_sym>		param_list
    253 %type	<y_sym>		abs_decl_param_list
    254 %type	<y_sym>		direct_param_decl
    255 %type	<y_sym>		notype_param_decl
    256 %type	<y_sym>		direct_notype_param_decl
    257 %type	<y_pqinf>	type_qualifier_list
    258 %type	<y_pqinf>	type_qualifier
    259 %type	<y_sym>		identifier_list
    260 %type	<y_sym>		abs_decl
    261 %type	<y_sym>		direct_abs_decl
    262 %type	<y_sym>		vararg_parameter_type_list
    263 %type	<y_sym>		parameter_type_list
    264 %type	<y_sym>		parameter_declaration
    265 %type	<y_tnode>	expr
    266 %type	<y_tnode>	expr_stmnt_val
    267 %type	<y_tnode>	expr_stmnt_list
    268 %type	<y_tnode>	term
    269 %type	<y_tnode>	func_arg_list
    270 %type	<y_op>		point_or_arrow
    271 %type	<y_type>	type_name
    272 %type	<y_sym>		abstract_declaration
    273 %type	<y_tnode>	do_while_expr
    274 %type	<y_tnode>	opt_expr
    275 %type	<y_strg>	string
    276 %type	<y_strg>	string2
    277 %type	<y_sb>		opt_asm_or_symbolrename
    278 %type	<y_range>	range
    279 %type	<y_range>	lorange
    280 
    281 
    282 %%
    283 
    284 program:
    285 	  /* empty */ {
    286 		if (sflag) {
    287 			/* empty translation unit */
    288 			error(272);
    289 		} else if (!tflag) {
    290 			/* empty translation unit */
    291 			warning(272);
    292 		}
    293 	  }
    294 	| translation_unit
    295 	;
    296 
    297 translation_unit:
    298 	  ext_decl
    299 	| translation_unit ext_decl
    300 	;
    301 
    302 ext_decl:
    303 	  asm_stmnt
    304 	| func_def {
    305 		glclup(0);
    306 		CLRWFLGS(__FILE__, __LINE__);
    307 	  }
    308 	| data_def {
    309 		glclup(0);
    310 		CLRWFLGS(__FILE__, __LINE__);
    311 	  }
    312 	;
    313 
    314 data_def:
    315 	  T_SEMI {
    316 		if (sflag) {
    317 			/* syntax error: empty declaration */
    318 			error(0);
    319 		} else if (!tflag) {
    320 			/* syntax error: empty declaration */
    321 			warning(0);
    322 		}
    323 	  }
    324 	| clrtyp deftyp notype_init_decls T_SEMI {
    325 		if (sflag) {
    326 			/* old style declaration; add "int" */
    327 			error(1);
    328 		} else if (!tflag) {
    329 			/* old style declaration; add "int" */
    330 			warning(1);
    331 		}
    332 	  }
    333 	| declmods deftyp T_SEMI {
    334 		if (dcs->d_scl == TYPEDEF) {
    335 			/* typedef declares no type name */
    336 			warning(72);
    337 		} else {
    338 			/* empty declaration */
    339 			warning(2);
    340 		}
    341 	  }
    342 	| declmods deftyp notype_init_decls T_SEMI
    343 	| declspecs deftyp T_SEMI {
    344 		if (dcs->d_scl == TYPEDEF) {
    345 			/* typedef declares no type name */
    346 			warning(72);
    347 		} else if (!dcs->d_nedecl) {
    348 			/* empty declaration */
    349 			warning(2);
    350 		}
    351 	  }
    352 	| declspecs deftyp type_init_decls T_SEMI
    353 	| error T_SEMI {
    354 		globclup();
    355 	  }
    356 	| error T_RBRACE {
    357 		globclup();
    358 	  }
    359 	;
    360 
    361 func_def:
    362 	  func_decl {
    363 		if ($1->s_type->t_tspec != FUNC) {
    364 			/* syntax error */
    365 			error(249, yytext);
    366 			YYERROR;
    367 		}
    368 		if ($1->s_type->t_typedef) {
    369 			/* ()-less function definition */
    370 			error(64);
    371 			YYERROR;
    372 		}
    373 		funcdef($1);
    374 		blklev++;
    375 		pushdecl(ARG);
    376 		if (nowarn)
    377 			$1->s_used = 1;
    378 	  } opt_arg_declaration_list {
    379 		popdecl();
    380 		blklev--;
    381 		cluparg();
    382 		pushctrl(0);
    383 	  } comp_stmnt {
    384 		funcend();
    385 		popctrl(0);
    386 	  }
    387 	;
    388 
    389 func_decl:
    390 	  clrtyp deftyp notype_decl {
    391 		$$ = $3;
    392 	  }
    393 	| declmods deftyp notype_decl {
    394 		$$ = $3;
    395 	  }
    396 	| declspecs deftyp type_decl {
    397 		$$ = $3;
    398 	  }
    399 	;
    400 
    401 opt_arg_declaration_list:
    402 	  /* empty */
    403 	| arg_declaration_list
    404 	;
    405 
    406 arg_declaration_list:
    407 	  arg_declaration
    408 	| arg_declaration_list arg_declaration
    409 	/* XXX or better "arg_declaration error" ? */
    410 	| error
    411 	;
    412 
    413 /*
    414  * "arg_declaration" is separated from "declaration" because it
    415  * needs other error handling.
    416  */
    417 
    418 arg_declaration:
    419 	  declmods deftyp T_SEMI {
    420 		/* empty declaration */
    421 		warning(2);
    422 	  }
    423 	| declmods deftyp notype_init_decls T_SEMI
    424 	| declspecs deftyp T_SEMI {
    425 		if (!dcs->d_nedecl) {
    426 			/* empty declaration */
    427 			warning(2);
    428 		} else {
    429 			tspec_t	ts = dcs->d_type->t_tspec;
    430 			/* %s declared in argument declaration list */
    431 			warning(3, ts == STRUCT ? "struct" :
    432 				(ts == UNION ? "union" : "enum"));
    433 		}
    434 	  }
    435 	| declspecs deftyp type_init_decls T_SEMI {
    436 		if (dcs->d_nedecl) {
    437 			tspec_t	ts = dcs->d_type->t_tspec;
    438 			/* %s declared in argument declaration list */
    439 			warning(3, ts == STRUCT ? "struct" :
    440 				(ts == UNION ? "union" : "enum"));
    441 		}
    442 	  }
    443 	| declmods error
    444 	| declspecs error
    445 	;
    446 
    447 declaration:
    448 	  declmods deftyp T_SEMI {
    449 		if (dcs->d_scl == TYPEDEF) {
    450 			/* typedef declares no type name */
    451 			warning(72);
    452 		} else {
    453 			/* empty declaration */
    454 			warning(2);
    455 		}
    456 	  }
    457 	| declmods deftyp notype_init_decls T_SEMI
    458 	| declspecs deftyp T_SEMI {
    459 		if (dcs->d_scl == TYPEDEF) {
    460 			/* typedef declares no type name */
    461 			warning(72);
    462 		} else if (!dcs->d_nedecl) {
    463 			/* empty declaration */
    464 			warning(2);
    465 		}
    466 	  }
    467 	| declspecs deftyp type_init_decls T_SEMI
    468 	| error T_SEMI
    469 	;
    470 
    471 type_attribute_spec:
    472 	  T_AT_DEPRECATED
    473 	| T_AT_ALIGNED T_LPARN constant T_RPARN
    474 	| T_AT_MAY_ALIAS
    475 	| T_AT_PACKED {
    476 		addpacked();
    477 	}
    478 	| T_AT_TUNION
    479 	| T_AT_UNUSED
    480 	;
    481 
    482 type_attribute:
    483 	  T_ATTRIBUTE T_LPARN T_LPARN type_attribute_spec T_RPARN T_RPARN
    484 	| T_PACKED {
    485 		addpacked();
    486 	}
    487 	;
    488 
    489 clrtyp:
    490 	  {
    491 		clrtyp();
    492 	  }
    493 	;
    494 
    495 deftyp:
    496 	  /* empty */ {
    497 		deftyp();
    498 	  }
    499 	;
    500 
    501 declspecs:
    502 	  clrtyp_typespec {
    503 		addtype($1);
    504 	  }
    505 	| declmods typespec {
    506 		addtype($2);
    507 	  }
    508 	| declspecs type_attribute
    509 	| declspecs declmod
    510 	| declspecs notype_typespec {
    511 		addtype($2);
    512 	  }
    513 	;
    514 
    515 declmods:
    516 	  clrtyp T_QUAL {
    517 		addqual($2);
    518 	  }
    519 	| clrtyp T_SCLASS {
    520 		addscl($2);
    521 	  }
    522 	| declmods declmod
    523 	;
    524 
    525 declmod:
    526 	  T_QUAL {
    527 		addqual($1);
    528 	  }
    529 	| T_SCLASS {
    530 		addscl($1);
    531 	  }
    532 	;
    533 
    534 clrtyp_typespec:
    535 	  clrtyp notype_typespec {
    536 		$$ = $2;
    537 	  }
    538 	| T_TYPENAME clrtyp {
    539 		$$ = getsym($1)->s_type;
    540 	  }
    541 	;
    542 
    543 typespec:
    544 	  notype_typespec {
    545 		$$ = $1;
    546 	  }
    547 	| T_TYPENAME {
    548 		$$ = getsym($1)->s_type;
    549 	  }
    550 	;
    551 
    552 notype_typespec:
    553 	  T_TYPE {
    554 		$$ = gettyp($1);
    555 	  }
    556 	| struct_spec {
    557 		popdecl();
    558 		$$ = $1;
    559 	  }
    560 	| enum_spec {
    561 		popdecl();
    562 		$$ = $1;
    563 	  }
    564 	;
    565 
    566 struct_spec:
    567 	  struct struct_tag {
    568 		/*
    569 		 * STDC requires that "struct a;" always introduces
    570 		 * a new tag if "a" is not declared at current level
    571 		 *
    572 		 * yychar is valid because otherwise the parser would
    573 		 * not been able to deceide if he must shift or reduce
    574 		 */
    575 		$$ = mktag($2, $1, 0, yychar == T_SEMI);
    576 	  }
    577 	| struct struct_tag {
    578 		dcs->d_tagtyp = mktag($2, $1, 1, 0);
    579 	  } struct_declaration {
    580 		$$ = compltag(dcs->d_tagtyp, $4);
    581 	  }
    582 	| struct {
    583 		dcs->d_tagtyp = mktag(NULL, $1, 1, 0);
    584 	  } struct_declaration {
    585 		$$ = compltag(dcs->d_tagtyp, $3);
    586 	  }
    587 	| struct error {
    588 		symtyp = FVFT;
    589 		$$ = gettyp(INT);
    590 	  }
    591 	;
    592 
    593 struct:
    594 	  struct type_attribute
    595 	| T_SOU {
    596 		symtyp = FTAG;
    597 		pushdecl($1 == STRUCT ? MOS : MOU);
    598 		dcs->d_offset = 0;
    599 		dcs->d_stralign = CHAR_BIT;
    600 		$$ = $1;
    601 	  }
    602 	;
    603 
    604 struct_tag:
    605 	  identifier {
    606 		$$ = getsym($1);
    607 	  }
    608 	;
    609 
    610 struct_declaration:
    611 	  struct_decl_lbrace member_declaration_list_with_rbrace {
    612 		$$ = $2;
    613 	  }
    614 	;
    615 
    616 struct_decl_lbrace:
    617 	  T_LBRACE {
    618 		symtyp = FVFT;
    619 	  }
    620 	;
    621 
    622 member_declaration_list_with_rbrace:
    623 	  member_declaration_list T_SEMI T_RBRACE {
    624 		$$ = $1;
    625 	  }
    626 	| member_declaration_list T_RBRACE {
    627 		if (sflag) {
    628 			/* syntax req. ";" after last struct/union member */
    629 			error(66);
    630 		} else {
    631 			/* syntax req. ";" after last struct/union member */
    632 			warning(66);
    633 		}
    634 		$$ = $1;
    635 	  }
    636 	| T_RBRACE {
    637 		$$ = NULL;
    638 	  }
    639 	;
    640 
    641 member_declaration_list:
    642 	  member_declaration {
    643 		$$ = $1;
    644 	  }
    645 	| member_declaration_list T_SEMI member_declaration {
    646 		$$ = lnklst($1, $3);
    647 	  }
    648 	;
    649 
    650 member_declaration:
    651 	  noclass_declmods deftyp {
    652 		/* too late, i know, but getsym() compensates it */
    653 		symtyp = FMOS;
    654 	  } notype_member_decls {
    655 		symtyp = FVFT;
    656 		$$ = $4;
    657 	  }
    658 	| noclass_declspecs deftyp {
    659 		symtyp = FMOS;
    660 	  } type_member_decls {
    661 		symtyp = FVFT;
    662 		$$ = $4;
    663 	  }
    664 	| noclass_declmods deftyp {
    665 		/* struct or union member must be named */
    666 		warning(49);
    667 		$$ = NULL;
    668 	  }
    669 	| noclass_declspecs deftyp {
    670 		/* struct or union member must be named */
    671 		warning(49);
    672 		$$ = NULL;
    673 	  }
    674 	| error {
    675 		symtyp = FVFT;
    676 		$$ = NULL;
    677 	  }
    678 	;
    679 
    680 noclass_declspecs:
    681 	  clrtyp_typespec {
    682 		addtype($1);
    683 	  }
    684 	| noclass_declmods typespec {
    685 		addtype($2);
    686 	  }
    687 	| noclass_declspecs T_QUAL {
    688 		addqual($2);
    689 	  }
    690 	| noclass_declspecs notype_typespec {
    691 		addtype($2);
    692 	  }
    693 	| noclass_declspecs type_attribute
    694 	;
    695 
    696 noclass_declmods:
    697 	  clrtyp T_QUAL {
    698 		addqual($2);
    699 	  }
    700 	| noclass_declmods T_QUAL {
    701 		addqual($2);
    702 	  }
    703 	;
    704 
    705 notype_member_decls:
    706 	  notype_member_decl {
    707 		$$ = decl1str($1);
    708 	  }
    709 	| notype_member_decls {
    710 		symtyp = FMOS;
    711 	  } T_COMMA type_member_decl {
    712 		$$ = lnklst($1, decl1str($4));
    713 	  }
    714 	;
    715 
    716 type_member_decls:
    717 	  type_member_decl {
    718 		$$ = decl1str($1);
    719 	  }
    720 	| type_member_decls {
    721 		symtyp = FMOS;
    722 	  } T_COMMA type_member_decl {
    723 		$$ = lnklst($1, decl1str($4));
    724 	  }
    725 	;
    726 
    727 notype_member_decl:
    728 	  notype_decl {
    729 		$$ = $1;
    730 	  }
    731 	| notype_decl T_COLON constant {
    732 		$$ = bitfield($1, toicon($3, 1));
    733 	  }
    734 	| {
    735 		symtyp = FVFT;
    736 	  } T_COLON constant {
    737 		$$ = bitfield(NULL, toicon($3, 1));
    738 	  }
    739 	;
    740 
    741 type_member_decl:
    742 	  type_decl {
    743 		$$ = $1;
    744 	  }
    745 	| type_decl T_COLON constant {
    746 		$$ = bitfield($1, toicon($3, 1));
    747 	  }
    748 	| {
    749 		symtyp = FVFT;
    750 	  } T_COLON constant {
    751 		$$ = bitfield(NULL, toicon($3, 1));
    752 	  }
    753 	;
    754 
    755 enum_spec:
    756 	  enum enum_tag {
    757 		$$ = mktag($2, ENUM, 0, 0);
    758 	  }
    759 	| enum enum_tag {
    760 		dcs->d_tagtyp = mktag($2, ENUM, 1, 0);
    761 	  } enum_declaration {
    762 		$$ = compltag(dcs->d_tagtyp, $4);
    763 	  }
    764 	| enum {
    765 		dcs->d_tagtyp = mktag(NULL, ENUM, 1, 0);
    766 	  } enum_declaration {
    767 		$$ = compltag(dcs->d_tagtyp, $3);
    768 	  }
    769 	| enum error {
    770 		symtyp = FVFT;
    771 		$$ = gettyp(INT);
    772 	  }
    773 	;
    774 
    775 enum:
    776 	  T_ENUM {
    777 		symtyp = FTAG;
    778 		pushdecl(ENUMCON);
    779 	  }
    780 	;
    781 
    782 enum_tag:
    783 	  identifier {
    784 		$$ = getsym($1);
    785 	  }
    786 	;
    787 
    788 enum_declaration:
    789 	  enum_decl_lbrace enums_with_opt_comma T_RBRACE {
    790 		$$ = $2;
    791 	  }
    792 	;
    793 
    794 enum_decl_lbrace:
    795 	  T_LBRACE {
    796 		symtyp = FVFT;
    797 		enumval = 0;
    798 	  }
    799 	;
    800 
    801 enums_with_opt_comma:
    802 	  enums {
    803 		$$ = $1;
    804 	  }
    805 	| enums T_COMMA {
    806 		if (sflag) {
    807 			/* trailing "," prohibited in enum declaration */
    808 			error(54);
    809 		} else {
    810 			/* trailing "," prohibited in enum declaration */
    811 			c99ism(54);
    812 		}
    813 		$$ = $1;
    814 	  }
    815 	;
    816 
    817 enums:
    818 	  enumerator {
    819 		$$ = $1;
    820 	  }
    821 	| enums T_COMMA enumerator {
    822 		$$ = lnklst($1, $3);
    823 	  }
    824 	| error {
    825 		$$ = NULL;
    826 	  }
    827 	;
    828 
    829 enumerator:
    830 	  ename {
    831 		$$ = ename($1, enumval, 1);
    832 	  }
    833 	| ename T_ASSIGN constant {
    834 		$$ = ename($1, toicon($3, 1), 0);
    835 	  }
    836 	;
    837 
    838 ename:
    839 	  identifier {
    840 		$$ = getsym($1);
    841 	  }
    842 	;
    843 
    844 
    845 notype_init_decls:
    846 	  notype_init_decl
    847 	| notype_init_decls T_COMMA type_init_decl
    848 	;
    849 
    850 type_init_decls:
    851 	  type_init_decl
    852 	| type_init_decls T_COMMA type_init_decl
    853 	;
    854 
    855 notype_init_decl:
    856 	  notype_decl opt_asm_or_symbolrename {
    857 		idecl($1, 0, $2);
    858 		chksz($1);
    859 	  }
    860 	| notype_decl opt_asm_or_symbolrename {
    861 		idecl($1, 1, $2);
    862 	  } T_ASSIGN initializer {
    863 		chksz($1);
    864 	  }
    865 	;
    866 
    867 type_init_decl:
    868 	  type_decl opt_asm_or_symbolrename {
    869 		idecl($1, 0, $2);
    870 		chksz($1);
    871 	  }
    872 	| type_decl opt_asm_or_symbolrename {
    873 		idecl($1, 1, $2);
    874 	  } T_ASSIGN initializer {
    875 		chksz($1);
    876 	  }
    877 	;
    878 
    879 notype_decl:
    880 	  notype_direct_decl {
    881 		$$ = $1;
    882 	  }
    883 	| pointer notype_direct_decl {
    884 		$$ = addptr($2, $1);
    885 	  }
    886 	;
    887 
    888 notype_direct_decl:
    889 	  T_NAME {
    890 		$$ = dname(getsym($1));
    891 	  }
    892 	| T_LPARN type_decl T_RPARN {
    893 		$$ = $2;
    894 	  }
    895 	| notype_direct_decl T_LBRACK T_RBRACK {
    896 		$$ = addarray($1, 0, 0);
    897 	  }
    898 	| notype_direct_decl T_LBRACK constant T_RBRACK {
    899 		$$ = addarray($1, 1, toicon($3, 0));
    900 	  }
    901 	| notype_direct_decl param_list {
    902 		$$ = addfunc($1, $2);
    903 		popdecl();
    904 		blklev--;
    905 	  }
    906 	| notype_direct_decl type_attribute
    907 	;
    908 
    909 type_decl:
    910 	  type_direct_decl {
    911 		$$ = $1;
    912 	  }
    913 	| pointer type_direct_decl {
    914 		$$ = addptr($2, $1);
    915 	  }
    916 	;
    917 
    918 type_direct_decl:
    919 	  identifier {
    920 		$$ = dname(getsym($1));
    921 	  }
    922 	| T_LPARN type_decl T_RPARN {
    923 		$$ = $2;
    924 	  }
    925 	| type_direct_decl T_LBRACK T_RBRACK {
    926 		$$ = addarray($1, 0, 0);
    927 	  }
    928 	| type_direct_decl T_LBRACK constant T_RBRACK {
    929 		$$ = addarray($1, 1, toicon($3, 0));
    930 	  }
    931 	| type_direct_decl param_list {
    932 		$$ = addfunc($1, $2);
    933 		popdecl();
    934 		blklev--;
    935 	  }
    936 	| type_direct_decl type_attribute
    937 	;
    938 
    939 /*
    940  * param_decl and notype_param_decl exist to avoid a conflict in
    941  * argument lists. A typename enclosed in parens should always be
    942  * treated as a typename, not an argument.
    943  * "typedef int a; f(int (a));" is  "typedef int a; f(int foo(a));"
    944  *				not "typedef int a; f(int a);"
    945  */
    946 param_decl:
    947 	  direct_param_decl {
    948 		$$ = $1;
    949 	  }
    950 	| pointer direct_param_decl {
    951 		$$ = addptr($2, $1);
    952 	  }
    953 	;
    954 
    955 direct_param_decl:
    956 	  identifier {
    957 		$$ = dname(getsym($1));
    958 	  }
    959 	| T_LPARN notype_param_decl T_RPARN {
    960 		$$ = $2;
    961 	  }
    962 	| direct_param_decl T_LBRACK T_RBRACK {
    963 		$$ = addarray($1, 0, 0);
    964 	  }
    965 	| direct_param_decl T_LBRACK constant T_RBRACK {
    966 		$$ = addarray($1, 1, toicon($3, 0));
    967 	  }
    968 	| direct_param_decl param_list {
    969 		$$ = addfunc($1, $2);
    970 		popdecl();
    971 		blklev--;
    972 	  }
    973 	;
    974 
    975 notype_param_decl:
    976 	  direct_notype_param_decl {
    977 		$$ = $1;
    978 	  }
    979 	| pointer direct_notype_param_decl {
    980 		$$ = addptr($2, $1);
    981 	  }
    982 	;
    983 
    984 direct_notype_param_decl:
    985 	  T_NAME {
    986 		$$ = dname(getsym($1));
    987 	  }
    988 	| T_LPARN notype_param_decl T_RPARN {
    989 		$$ = $2;
    990 	  }
    991 	| direct_notype_param_decl T_LBRACK T_RBRACK {
    992 		$$ = addarray($1, 0, 0);
    993 	  }
    994 	| direct_notype_param_decl T_LBRACK constant T_RBRACK {
    995 		$$ = addarray($1, 1, toicon($3, 0));
    996 	  }
    997 	| direct_notype_param_decl param_list {
    998 		$$ = addfunc($1, $2);
    999 		popdecl();
   1000 		blklev--;
   1001 	  }
   1002 	;
   1003 
   1004 pointer:
   1005 	  asterisk {
   1006 		$$ = $1;
   1007 	  }
   1008 	| asterisk type_qualifier_list {
   1009 		$$ = mergepq($1, $2);
   1010 	  }
   1011 	| asterisk pointer {
   1012 		$$ = mergepq($1, $2);
   1013 	  }
   1014 	| asterisk type_qualifier_list pointer {
   1015 		$$ = mergepq(mergepq($1, $2), $3);
   1016 	  }
   1017 	;
   1018 
   1019 asterisk:
   1020 	  T_MULT {
   1021 		$$ = xcalloc(1, sizeof (pqinf_t));
   1022 		$$->p_pcnt = 1;
   1023 	  }
   1024 	;
   1025 
   1026 type_qualifier_list:
   1027 	  type_qualifier {
   1028 		$$ = $1;
   1029 	  }
   1030 	| type_qualifier_list type_qualifier {
   1031 		$$ = mergepq($1, $2);
   1032 	  }
   1033 	;
   1034 
   1035 type_qualifier:
   1036 	  T_QUAL {
   1037 		$$ = xcalloc(1, sizeof (pqinf_t));
   1038 		if ($1 == CONST) {
   1039 			$$->p_const = 1;
   1040 		} else {
   1041 			$$->p_volatile = 1;
   1042 		}
   1043 	  }
   1044 	;
   1045 
   1046 param_list:
   1047 	  id_list_lparn identifier_list T_RPARN {
   1048 		$$ = $2;
   1049 	  }
   1050 	| abs_decl_param_list {
   1051 		$$ = $1;
   1052 	  }
   1053 	;
   1054 
   1055 id_list_lparn:
   1056 	  T_LPARN {
   1057 		blklev++;
   1058 		pushdecl(PARG);
   1059 	  }
   1060 	;
   1061 
   1062 identifier_list:
   1063 	  T_NAME {
   1064 		$$ = iname(getsym($1));
   1065 	  }
   1066 	| identifier_list T_COMMA T_NAME {
   1067 		$$ = lnklst($1, iname(getsym($3)));
   1068 	  }
   1069 	| identifier_list error {
   1070 		$$ = $1;
   1071 	  }
   1072 	;
   1073 
   1074 abs_decl_param_list:
   1075 	  abs_decl_lparn T_RPARN {
   1076 		$$ = NULL;
   1077 	  }
   1078 	| abs_decl_lparn vararg_parameter_type_list T_RPARN {
   1079 		dcs->d_proto = 1;
   1080 		$$ = $2;
   1081 	  }
   1082 	| abs_decl_lparn error T_RPARN {
   1083 		$$ = NULL;
   1084 	  }
   1085 	;
   1086 
   1087 abs_decl_lparn:
   1088 	  T_LPARN {
   1089 		blklev++;
   1090 		pushdecl(PARG);
   1091 	  }
   1092 	;
   1093 
   1094 vararg_parameter_type_list:
   1095 	  parameter_type_list {
   1096 		$$ = $1;
   1097 	  }
   1098 	| parameter_type_list T_COMMA T_ELLIPSE {
   1099 		dcs->d_vararg = 1;
   1100 		$$ = $1;
   1101 	  }
   1102 	| T_ELLIPSE {
   1103 		if (sflag) {
   1104 			/* ANSI C requires formal parameter before "..." */
   1105 			error(84);
   1106 		} else if (!tflag) {
   1107 			/* ANSI C requires formal parameter before "..." */
   1108 			warning(84);
   1109 		}
   1110 		dcs->d_vararg = 1;
   1111 		$$ = NULL;
   1112 	  }
   1113 	;
   1114 
   1115 parameter_type_list:
   1116 	  parameter_declaration {
   1117 		$$ = $1;
   1118 	  }
   1119 	| parameter_type_list T_COMMA parameter_declaration {
   1120 		$$ = lnklst($1, $3);
   1121 	  }
   1122 	;
   1123 
   1124 parameter_declaration:
   1125 	  declmods deftyp {
   1126 		$$ = decl1arg(aname(), 0);
   1127 	  }
   1128 	| declspecs deftyp {
   1129 		$$ = decl1arg(aname(), 0);
   1130 	  }
   1131 	| declmods deftyp notype_param_decl {
   1132 		$$ = decl1arg($3, 0);
   1133 	  }
   1134 	/*
   1135 	 * param_decl is needed because of following conflict:
   1136 	 * "typedef int a; f(int (a));" could be parsed as
   1137 	 * "function with argument a of type int", or
   1138 	 * "function with an abstract argument of type function".
   1139 	 * This grammar realizes the second case.
   1140 	 */
   1141 	| declspecs deftyp param_decl {
   1142 		$$ = decl1arg($3, 0);
   1143 	  }
   1144 	| declmods deftyp abs_decl {
   1145 		$$ = decl1arg($3, 0);
   1146 	  }
   1147 	| declspecs deftyp abs_decl {
   1148 		$$ = decl1arg($3, 0);
   1149 	  }
   1150 	;
   1151 
   1152 opt_asm_or_symbolrename:		/* expect only one */
   1153 	  /* empty */ {
   1154 		$$ = NULL;
   1155 	  }
   1156 	| T_ASM T_LPARN T_STRING T_RPARN {
   1157 		freeyyv(&$3, T_STRING);
   1158 		$$ = NULL;
   1159 	  }
   1160 	| T_SYMBOLRENAME T_LPARN T_NAME T_RPARN {
   1161 		$$ = $3;
   1162 	  }
   1163 	;
   1164 
   1165 initializer:
   1166 	  init_expr
   1167 	;
   1168 
   1169 init_expr:
   1170 	  expr				%prec T_COMMA {
   1171 		mkinit($1);
   1172 	  }
   1173 	| init_by_name init_expr	%prec T_COMMA
   1174 	| init_lbrace init_expr_list init_rbrace
   1175 	| init_lbrace init_expr_list T_COMMA init_rbrace
   1176 	| error
   1177 	;
   1178 
   1179 init_expr_list:
   1180 	  init_expr			%prec T_COMMA
   1181 	| init_expr_list T_COMMA init_expr
   1182 	;
   1183 
   1184 lorange:
   1185 	  constant T_ELLIPSE {
   1186 		$$.lo = toicon($1, 1);
   1187 	  }
   1188 	;
   1189 range:
   1190 	constant {
   1191 		$$.lo = toicon($1, 1);
   1192 		$$.hi = $$.lo + 1;
   1193 	  }
   1194 	| lorange constant {
   1195 		$$.lo = $1.lo;
   1196 		$$.hi = toicon($2, 1);
   1197 	  }
   1198 	;
   1199 
   1200 init_by_name:
   1201 	  T_LBRACK range T_RBRACK T_ASSIGN {
   1202 		if (!Sflag)
   1203 			warning(321);
   1204 	  }
   1205 	| point identifier T_ASSIGN {
   1206 		if (!Sflag)
   1207 			warning(313);
   1208 		memberpush($2);
   1209 	  }
   1210 	| identifier T_COLON {
   1211 		gnuism(315);
   1212 		memberpush($1);
   1213 	  }
   1214 	;
   1215 
   1216 init_lbrace:
   1217 	  T_LBRACE {
   1218 		initlbr();
   1219 	  }
   1220 	;
   1221 
   1222 init_rbrace:
   1223 	  T_RBRACE {
   1224 		initrbr();
   1225 	  }
   1226 	;
   1227 
   1228 type_name:
   1229 	  {
   1230 		pushdecl(ABSTRACT);
   1231 	  } abstract_declaration {
   1232 		popdecl();
   1233 		$$ = $2->s_type;
   1234 	  }
   1235 	;
   1236 
   1237 abstract_declaration:
   1238 	  noclass_declmods deftyp {
   1239 		$$ = decl1abs(aname());
   1240 	  }
   1241 	| noclass_declspecs deftyp {
   1242 		$$ = decl1abs(aname());
   1243 	  }
   1244 	| noclass_declmods deftyp abs_decl {
   1245 		$$ = decl1abs($3);
   1246 	  }
   1247 	| noclass_declspecs deftyp abs_decl {
   1248 		$$ = decl1abs($3);
   1249 	  }
   1250 	;
   1251 
   1252 abs_decl:
   1253 	  pointer {
   1254 		$$ = addptr(aname(), $1);
   1255 	  }
   1256 	| direct_abs_decl {
   1257 		$$ = $1;
   1258 	  }
   1259 	| pointer direct_abs_decl {
   1260 		$$ = addptr($2, $1);
   1261 	  }
   1262 	;
   1263 
   1264 direct_abs_decl:
   1265 	  T_LPARN abs_decl T_RPARN {
   1266 		$$ = $2;
   1267 	  }
   1268 	| T_LBRACK T_RBRACK {
   1269 		$$ = addarray(aname(), 0, 0);
   1270 	  }
   1271 	| T_LBRACK constant T_RBRACK {
   1272 		$$ = addarray(aname(), 1, toicon($2, 0));
   1273 	  }
   1274 	| direct_abs_decl T_LBRACK T_RBRACK {
   1275 		$$ = addarray($1, 0, 0);
   1276 	  }
   1277 	| direct_abs_decl T_LBRACK constant T_RBRACK {
   1278 		$$ = addarray($1, 1, toicon($3, 0));
   1279 	  }
   1280 	| abs_decl_param_list {
   1281 		$$ = addfunc(aname(), $1);
   1282 		popdecl();
   1283 		blklev--;
   1284 	  }
   1285 	| direct_abs_decl abs_decl_param_list {
   1286 		$$ = addfunc($1, $2);
   1287 		popdecl();
   1288 		blklev--;
   1289 	  }
   1290 	| direct_abs_decl type_attribute
   1291 	;
   1292 
   1293 non_expr_stmnt:
   1294 	  labeled_stmnt
   1295 	| comp_stmnt
   1296 	| selection_stmnt
   1297 	| iteration_stmnt
   1298 	| jump_stmnt {
   1299 		ftflg = 0;
   1300 	  }
   1301 	| asm_stmnt
   1302 
   1303 stmnt:
   1304 	  expr_stmnt
   1305 	| non_expr_stmnt
   1306 	;
   1307 
   1308 labeled_stmnt:
   1309 	  label stmnt
   1310 	;
   1311 
   1312 label:
   1313 	  T_NAME T_COLON {
   1314 		symtyp = FLAB;
   1315 		label(T_NAME, getsym($1), NULL);
   1316 	  }
   1317 	| T_CASE constant T_COLON {
   1318 		label(T_CASE, NULL, $2);
   1319 		ftflg = 1;
   1320 	}
   1321 	| T_CASE constant T_ELLIPSE constant T_COLON {
   1322 		/* XXX: We don't fill all cases */
   1323 		label(T_CASE, NULL, $2);
   1324 		ftflg = 1;
   1325 	}
   1326 	| T_DEFAULT T_COLON {
   1327 		label(T_DEFAULT, NULL, NULL);
   1328 		ftflg = 1;
   1329 	  }
   1330 	;
   1331 
   1332 stmnt_d_list:
   1333 	  stmnt_list
   1334 	| stmnt_d_list declaration_list stmnt_list {
   1335 		if (!Sflag)
   1336 			c99ism(327);
   1337 	}
   1338 	;
   1339 
   1340 comp_stmnt:
   1341 	  comp_stmnt_lbrace comp_stmnt_rbrace
   1342 	| comp_stmnt_lbrace stmnt_list comp_stmnt_rbrace
   1343 	| comp_stmnt_lbrace declaration_list comp_stmnt_rbrace
   1344 	| comp_stmnt_lbrace declaration_list stmnt_d_list comp_stmnt_rbrace
   1345 	;
   1346 
   1347 comp_stmnt_lbrace:
   1348 	  T_LBRACE {
   1349 		blklev++;
   1350 		mblklev++;
   1351 		pushdecl(AUTO);
   1352 	  }
   1353 	;
   1354 
   1355 comp_stmnt_rbrace:
   1356 	  T_RBRACE {
   1357 		popdecl();
   1358 		freeblk();
   1359 		mblklev--;
   1360 		blklev--;
   1361 		ftflg = 0;
   1362 	  }
   1363 	;
   1364 
   1365 stmnt_list:
   1366 	  stmnt
   1367 	| stmnt_list stmnt {
   1368 		RESTORE(__FILE__, __LINE__);
   1369 	  }
   1370 	| stmnt_list error T_SEMI
   1371 	;
   1372 
   1373 expr_stmnt:
   1374 	  expr T_SEMI {
   1375 		expr($1, 0, 0, 1);
   1376 		ftflg = 0;
   1377 	  }
   1378 	| T_SEMI {
   1379 		ftflg = 0;
   1380 	  }
   1381 	;
   1382 
   1383 /*
   1384  * The following two productions are used to implement
   1385  * ({ [[decl-list] stmt-list] }).
   1386  * XXX: This is not well tested.
   1387  */
   1388 expr_stmnt_val:
   1389 	  expr T_SEMI {
   1390 		/* XXX: We should really do that only on the last name */
   1391 		if ($1->tn_op == NAME)
   1392 			$1->tn_sym->s_used = 1;
   1393 		$$ = $1;
   1394 		expr($1, 0, 0, 0);
   1395 		ftflg = 0;
   1396 	  }
   1397 	| non_expr_stmnt {
   1398 		$$ = getnode();
   1399 		$$->tn_type = gettyp(VOID);
   1400 	}
   1401 	;
   1402 
   1403 expr_stmnt_list:
   1404 	  expr_stmnt_val
   1405 	| expr_stmnt_list expr_stmnt_val {
   1406 		$$ = $2;
   1407 	}
   1408 	;
   1409 
   1410 selection_stmnt:
   1411 	  if_without_else {
   1412 		SAVE(__FILE__, __LINE__);
   1413 		if2();
   1414 		if3(0);
   1415 	  }
   1416 	| if_without_else T_ELSE {
   1417 		SAVE(__FILE__, __LINE__);
   1418 		if2();
   1419 	  } stmnt {
   1420 		CLRWFLGS(__FILE__, __LINE__);
   1421 		if3(1);
   1422 	  }
   1423 	| if_without_else T_ELSE error {
   1424 		CLRWFLGS(__FILE__, __LINE__);
   1425 		if3(0);
   1426 	  }
   1427 	| switch_expr stmnt {
   1428 		CLRWFLGS(__FILE__, __LINE__);
   1429 		switch2();
   1430 	  }
   1431 	| switch_expr error {
   1432 		CLRWFLGS(__FILE__, __LINE__);
   1433 		switch2();
   1434 	  }
   1435 	;
   1436 
   1437 if_without_else:
   1438 	  if_expr stmnt
   1439 	| if_expr error
   1440 	;
   1441 
   1442 if_expr:
   1443 	  T_IF T_LPARN expr T_RPARN {
   1444 		if1($3);
   1445 		CLRWFLGS(__FILE__, __LINE__);
   1446 	  }
   1447 	;
   1448 
   1449 switch_expr:
   1450 	  T_SWITCH T_LPARN expr T_RPARN {
   1451 		switch1($3);
   1452 		CLRWFLGS(__FILE__, __LINE__);
   1453 	  }
   1454 	;
   1455 
   1456 do_stmnt:
   1457 	  do stmnt {
   1458 		CLRWFLGS(__FILE__, __LINE__);
   1459 	  }
   1460 	;
   1461 
   1462 iteration_stmnt:
   1463 	  while_expr stmnt {
   1464 		CLRWFLGS(__FILE__, __LINE__);
   1465 		while2();
   1466 	  }
   1467 	| while_expr error {
   1468 		CLRWFLGS(__FILE__, __LINE__);
   1469 		while2();
   1470 	  }
   1471 	| do_stmnt do_while_expr {
   1472 		do2($2);
   1473 		ftflg = 0;
   1474 	  }
   1475 	| do error {
   1476 		CLRWFLGS(__FILE__, __LINE__);
   1477 		do2(NULL);
   1478 	  }
   1479 	| for_exprs stmnt {
   1480 		CLRWFLGS(__FILE__, __LINE__);
   1481 		for2();
   1482 	  }
   1483 	| for_exprs error {
   1484 		CLRWFLGS(__FILE__, __LINE__);
   1485 		for2();
   1486 	  }
   1487 	;
   1488 
   1489 while_expr:
   1490 	  T_WHILE T_LPARN expr T_RPARN {
   1491 		while1($3);
   1492 		CLRWFLGS(__FILE__, __LINE__);
   1493 	  }
   1494 	;
   1495 
   1496 do:
   1497 	  T_DO {
   1498 		do1();
   1499 	  }
   1500 	;
   1501 
   1502 do_while_expr:
   1503 	  T_WHILE T_LPARN expr T_RPARN T_SEMI {
   1504 		$$ = $3;
   1505 	  }
   1506 	;
   1507 
   1508 for_exprs:
   1509 	    T_FOR T_LPARN declspecs deftyp notype_init_decls T_SEMI opt_expr
   1510 	    T_SEMI opt_expr T_RPARN {
   1511 		c99ism(325);
   1512 		for1(NULL, $7, $9);
   1513 		CLRWFLGS(__FILE__, __LINE__);
   1514 	    }
   1515 	  | T_FOR T_LPARN opt_expr T_SEMI opt_expr T_SEMI opt_expr T_RPARN {
   1516 		for1($3, $5, $7);
   1517 		CLRWFLGS(__FILE__, __LINE__);
   1518 	  }
   1519 	;
   1520 
   1521 opt_expr:
   1522 	  /* empty */ {
   1523 		$$ = NULL;
   1524 	  }
   1525 	| expr {
   1526 		$$ = $1;
   1527 	  }
   1528 	;
   1529 
   1530 jump_stmnt:
   1531 	  goto identifier T_SEMI {
   1532 		dogoto(getsym($2));
   1533 	  }
   1534 	| goto error T_SEMI {
   1535 		symtyp = FVFT;
   1536 	  }
   1537 	| T_CONTINUE T_SEMI {
   1538 		docont();
   1539 	  }
   1540 	| T_BREAK T_SEMI {
   1541 		dobreak();
   1542 	  }
   1543 	| T_RETURN T_SEMI {
   1544 		doreturn(NULL);
   1545 	  }
   1546 	| T_RETURN expr T_SEMI {
   1547 		doreturn($2);
   1548 	  }
   1549 	;
   1550 
   1551 goto:
   1552 	  T_GOTO {
   1553 		symtyp = FLAB;
   1554 	  }
   1555 	;
   1556 
   1557 asm_stmnt:
   1558 	  T_ASM T_LPARN read_until_rparn T_SEMI {
   1559 		setasm();
   1560 	  }
   1561 	| T_ASM T_QUAL T_LPARN read_until_rparn T_SEMI {
   1562 		setasm();
   1563 	  }
   1564 	| T_ASM error
   1565 	;
   1566 
   1567 read_until_rparn:
   1568 	  /* empty */ {
   1569 		ignuptorp();
   1570 	  }
   1571 	;
   1572 
   1573 declaration_list:
   1574 	  declaration {
   1575 		CLRWFLGS(__FILE__, __LINE__);
   1576 	  }
   1577 	| declaration_list declaration {
   1578 		CLRWFLGS(__FILE__, __LINE__);
   1579 	  }
   1580 	;
   1581 
   1582 constant:
   1583 	  expr				%prec T_COMMA {
   1584 		  $$ = $1;
   1585 	  }
   1586 	;
   1587 
   1588 expr:
   1589 	  expr T_MULT expr {
   1590 		$$ = build(MULT, $1, $3);
   1591 	  }
   1592 	| expr T_DIVOP expr {
   1593 		$$ = build($2, $1, $3);
   1594 	  }
   1595 	| expr T_ADDOP expr {
   1596 		$$ = build($2, $1, $3);
   1597 	  }
   1598 	| expr T_SHFTOP expr {
   1599 		$$ = build($2, $1, $3);
   1600 	  }
   1601 	| expr T_RELOP expr {
   1602 		$$ = build($2, $1, $3);
   1603 	  }
   1604 	| expr T_EQOP expr {
   1605 		$$ = build($2, $1, $3);
   1606 	  }
   1607 	| expr T_AND expr {
   1608 		$$ = build(AND, $1, $3);
   1609 	  }
   1610 	| expr T_XOR expr {
   1611 		$$ = build(XOR, $1, $3);
   1612 	  }
   1613 	| expr T_OR expr {
   1614 		$$ = build(OR, $1, $3);
   1615 	  }
   1616 	| expr T_LOGAND expr {
   1617 		$$ = build(LOGAND, $1, $3);
   1618 	  }
   1619 	| expr T_LOGOR expr {
   1620 		$$ = build(LOGOR, $1, $3);
   1621 	  }
   1622 	| expr T_QUEST expr T_COLON expr {
   1623 		$$ = build(QUEST, $1, build(COLON, $3, $5));
   1624 	  }
   1625 	| expr T_ASSIGN expr {
   1626 		$$ = build(ASSIGN, $1, $3);
   1627 	  }
   1628 	| expr T_OPASS expr {
   1629 		$$ = build($2, $1, $3);
   1630 	  }
   1631 	| expr T_COMMA expr {
   1632 		$$ = build(COMMA, $1, $3);
   1633 	  }
   1634 	| term {
   1635 		$$ = $1;
   1636 	  }
   1637 	;
   1638 
   1639 term:
   1640 	  T_NAME {
   1641 		/* XXX really necessary? */
   1642 		if (yychar < 0)
   1643 			yychar = yylex();
   1644 		$$ = getnnode(getsym($1), yychar);
   1645 	  }
   1646 	| string {
   1647 		$$ = getsnode($1);
   1648 	  }
   1649 	| T_CON {
   1650 		$$ = getcnode(gettyp($1->v_tspec), $1);
   1651 	  }
   1652 	| T_LPARN expr T_RPARN {
   1653 		if ($2 != NULL)
   1654 			$2->tn_parn = 1;
   1655 		$$ = $2;
   1656 	  }
   1657 	| T_LPARN comp_stmnt_lbrace declaration_list expr_stmnt_list {
   1658 		blklev--;
   1659 		mblklev--;
   1660 		initsym = mktempsym(duptyp($4->tn_type));
   1661 		mblklev++;
   1662 		blklev++;
   1663 		gnuism(320);
   1664 	} comp_stmnt_rbrace T_RPARN {
   1665 		$$ = getnnode(initsym, 0);
   1666 	}
   1667 	| T_LPARN comp_stmnt_lbrace expr_stmnt_list {
   1668 		blklev--;
   1669 		mblklev--;
   1670 		initsym = mktempsym($3->tn_type);
   1671 		mblklev++;
   1672 		blklev++;
   1673 		gnuism(320);
   1674 	} comp_stmnt_rbrace T_RPARN {
   1675 		$$ = getnnode(initsym, 0);
   1676 	}
   1677 	| term T_INCDEC {
   1678 		$$ = build($2 == INC ? INCAFT : DECAFT, $1, NULL);
   1679 	  }
   1680 	| T_INCDEC term {
   1681 		$$ = build($1 == INC ? INCBEF : DECBEF, $2, NULL);
   1682 	  }
   1683 	| T_MULT term {
   1684 		$$ = build(STAR, $2, NULL);
   1685 	  }
   1686 	| T_AND term {
   1687 		$$ = build(AMPER, $2, NULL);
   1688 	  }
   1689 	| T_UNOP term {
   1690 		$$ = build($1, $2, NULL);
   1691 	  }
   1692 	| T_ADDOP term {
   1693 		if (tflag && $1 == PLUS) {
   1694 			/* unary + is illegal in traditional C */
   1695 			warning(100);
   1696 		}
   1697 		$$ = build($1 == PLUS ? UPLUS : UMINUS, $2, NULL);
   1698 	  }
   1699 	| term T_LBRACK expr T_RBRACK {
   1700 		$$ = build(STAR, build(PLUS, $1, $3), NULL);
   1701 	  }
   1702 	| term T_LPARN T_RPARN {
   1703 		$$ = funccall($1, NULL);
   1704 	  }
   1705 	| term T_LPARN func_arg_list T_RPARN {
   1706 		$$ = funccall($1, $3);
   1707 	  }
   1708 	| term point_or_arrow T_NAME {
   1709 		if ($1 != NULL) {
   1710 			sym_t	*msym;
   1711 			/* XXX strmemb should be integrated in build() */
   1712 			if ($2 == ARROW) {
   1713 				/* must to this before strmemb is called */
   1714 				$1 = cconv($1);
   1715 			}
   1716 			msym = strmemb($1, $2, getsym($3));
   1717 			$$ = build($2, $1, getnnode(msym, 0));
   1718 		} else {
   1719 			$$ = NULL;
   1720 		}
   1721 	  }
   1722 	| T_REAL term {
   1723 		$$ = build(REAL, $2, NULL);
   1724 	  }
   1725 	| T_IMAG term {
   1726 		$$ = build(IMAG, $2, NULL);
   1727 	  }
   1728 	| T_REAL T_LPARN term T_RPARN {
   1729 		$$ = build(REAL, $3, NULL);
   1730 	  }
   1731 	| T_IMAG T_LPARN term T_RPARN {
   1732 		$$ = build(IMAG, $3, NULL);
   1733 	  }
   1734 	| T_SIZEOF term					%prec T_SIZEOF {
   1735 		if (($$ = $2 == NULL ? NULL : bldszof($2->tn_type)) != NULL)
   1736 			chkmisc($2, 0, 0, 0, 0, 0, 1);
   1737 	  }
   1738 	| T_SIZEOF T_LPARN type_name T_RPARN		%prec T_SIZEOF {
   1739 		$$ = bldszof($3);
   1740 	  }
   1741 	| T_ALIGNOF T_LPARN type_name T_RPARN		%prec T_ALIGNOF {
   1742 		$$ = bldalof($3);
   1743 	  }
   1744 	| T_LPARN type_name T_RPARN term		%prec T_UNOP {
   1745 		$$ = cast($4, $2);
   1746 	  }
   1747 	| T_LPARN type_name T_RPARN 			%prec T_UNOP {
   1748 		sym_t *tmp = mktempsym($2);
   1749 		idecl(tmp, 1, NULL);
   1750 	  } init_lbrace init_expr_list init_rbrace {
   1751 		if (!Sflag)
   1752 			gnuism(319);
   1753 		$$ = getnnode(initsym, 0);
   1754 	  }
   1755 	;
   1756 
   1757 string:
   1758 	  T_STRING {
   1759 		$$ = $1;
   1760 	  }
   1761 	| T_STRING string2 {
   1762 		$$ = catstrg($1, $2);
   1763 	  }
   1764 	;
   1765 
   1766 string2:
   1767 	 T_STRING {
   1768 		if (tflag) {
   1769 			/* concatenated strings are illegal in traditional C */
   1770 			warning(219);
   1771 		}
   1772 		$$ = $1;
   1773 	  }
   1774 	| string2 T_STRING {
   1775 		$$ = catstrg($1, $2);
   1776 	  }
   1777 	;
   1778 
   1779 func_arg_list:
   1780 	  expr						%prec T_COMMA {
   1781 		$$ = funcarg(NULL, $1);
   1782 	  }
   1783 	| func_arg_list T_COMMA expr {
   1784 		$$ = funcarg($1, $3);
   1785 	  }
   1786 	;
   1787 
   1788 point_or_arrow:
   1789 	  T_STROP {
   1790 		symtyp = FMOS;
   1791 		$$ = $1;
   1792 	  }
   1793 	;
   1794 
   1795 point:
   1796 	  T_STROP {
   1797 		if ($1 != POINT) {
   1798 			error(249, yytext);
   1799 		}
   1800 	  }
   1801 	;
   1802 
   1803 identifier:
   1804 	  T_NAME {
   1805 		$$ = $1;
   1806 	  }
   1807 	| T_TYPENAME {
   1808 		$$ = $1;
   1809 	  }
   1810 	;
   1811 
   1812 %%
   1813 
   1814 /* ARGSUSED */
   1815 int
   1816 yyerror(const char *msg)
   1817 {
   1818 	error(249, yytext);
   1819 	if (++sytxerr >= 5)
   1820 		norecover();
   1821 	return (0);
   1822 }
   1823 
   1824 static __inline int uq_gt(uint64_t, uint64_t);
   1825 static __inline int q_gt(int64_t, int64_t);
   1826 
   1827 static __inline int
   1828 uq_gt(uint64_t a, uint64_t b)
   1829 {
   1830 
   1831 	return (a > b);
   1832 }
   1833 
   1834 static __inline int
   1835 q_gt(int64_t a, int64_t b)
   1836 {
   1837 
   1838 	return (a > b);
   1839 }
   1840 
   1841 #define	q_lt(a, b)	q_gt(b, a)
   1842 
   1843 /*
   1844  * Gets a node for a constant and returns the value of this constant
   1845  * as integer.
   1846  * Is the node not constant or too large for int or of type float,
   1847  * a warning will be printed.
   1848  *
   1849  * toicon() should be used only inside declarations. If it is used in
   1850  * expressions, it frees the memory used for the expression.
   1851  */
   1852 static int
   1853 toicon(tnode_t *tn, int required)
   1854 {
   1855 	int	i;
   1856 	tspec_t	t;
   1857 	val_t	*v;
   1858 
   1859 	v = constant(tn, required);
   1860 
   1861 	/*
   1862 	 * Abstract declarations are used inside expression. To free
   1863 	 * the memory would be a fatal error.
   1864 	 */
   1865 	if (dcs->d_ctx != ABSTRACT)
   1866 		tfreeblk();
   1867 
   1868 	if ((t = v->v_tspec) == FLOAT || t == DOUBLE || t == LDOUBLE) {
   1869 		i = (int)v->v_ldbl;
   1870 		/* integral constant expression expected */
   1871 		error(55);
   1872 	} else {
   1873 		i = (int)v->v_quad;
   1874 		if (isutyp(t)) {
   1875 			if (uq_gt((uint64_t)v->v_quad,
   1876 				  (uint64_t)TARG_INT_MAX)) {
   1877 				/* integral constant too large */
   1878 				warning(56);
   1879 			}
   1880 		} else {
   1881 			if (q_gt(v->v_quad, (int64_t)TARG_INT_MAX) ||
   1882 			    q_lt(v->v_quad, (int64_t)TARG_INT_MIN)) {
   1883 				/* integral constant too large */
   1884 				warning(56);
   1885 			}
   1886 		}
   1887 	}
   1888 	free(v);
   1889 	return (i);
   1890 }
   1891 
   1892 static void
   1893 idecl(sym_t *decl, int initflg, sbuf_t *renaming)
   1894 {
   1895 	char *s;
   1896 
   1897 	initerr = 0;
   1898 	initsym = decl;
   1899 
   1900 	switch (dcs->d_ctx) {
   1901 	case EXTERN:
   1902 		if (renaming != NULL) {
   1903 			if (decl->s_rename != NULL)
   1904 				LERROR("idecl()");
   1905 
   1906 			s = getlblk(1, renaming->sb_len + 1);
   1907 	                (void)memcpy(s, renaming->sb_name, renaming->sb_len + 1);
   1908 			decl->s_rename = s;
   1909 			freeyyv(&renaming, T_NAME);
   1910 		}
   1911 		decl1ext(decl, initflg);
   1912 		break;
   1913 	case ARG:
   1914 		if (renaming != NULL) {
   1915 			/* symbol renaming can't be used on function arguments */
   1916 			error(310);
   1917 			freeyyv(&renaming, T_NAME);
   1918 			break;
   1919 		}
   1920 		(void)decl1arg(decl, initflg);
   1921 		break;
   1922 	case AUTO:
   1923 		if (renaming != NULL) {
   1924 			/* symbol renaming can't be used on automatic variables */
   1925 			error(311);
   1926 			freeyyv(&renaming, T_NAME);
   1927 			break;
   1928 		}
   1929 		decl1loc(decl, initflg);
   1930 		break;
   1931 	default:
   1932 		LERROR("idecl()");
   1933 	}
   1934 
   1935 	if (initflg && !initerr)
   1936 		prepinit();
   1937 }
   1938 
   1939 /*
   1940  * Discard all input tokens up to and including the next
   1941  * unmatched right paren
   1942  */
   1943 static void
   1944 ignuptorp(void)
   1945 {
   1946 	int	level;
   1947 
   1948 	if (yychar < 0)
   1949 		yychar = yylex();
   1950 	freeyyv(&yylval, yychar);
   1951 
   1952 	level = 1;
   1953 	while (yychar != T_RPARN || --level > 0) {
   1954 		if (yychar == T_LPARN) {
   1955 			level++;
   1956 		} else if (yychar <= 0) {
   1957 			break;
   1958 		}
   1959 		freeyyv(&yylval, yychar = yylex());
   1960 	}
   1961 
   1962 	yyclearin;
   1963 }
   1964