1 using System;
2 using System.Collections;
3
4
5
6
7
8 namespace System.Lex
9 {
10 public class Keyword
11 {
12 public Keyword() :
13 str(null), tokenID(INVALID_TOKEN)
14 {
15 }
16 public Keyword(const uchar* str_, int tokenID_) :
17 str(str_), tokenID(tokenID_)
18 {
19 }
20 public const uchar* str;
21 public int tokenID;
22 }
23 public class KeywordMap
24 {
25 public KeywordMap(const Keyword* keywords_) :
26 keywords(keywords_)
27 {
28 const Keyword* kw = keywords;
29 while ((kw->str != null))
30 {
31 Lexeme lexeme(kw->str, StrEnd(kw->str));
32 keywordMap[lexeme] = kw->tokenID;
33 ++kw;
34 }
35 }
36 public int GetKeywordToken(const Lexeme& lexeme) const
37 {
38 Map<Lexeme, int>.ConstIterator it = keywordMap.CFind(lexeme);
39 if (it != keywordMap.CEnd())
40 {
41 return it->second;
42 }
43 else
44 {
45 return INVALID_TOKEN;
46 }
47 }
48 private const Keyword* keywords;
49 private Map<Lexeme, int> keywordMap;
50 }
51 public inline const uchar* StrEnd(const uchar* s)
52 {
53 while ((*s != u'\0'))
54 {
55 ++s;
56 }
57 return s;
58 }
59 }