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