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