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