1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
|
%{
#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___THREAD 2004
#define C_ASM 2005
#define C_CONST 2006
#define C_INLINE 2007
#define C_RESTRICT 2008
#define C_SIGNED 2009
#define C_VOLATILE 2010
#define C__BOOL 2011
#define C__COMPLEX 2012
#define C__IMAGINARY 2013
#define C_AUTO 2014
#define C_BREAK 2015
#define C_CASE 2016
#define C_CHAR 2017
#define C_CONTINUE 2018
#define C_DEFAULT 2019
#define C_DO 2020
#define C_DOUBLE 2021
#define C_ELSE 2022
#define C_ENUM 2023
#define C_EXTERN 2024
#define C_FLOAT 2025
#define C_FOR 2026
#define C_GOTO 2027
#define C_IF 2028
#define C_INT 2029
#define C_LONG 2030
#define C_REGISTER 2031
#define C_RETURN 2032
#define C_SHORT 2033
#define C_SIZEOF 2034
#define C_STATIC 2035
#define C_STRUCT 2036
#define C_SWITCH 2037
#define C_TYPEDEF 2038
#define C_UNION 2039
#define C_UNSIGNED 2040
#define C_VOID 2041
#define C_WHILE 2042
#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_RIGHT 4029
#define YACC_SKELETON 4030
#define YACC_START 4031
#define YACC_TOKEN 4032
#define YACC_TOKEN_TABLE 4033
#define YACC_TYPE 4034
#define YACC_UNION 4035
#define YACC_VERBOSE 4036
#define YACC_YACC 4037
#define YACC_BEGIN 4038
#define YACC_END 4039
%}
struct keyword { char *name; int token; }
%%
__P, C___P
__attribute__, C___ATTRIBUTE__
__attribute, C___ATTRIBUTE__
__extension__, C___EXTENSION__
__thread, C___THREAD
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
_Bool, C__BOOL
_Complex, C__COMPLEX
_Imaginary, C__IMAGINARY
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
"%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 *, int);
int
c_reserved_word(str, len)
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 *, int);
int
c_reserved_sharp(str, len)
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 *, int);
int
c_reserved_yacc(str, len)
const char *str;
int len;
{
struct keyword *keyword;
keyword = c_lookup(str, len);
return (keyword && IS_RESERVED_YACC(keyword->token)) ? keyword->token : 0;
}
|