1 using System;
2
3
4
5 namespace MdbTokens
6 {
7 public const int END = 0;
8
9 public const int SEG = 1;
10
11 public const int REG = 2;
12
13 public const int HEX = 3;
14
15 public const int DEC = 4;
16
17 public const int ID = 5;
18
19 public const int PLUS = 6;
20
21 public const int MINUS = 7;
22
23 public const int BAR = 8;
24
25 public const int CARET = 9;
26
27 public const int AST = 10;
28
29 public const int SLASH = 11;
30
31 public const int PERCENT = 12;
32
33 public const int SHIFT_LEFT = 13;
34
35 public const int SHIFT_RIGHT = 14;
36
37 public const int AMP = 15;
38
39 public const int TILDE = 16;
40
41 public const int DOT = 17;
42
43 public const int LPAREN = 18;
44
45 public const int RPAREN = 19;
46
47 public const int PRINT = 20;
48
49 public const int TRACE = 21;
50
51 internal class TokenMap
52 {
53 static TokenMap() :
54 instance(new TokenMap())
55 {
56 }
57 public static TokenMap& Instance()
58 {
59 return *instance;
60 }
61 public int GetTokenId(const ustring& tokenName)
62 {
63 System.Collections.Map<ustring, int>.ConstIterator it = tokenIdMap.CFind(tokenName);
64 if (it != tokenIdMap.CEnd())
65 {
66 return it->second;
67 }
68 else
69 {
70 return -1;
71 }
72 }
73 public ustring GetTokenName(int tokenId)
74 {
75 return tokenNameList[tokenId];
76 }
77 public ustring GetTokenInfo(int tokenId)
78 {
79 return tokenInfoList[tokenId];
80 }
81 private TokenMap()
82 {
83 tokenIdMap[u"AMP"] = 15;
84 tokenIdMap[u"AST"] = 10;
85 tokenIdMap[u"BAR"] = 8;
86 tokenIdMap[u"CARET"] = 9;
87 tokenIdMap[u"DEC"] = 4;
88 tokenIdMap[u"DOT"] = 17;
89 tokenIdMap[u"HEX"] = 3;
90 tokenIdMap[u"ID"] = 5;
91 tokenIdMap[u"LPAREN"] = 18;
92 tokenIdMap[u"MINUS"] = 7;
93 tokenIdMap[u"PERCENT"] = 12;
94 tokenIdMap[u"PLUS"] = 6;
95 tokenIdMap[u"PRINT"] = 20;
96 tokenIdMap[u"REG"] = 2;
97 tokenIdMap[u"RPAREN"] = 19;
98 tokenIdMap[u"SEG"] = 1;
99 tokenIdMap[u"SHIFT_LEFT"] = 13;
100 tokenIdMap[u"SHIFT_RIGHT"] = 14;
101 tokenIdMap[u"SLASH"] = 11;
102 tokenIdMap[u"TILDE"] = 16;
103 tokenIdMap[u"TRACE"] = 21;
104 tokenNameList.Add(u"END");
105 tokenInfoList.Add(u"end of file");
106 tokenNameList.Add(u"SEG");
107 tokenInfoList.Add(u"seg");
108 tokenNameList.Add(u"REG");
109 tokenInfoList.Add(u"reg");
110 tokenNameList.Add(u"HEX");
111 tokenInfoList.Add(u"hex");
112 tokenNameList.Add(u"DEC");
113 tokenInfoList.Add(u"dec");
114 tokenNameList.Add(u"ID");
115 tokenInfoList.Add(u"identifier");
116 tokenNameList.Add(u"PLUS");
117 tokenInfoList.Add(u"'+'");
118 tokenNameList.Add(u"MINUS");
119 tokenInfoList.Add(u"'-'");
120 tokenNameList.Add(u"BAR");
121 tokenInfoList.Add(u"'|'");
122 tokenNameList.Add(u"CARET");
123 tokenInfoList.Add(u"'^'");
124 tokenNameList.Add(u"AST");
125 tokenInfoList.Add(u"'*'");
126 tokenNameList.Add(u"SLASH");
127 tokenInfoList.Add(u"'/'");
128 tokenNameList.Add(u"PERCENT");
129 tokenInfoList.Add(u"'%'");
130 tokenNameList.Add(u"SHIFT_LEFT");
131 tokenInfoList.Add(u"'<<'");
132 tokenNameList.Add(u"SHIFT_RIGHT");
133 tokenInfoList.Add(u"'>>'");
134 tokenNameList.Add(u"AMP");
135 tokenInfoList.Add(u"'&'");
136 tokenNameList.Add(u"TILDE");
137 tokenInfoList.Add(u"'~'");
138 tokenNameList.Add(u"DOT");
139 tokenInfoList.Add(u"'.'");
140 tokenNameList.Add(u"LPAREN");
141 tokenInfoList.Add(u"'()");
142 tokenNameList.Add(u"RPAREN");
143 tokenInfoList.Add(u"')'");
144 tokenNameList.Add(u"PRINT");
145 tokenInfoList.Add(u"print");
146 tokenNameList.Add(u"TRACE");
147 tokenInfoList.Add(u"trace");
148 }
149 private static System.UniquePtr<TokenMap> instance;
150 private System.Collections.Map<ustring, int> tokenIdMap;
151 private System.Collections.List<ustring> tokenNameList;
152 private System.Collections.List<ustring> tokenInfoList;
153 }
154 public int GetTokenId(const ustring& tokenName)
155 {
156 return TokenMap.Instance().GetTokenId(tokenName);
157 }
158
159 public ustring GetTokenName(int tokenId)
160 {
161 return TokenMap.Instance().GetTokenName(tokenId);
162 }
163
164 public ustring GetTokenInfo(int tokenId)
165 {
166 return TokenMap.Instance().GetTokenInfo(tokenId);
167 }
168 }