1 using System;
2
3
4
5 namespace AssemblyTokens
6 {
7 public const int END = 0;
8
9 public const int DECIMAL_CONSTANT = 1;
10
11 public const int HEX_CONSTANT = 2;
12
13 public const int CHAR_CONSTANT = 3;
14
15 public const int STRING_CONSTANT = 4;
16
17 public const int CLSID_CONSTANT = 5;
18
19 public const int LOCAL_SYMBOL = 6;
20
21 public const int SYMBOL = 7;
22
23 public const int AT = 8;
24
25 public const int PLUS = 9;
26
27 public const int MINUS = 10;
28
29 public const int TILDE = 11;
30
31 public const int DOLLAR = 12;
32
33 public const int AMP = 13;
34
35 public const int AST = 14;
36
37 public const int SLASHSLASH = 15;
38
39 public const int SLASH = 16;
40
41 public const int PERCENT = 17;
42
43 public const int SHIFT_LEFT = 18;
44
45 public const int SHIFT_RIGHT = 19;
46
47 public const int BAR = 20;
48
49 public const int CARET = 21;
50
51 public const int DOT = 22;
52
53 public const int SPACE = 23;
54
55 public const int NEWLINE = 24;
56
57 public const int LPAREN = 25;
58
59 public const int RPAREN = 26;
60
61 public const int SEMICOLON = 27;
62
63 public const int COMMA = 28;
64
65 public const int CHAR = 29;
66
67 internal class TokenMap
68 {
69 static TokenMap() :
70 instance(new TokenMap())
71 {
72 }
73 public static TokenMap& Instance()
74 {
75 return *instance;
76 }
77 public int GetTokenId(const ustring& tokenName)
78 {
79 System.Collections.Map<ustring, int>.ConstIterator it = tokenIdMap.CFind(tokenName);
80 if (it != tokenIdMap.CEnd())
81 {
82 return it->second;
83 }
84 else
85 {
86 return -1;
87 }
88 }
89 public ustring GetTokenName(int tokenId)
90 {
91 return tokenNameList[tokenId];
92 }
93 public ustring GetTokenInfo(int tokenId)
94 {
95 return tokenInfoList[tokenId];
96 }
97 private TokenMap()
98 {
99 tokenIdMap[u"AMP"] = 13;
100 tokenIdMap[u"AST"] = 14;
101 tokenIdMap[u"AT"] = 8;
102 tokenIdMap[u"BAR"] = 20;
103 tokenIdMap[u"CARET"] = 21;
104 tokenIdMap[u"CHAR"] = 29;
105 tokenIdMap[u"CHAR_CONSTANT"] = 3;
106 tokenIdMap[u"CLSID_CONSTANT"] = 5;
107 tokenIdMap[u"COMMA"] = 28;
108 tokenIdMap[u"DECIMAL_CONSTANT"] = 1;
109 tokenIdMap[u"DOLLAR"] = 12;
110 tokenIdMap[u"DOT"] = 22;
111 tokenIdMap[u"HEX_CONSTANT"] = 2;
112 tokenIdMap[u"LOCAL_SYMBOL"] = 6;
113 tokenIdMap[u"LPAREN"] = 25;
114 tokenIdMap[u"MINUS"] = 10;
115 tokenIdMap[u"NEWLINE"] = 24;
116 tokenIdMap[u"PERCENT"] = 17;
117 tokenIdMap[u"PLUS"] = 9;
118 tokenIdMap[u"RPAREN"] = 26;
119 tokenIdMap[u"SEMICOLON"] = 27;
120 tokenIdMap[u"SHIFT_LEFT"] = 18;
121 tokenIdMap[u"SHIFT_RIGHT"] = 19;
122 tokenIdMap[u"SLASH"] = 16;
123 tokenIdMap[u"SLASHSLASH"] = 15;
124 tokenIdMap[u"SPACE"] = 23;
125 tokenIdMap[u"STRING_CONSTANT"] = 4;
126 tokenIdMap[u"SYMBOL"] = 7;
127 tokenIdMap[u"TILDE"] = 11;
128 tokenNameList.Add(u"END");
129 tokenInfoList.Add(u"end of file");
130 tokenNameList.Add(u"DECIMAL_CONSTANT");
131 tokenInfoList.Add(u"'decimal constant'");
132 tokenNameList.Add(u"HEX_CONSTANT");
133 tokenInfoList.Add(u"'hex constant'");
134 tokenNameList.Add(u"CHAR_CONSTANT");
135 tokenInfoList.Add(u"'char constant'");
136 tokenNameList.Add(u"STRING_CONSTANT");
137 tokenInfoList.Add(u"'string constant'");
138 tokenNameList.Add(u"CLSID_CONSTANT");
139 tokenInfoList.Add(u"'clsid constant'");
140 tokenNameList.Add(u"LOCAL_SYMBOL");
141 tokenInfoList.Add(u"'local symbol'");
142 tokenNameList.Add(u"SYMBOL");
143 tokenInfoList.Add(u"'symbol'");
144 tokenNameList.Add(u"AT");
145 tokenInfoList.Add(u"'at'");
146 tokenNameList.Add(u"PLUS");
147 tokenInfoList.Add(u"'plus'");
148 tokenNameList.Add(u"MINUS");
149 tokenInfoList.Add(u"'minus'");
150 tokenNameList.Add(u"TILDE");
151 tokenInfoList.Add(u"'tilde'");
152 tokenNameList.Add(u"DOLLAR");
153 tokenInfoList.Add(u"'$'");
154 tokenNameList.Add(u"AMP");
155 tokenInfoList.Add(u"'amp'");
156 tokenNameList.Add(u"AST");
157 tokenInfoList.Add(u"'ast'");
158 tokenNameList.Add(u"SLASHSLASH");
159 tokenInfoList.Add(u"'slashslash'");
160 tokenNameList.Add(u"SLASH");
161 tokenInfoList.Add(u"'slash'");
162 tokenNameList.Add(u"PERCENT");
163 tokenInfoList.Add(u"'percent'");
164 tokenNameList.Add(u"SHIFT_LEFT");
165 tokenInfoList.Add(u"'shift left'");
166 tokenNameList.Add(u"SHIFT_RIGHT");
167 tokenInfoList.Add(u"'shift right'");
168 tokenNameList.Add(u"BAR");
169 tokenInfoList.Add(u"'bar'");
170 tokenNameList.Add(u"CARET");
171 tokenInfoList.Add(u"'caret'");
172 tokenNameList.Add(u"DOT");
173 tokenInfoList.Add(u"'dot'");
174 tokenNameList.Add(u"SPACE");
175 tokenInfoList.Add(u"'space'");
176 tokenNameList.Add(u"NEWLINE");
177 tokenInfoList.Add(u"'newline'");
178 tokenNameList.Add(u"LPAREN");
179 tokenInfoList.Add(u"'('");
180 tokenNameList.Add(u"RPAREN");
181 tokenInfoList.Add(u"')'");
182 tokenNameList.Add(u"SEMICOLON");
183 tokenInfoList.Add(u"';'");
184 tokenNameList.Add(u"COMMA");
185 tokenInfoList.Add(u"','");
186 tokenNameList.Add(u"CHAR");
187 tokenInfoList.Add(u"'char'");
188 }
189 private static System.UniquePtr<TokenMap> instance;
190 private System.Collections.Map<ustring, int> tokenIdMap;
191 private System.Collections.List<ustring> tokenNameList;
192 private System.Collections.List<ustring> tokenInfoList;
193 }
194 public int GetTokenId(const ustring& tokenName)
195 {
196 return TokenMap.Instance().GetTokenId(tokenName);
197 }
198
199 public ustring GetTokenName(int tokenId)
200 {
201 return TokenMap.Instance().GetTokenName(tokenId);
202 }
203
204 public ustring GetTokenInfo(int tokenId)
205 {
206 return TokenMap.Instance().GetTokenInfo(tokenId);
207 }
208 }