%{
#include "strmake.h"
#define START_VARIABLE	1001
#define START_WORD	2001
#define START_SHARP	3001
#define START_YACC	4001
#define IS_RESERVED_WORD(a)	((a) >= START_WORD)
#define IS_RESERVED_VARIABLE(a)	((a) >= START_VARIABLE && (a) < START_WORD)
#define IS_RESERVED_SHARP(a)	((a) >= START_SHARP && (a) < START_YACC)
#define IS_RESERVED_YACC(a)	((a) >= START_YACC)

#define C___P	2001
#define C___ATTRIBUTE__	2002
#define C___EXTENSION__	2003
#define C_ASM	2004
#define C_CONST	2005
#define C_INLINE	2006
#define C_RESTRICT	2007
#define C_SIGNED	2008
#define C_VOLATILE	2009
#define C__ALIGNAS	2010
#define C__ALIGNOF	2011
#define C__ATOMIC	2012
#define C__BOOL	2013
#define C__COMPLEX	2014
#define C__GENERIC	2015
#define C__IMAGINARY	2016
#define C__NORETURN	2017
#define C__STATIC_ASSERT	2018
#define C__THREAD_LOCAL	2019
#define C_AUTO	2020
#define C_BREAK	2021
#define C_CASE	2022
#define C_CHAR	2023
#define C_CONTINUE	2024
#define C_DEFAULT	2025
#define C_DO	2026
#define C_DOUBLE	2027
#define C_ELSE	2028
#define C_ENUM	2029
#define C_EXTERN	2030
#define C_FLOAT	2031
#define C_FOR	2032
#define C_GOTO	2033
#define C_IF	2034
#define C_INT	2035
#define C_LONG	2036
#define C_REGISTER	2037
#define C_RETURN	2038
#define C_SHORT	2039
#define C_SIZEOF	2040
#define C_STATIC	2041
#define C_STRUCT	2042
#define C_SWITCH	2043
#define C_TYPEDEF	2044
#define C_UNION	2045
#define C_UNSIGNED	2046
#define C_VOID	2047
#define C_WHILE	2048
#define SHARP_SHARP	3001
#define SHARP_ASSERT	3002
#define SHARP_DEFINE	3003
#define SHARP_ELIF	3004
#define SHARP_ELSE	3005
#define SHARP_ENDIF	3006
#define SHARP_ERROR	3007
#define SHARP_IDENT	3008
#define SHARP_IF	3009
#define SHARP_IFDEF	3010
#define SHARP_IFNDEF	3011
#define SHARP_IMPORT	3012
#define SHARP_INCLUDE	3013
#define SHARP_INCLUDE_NEXT	3014
#define SHARP_LINE	3015
#define SHARP_PRAGMA	3016
#define SHARP_SCCS	3017
#define SHARP_UNASSERT	3018
#define SHARP_UNDEF	3019
#define SHARP_WARNING	3020
#define YACC_SEP	4001
#define YACC_DEBUG	4002
#define YACC_DEFAULT_PREC	4003
#define YACC_DEFINE	4004
#define YACC_DEFINES	4005
#define YACC_DESTRUCTOR	4006
#define YACC_DPREC	4007
#define YACC_ERROR_VERBOSE	4008
#define YACC_EXPECT	4009
#define YACC_EXPECT_RR	4010
#define YACC_FILE_PREFIX	4011
#define YACC_GLR_PARSER	4012
#define YACC_INITIAL_ACTION	4013
#define YACC_LEFT	4014
#define YACC_LEX_PARAM	4015
#define YACC_LOCATIONS	4016
#define YACC_MERGE	4017
#define YACC_NAME_PREFIX	4018
#define YACC_NO_DEFAULT_PREC	4019
#define YACC_NO_LINES	4020
#define YACC_NONASSOC	4021
#define YACC_NONDETERMINISTIC_PARSER	4022
#define YACC_NTERM	4023
#define YACC_OUTPUT	4024
#define YACC_PARSE_PARAM	4025
#define YACC_PREC	4026
#define YACC_PRINTER	4027
#define YACC_PURE_PARSER	4028
#define YACC_REQUIRE	4029
#define YACC_RIGHT	4030
#define YACC_SKELETON	4031
#define YACC_START	4032
#define YACC_TOKEN	4033
#define YACC_TOKEN_TABLE	4034
#define YACC_TYPE	4035
#define YACC_UNION	4036
#define YACC_VERBOSE	4037
#define YACC_YACC	4038
#define YACC_BEGIN	4039
#define YACC_END	4040
%}
struct keyword { char *name; int token; }
%%
__P, C___P
__attribute__, C___ATTRIBUTE__
__attribute, C___ATTRIBUTE__
__extension__, C___EXTENSION__
asm, C_ASM
__asm, C_ASM
__asm__, C_ASM
const, C_CONST
__const, C_CONST
__const__, C_CONST
inline, C_INLINE
__inline, C_INLINE
__inline__, C_INLINE
restrict, C_RESTRICT
__restrict, C_RESTRICT
__restrict__, C_RESTRICT
signed, C_SIGNED
__signed, C_SIGNED
__signed__, C_SIGNED
volatile, C_VOLATILE
__volatile, C_VOLATILE
__volatile__, C_VOLATILE
_Alignas, C__ALIGNAS
_Alignof, C__ALIGNOF
__alignof, C__ALIGNOF
__alignof__, C__ALIGNOF
_Atomic, C__ATOMIC
_Bool, C__BOOL
_Complex, C__COMPLEX
__complex, C__COMPLEX
__complex__, C__COMPLEX
_Generic, C__GENERIC
_Imaginary, C__IMAGINARY
_Noreturn, C__NORETURN
_Static_assert, C__STATIC_ASSERT
_Thread_local, C__THREAD_LOCAL
__thread, C__THREAD_LOCAL
auto, C_AUTO
break, C_BREAK
case, C_CASE
char, C_CHAR
continue, C_CONTINUE
default, C_DEFAULT
do, C_DO
double, C_DOUBLE
else, C_ELSE
enum, C_ENUM
extern, C_EXTERN
float, C_FLOAT
for, C_FOR
goto, C_GOTO
if, C_IF
int, C_INT
long, C_LONG
register, C_REGISTER
return, C_RETURN
short, C_SHORT
sizeof, C_SIZEOF
static, C_STATIC
struct, C_STRUCT
switch, C_SWITCH
typedef, C_TYPEDEF
union, C_UNION
unsigned, C_UNSIGNED
void, C_VOID
while, C_WHILE
"##", SHARP_SHARP
"#assert", SHARP_ASSERT
"#define", SHARP_DEFINE
"#elif", SHARP_ELIF
"#else", SHARP_ELSE
"#endif", SHARP_ENDIF
"#error", SHARP_ERROR
"#ident", SHARP_IDENT
"#if", SHARP_IF
"#ifdef", SHARP_IFDEF
"#ifndef", SHARP_IFNDEF
"#import", SHARP_IMPORT
"#include", SHARP_INCLUDE
"#include_next", SHARP_INCLUDE_NEXT
"#line", SHARP_LINE
"#pragma", SHARP_PRAGMA
"#sccs", SHARP_SCCS
"#unassert", SHARP_UNASSERT
"#undef", SHARP_UNDEF
"#warning", SHARP_WARNING
"%%", YACC_SEP
"%debug", YACC_DEBUG
"%default_prec", YACC_DEFAULT_PREC
"%default-prec", YACC_DEFAULT_PREC
"%define", YACC_DEFINE
"%defines", YACC_DEFINES
"%destructor", YACC_DESTRUCTOR
"%dprec", YACC_DPREC
"%error_verbose", YACC_ERROR_VERBOSE
"%error-verbose", YACC_ERROR_VERBOSE
"%expect", YACC_EXPECT
"%expect_rr", YACC_EXPECT_RR
"%expect-rr", YACC_EXPECT_RR
"%file-prefix", YACC_FILE_PREFIX
"%glr-parser", YACC_GLR_PARSER
"%initial-action", YACC_INITIAL_ACTION
"%left", YACC_LEFT
"%lex-param", YACC_LEX_PARAM
"%locations", YACC_LOCATIONS
"%merge", YACC_MERGE
"%name_prefix", YACC_NAME_PREFIX
"%name-prefix", YACC_NAME_PREFIX
"%no_default_prec", YACC_NO_DEFAULT_PREC
"%no_default-prec", YACC_NO_DEFAULT_PREC
"%no-default_prec", YACC_NO_DEFAULT_PREC
"%no-default-prec", YACC_NO_DEFAULT_PREC
"%no_lines", YACC_NO_LINES
"%no-lines", YACC_NO_LINES
"%nonassoc", YACC_NONASSOC
"%binary", YACC_NONASSOC
"%nondeterministic-parser", YACC_NONDETERMINISTIC_PARSER
"%nterm", YACC_NTERM
"%output", YACC_OUTPUT
"%parse-param", YACC_PARSE_PARAM
"%prec", YACC_PREC
"%printer", YACC_PRINTER
"%pure_parser", YACC_PURE_PARSER
"%pure-parser", YACC_PURE_PARSER
"%require", YACC_REQUIRE
"%right", YACC_RIGHT
"%skeleton", YACC_SKELETON
"%start", YACC_START
"%token", YACC_TOKEN
"%term", YACC_TOKEN
"%token_table", YACC_TOKEN_TABLE
"%token-table", YACC_TOKEN_TABLE
"%type", YACC_TYPE
"%union", YACC_UNION
"%verbose", YACC_VERBOSE
"%yacc", YACC_YACC
"%fixed_output_files", YACC_YACC
"%fixed-output_files", YACC_YACC
"%fixed_output-files", YACC_YACC
"%fixed-output-files", YACC_YACC
"%{", YACC_BEGIN
"%}", YACC_END
%%
int
c_reserved_word(const char *str, int len)
{
	struct keyword *keyword;

	keyword = c_lookup(str, len);
	return (keyword && IS_RESERVED_WORD(keyword->token)) ? keyword->token : 0;
}
int
c_reserved_sharp(const char *str, int len)
{
	struct keyword *keyword;

	/* Delete blanks. Ex. ' # define ' => '#define' */
	str = strtrim(str, TRIM_ALL, &len);

	keyword = c_lookup(str, len);
	return (keyword && IS_RESERVED_SHARP(keyword->token)) ? keyword->token : 0;
}
int
c_reserved_yacc(const char *str, int len)
{
	struct keyword *keyword;

	keyword = c_lookup(str, len);
	return (keyword && IS_RESERVED_YACC(keyword->token)) ? keyword->token : 0;
}
