1 /* Perfect hash generated by command line:
2 * ./perfhash 11
3 */
4 #ifndef SLCONST
5 #define SLCONST const
6 #endif
7 #define MIN_HASH_VALUE 2
8 #define MAX_HASH_VALUE 133
9 #define MIN_KEYWORD_LEN 2
10 #define MAX_KEYWORD_LEN 11
11
12 static SLCONST unsigned char Keyword_Hash_Table [256] =
13 {
14 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134,
15 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134,
16 134, 55, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134,
17 11, 22, 33, 44, 55, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134,
18 134, 134, 0, 0, 134, 0, 134, 134, 134, 0, 134, 0, 0, 134, 134, 0,
19 134, 134, 0, 0, 0, 0, 134, 134, 0, 134, 134, 134, 134, 134, 134, 0,
20 134, 11, 0, 0, 55, 0, 17, 0, 46, 13, 134, 0, 22, 11, 11, 0,
21 37, 134, 0, 22, 0, 55, 0, 0, 44, 0, 134, 134, 134, 134, 134, 134,
22 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134,
23 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134,
24 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134,
25 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134,
26 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134,
27 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134,
28 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134,
29 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134
30 };
31
keyword_hash(char * s,unsigned int len)32 static unsigned char keyword_hash (char *s, unsigned int len)
33 {
34 unsigned int sum;
35
36 sum = len;
37 while (len)
38 {
39 len--;
40 sum += (unsigned int) Keyword_Hash_Table [(unsigned char)s[len]];
41 }
42 return sum;
43 }
44
45 typedef SLCONST struct
46 {
47 SLFUTURE_CONST char *name;
48 unsigned int type;
49 }
50 Keyword_Table_Type;
51
52 static Keyword_Table_Type Keyword_Table [/* 132 */] =
53 {
54 {"or", OR_TOKEN},
55 {"try", TRY_TOKEN},
56 {NULL,0},
57 {NULL,0},
58 {NULL,0},
59 {NULL,0},
60 {NULL,0},
61 {NULL,0},
62 {"EXIT_BLOCK", EXITBLK_TOKEN},
63 {"ERROR_BLOCK", ERRBLK_TOKEN},
64 {NULL,0},
65 {NULL,0},
66 {"not", NOT_TOKEN},
67 {NULL,0},
68 {"break", BREAK_TOKEN},
69 {NULL,0},
70 {NULL,0},
71 {NULL,0},
72 {"for", FOR_TOKEN},
73 {"_for", _FOR_TOKEN},
74 {"USER_BLOCK0", USRBLK0_TOKEN},
75 {NULL,0},
76 {"forever", FOREVER_TOKEN},
77 {NULL,0},
78 {NULL,0},
79 {NULL,0},
80 {NULL,0},
81 {NULL,0},
82 {NULL,0},
83 {NULL,0},
84 {"if", IF_TOKEN},
85 {"USER_BLOCK1", USRBLK1_TOKEN},
86 {NULL,0},
87 {NULL,0},
88 {NULL,0},
89 {"case", CASE_TOKEN},
90 {NULL,0},
91 {NULL,0},
92 {NULL,0},
93 {NULL,0},
94 {NULL,0},
95 {NULL,0},
96 {"USER_BLOCK2", USRBLK2_TOKEN},
97 {NULL,0},
98 {"ifnot", IFNOT_TOKEN},
99 {"xor", BXOR_TOKEN},
100 {"else", ELSE_TOKEN},
101 {NULL,0},
102 {"orelse", ORELSE_TOKEN},
103 {"throw", THROW_TOKEN},
104 {"static", STATIC_TOKEN},
105 {"__tmp", TMP_TOKEN},
106 {NULL,0},
107 {"USER_BLOCK3", USRBLK3_TOKEN},
108 {NULL,0},
109 {"do", DO_TOKEN},
110 {NULL,0},
111 {NULL,0},
112 {NULL,0},
113 {"then", THEN_TOKEN},
114 {"catch", CATCH_TOKEN},
115 {"loop", LOOP_TOKEN},
116 {NULL,0},
117 {"variable", VARIABLE_TOKEN},
118 {"USER_BLOCK4", USRBLK4_TOKEN},
119 {NULL,0},
120 {"private", PRIVATE_TOKEN},
121 {"mod", MOD_TOKEN},
122 {NULL,0},
123 {"shr", SHR_TOKEN},
124 {"return", RETURN_TOKEN},
125 {NULL,0},
126 {NULL,0},
127 {NULL,0},
128 {NULL,0},
129 {"pop", POP_TOKEN},
130 {NULL,0},
131 {NULL,0},
132 {"and", AND_TOKEN},
133 {"foreach", FOREACH_TOKEN},
134 {NULL,0},
135 {"struct", STRUCT_TOKEN},
136 {NULL,0},
137 {NULL,0},
138 {"while", WHILE_TOKEN},
139 {"switch", SWITCH_TOKEN},
140 {"!if", IFNOT_TOKEN},
141 {NULL,0},
142 {NULL,0},
143 {NULL,0},
144 {NULL,0},
145 {"shl", SHL_TOKEN},
146 {"exch", EXCH_TOKEN},
147 {NULL,0},
148 {NULL,0},
149 {NULL,0},
150 {"continue", CONT_TOKEN},
151 {NULL,0},
152 {NULL,0},
153 {NULL,0},
154 {"define", DEFINE_TOKEN},
155 {"finally", FINALLY_TOKEN},
156 {NULL,0},
157 {NULL,0},
158 {"using", USING_TOKEN},
159 {NULL,0},
160 {NULL,0},
161 {NULL,0},
162 {NULL,0},
163 {NULL,0},
164 {NULL,0},
165 {NULL,0},
166 {NULL,0},
167 {NULL,0},
168 {"typedef", TYPEDEF_TOKEN},
169 {NULL,0},
170 {NULL,0},
171 {NULL,0},
172 {NULL,0},
173 {NULL,0},
174 {NULL,0},
175 {NULL,0},
176 {NULL,0},
177 {NULL,0},
178 {NULL,0},
179 {NULL,0},
180 {"andelse", ANDELSE_TOKEN},
181 {NULL,0},
182 {NULL,0},
183 {NULL,0},
184 {NULL,0},
185 {"public", PUBLIC_TOKEN},
186 };
187
is_keyword(char * str,unsigned int len)188 static Keyword_Table_Type *is_keyword (char *str, unsigned int len)
189 {
190 unsigned int hash;
191 SLCONST char *name;
192 Keyword_Table_Type *kw;
193
194 if ((len < MIN_KEYWORD_LEN)
195 || (len > MAX_KEYWORD_LEN))
196 return NULL;
197
198 hash = keyword_hash (str, len);
199 if ((hash > MAX_HASH_VALUE) || (hash < MIN_HASH_VALUE))
200 return NULL;
201
202 kw = &Keyword_Table[hash - MIN_HASH_VALUE];
203 if ((NULL != (name = kw->name))
204 && (*str == *name)
205 && (0 == strcmp (str, name)))
206 return kw;
207 return NULL;
208 }
209