109 "enum", |
109 "enum", |
110 "func", |
110 "func", |
111 "return", |
111 "return", |
112 }; |
112 }; |
113 |
113 |
114 static_assert (countof (gTokenStrings) == (int) tkLastNamedToken + 1, |
114 static_assert (countof (gTokenStrings) == (int)gLastNamedToken + 1, |
115 "Count of gTokenStrings is not the same as the amount of named token identifiers."); |
115 "Count of gTokenStrings is not the same as the amount of named token identifiers."); |
116 |
116 |
117 // ============================================================================= |
117 // ============================================================================= |
118 // |
118 // |
119 LexerScanner::LexerScanner (FILE* fp) : |
119 LexerScanner::LexerScanner (FILE* fp) : |
190 // Check tokens |
190 // Check tokens |
191 for (int i = 0; i < countof (gTokenStrings); ++i) |
191 for (int i = 0; i < countof (gTokenStrings); ++i) |
192 { |
192 { |
193 int flags = 0; |
193 int flags = 0; |
194 |
194 |
195 if (i >= tkFirstNamedToken) |
195 if (i >= gFirstNamedToken) |
196 flags |= FCheckWord; |
196 flags |= FCheckWord; |
197 |
197 |
198 if (CheckString (gTokenStrings[i], flags)) |
198 if (CheckString (gTokenStrings[i], flags)) |
199 { |
199 { |
200 mTokenText = gTokenStrings[i]; |
200 mTokenText = gTokenStrings[i]; |
201 mTokenType = (EToken) i; |
201 mTokenType = (TokenType) i; |
202 return true; |
202 return true; |
203 } |
203 } |
204 } |
204 } |
205 |
205 |
206 // Check and parse string |
206 // Check and parse string |
230 } |
230 } |
231 |
231 |
232 mTokenText += *mPosition++; |
232 mTokenText += *mPosition++; |
233 } |
233 } |
234 |
234 |
235 mTokenType = tkString; |
235 mTokenType =TK_String; |
236 Skip(); // skip the final quote |
236 Skip(); // skip the final quote |
237 return true; |
237 return true; |
238 } |
238 } |
239 |
239 |
240 if (isdigit (*mPosition)) |
240 if (isdigit (*mPosition)) |
241 { |
241 { |
242 while (isdigit (*mPosition)) |
242 while (isdigit (*mPosition)) |
243 mTokenText += *mPosition++; |
243 mTokenText += *mPosition++; |
244 |
244 |
245 mTokenType = tkNumber; |
245 mTokenType =TK_Number; |
246 return true; |
246 return true; |
247 } |
247 } |
248 |
248 |
249 if (IsSymbolChar (*mPosition, false)) |
249 if (IsSymbolChar (*mPosition, false)) |
250 { |
250 { |
251 mTokenType = tkSymbol; |
251 mTokenType =TK_Symbol; |
252 |
252 |
253 do |
253 do |
254 { |
254 { |
255 if (!IsSymbolChar (*mPosition, true)) |
255 if (!IsSymbolChar (*mPosition, true)) |
256 break; |
256 break; |
286 Skip(); |
286 Skip(); |
287 } |
287 } |
288 |
288 |
289 // ============================================================================= |
289 // ============================================================================= |
290 // |
290 // |
291 String LexerScanner::GetTokenString (EToken a) |
291 String LexerScanner::GetTokenString (TokenType a) |
292 { |
292 { |
293 assert ((int) a <= tkLastNamedToken); |
293 assert ((int) a <= gLastNamedToken); |
294 return gTokenStrings[a]; |
294 return gTokenStrings[a]; |
295 } |
295 } |
296 |
296 |
297 // ============================================================================= |
297 // ============================================================================= |
298 // |
298 // |