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