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