1 using System;
2
3
4
5 namespace BigNumTokens
6 {
7 public const int END = 0;
8
9 public const int PLUS = 1;
10
11 public const int MINUS = 2;
12
13 public const int MUL = 3;
14
15 public const int DIV = 4;
16
17 public const int LPAREN = 5;
18
19 public const int RPAREN = 6;
20
21 public const int FLOAT = 7;
22
23 public const int RATIONAL = 8;
24
25 public const int INTEGER = 9;
26
27 internal class TokenMap
28 {
29 static TokenMap() :
30 instance(new TokenMap())
31 {
32 }
33 public static TokenMap& Instance()
34 {
35 return *instance;
36 }
37 public int GetTokenId(const ustring& tokenName)
38 {
39 System.Collections.Map<ustring, int>.ConstIterator it = tokenIdMap.CFind(tokenName);
40 if (it != tokenIdMap.CEnd())
41 {
42 return it->second;
43 }
44 else
45 {
46 return -1;
47 }
48 }
49 public ustring GetTokenName(int tokenId)
50 {
51 return tokenNameList[tokenId];
52 }
53 public ustring GetTokenInfo(int tokenId)
54 {
55 return tokenInfoList[tokenId];
56 }
57 private TokenMap()
58 {
59 tokenIdMap[u"DIV"] = 4;
60 tokenIdMap[u"FLOAT"] = 7;
61 tokenIdMap[u"INTEGER"] = 9;
62 tokenIdMap[u"LPAREN"] = 5;
63 tokenIdMap[u"MINUS"] = 2;
64 tokenIdMap[u"MUL"] = 3;
65 tokenIdMap[u"PLUS"] = 1;
66 tokenIdMap[u"RATIONAL"] = 8;
67 tokenIdMap[u"RPAREN"] = 6;
68 tokenNameList.Add(u"END");
69 tokenInfoList.Add(u"end of file");
70 tokenNameList.Add(u"PLUS");
71 tokenInfoList.Add(u"'+'");
72 tokenNameList.Add(u"MINUS");
73 tokenInfoList.Add(u"'-'");
74 tokenNameList.Add(u"MUL");
75 tokenInfoList.Add(u"'*'");
76 tokenNameList.Add(u"DIV");
77 tokenInfoList.Add(u"'/'");
78 tokenNameList.Add(u"LPAREN");
79 tokenInfoList.Add(u"'('");
80 tokenNameList.Add(u"RPAREN");
81 tokenInfoList.Add(u"')'");
82 tokenNameList.Add(u"FLOAT");
83 tokenInfoList.Add(u"'float");
84 tokenNameList.Add(u"RATIONAL");
85 tokenInfoList.Add(u"'rational'");
86 tokenNameList.Add(u"INTEGER");
87 tokenInfoList.Add(u"'integer'");
88 }
89 private static System.UniquePtr<TokenMap> instance;
90 private System.Collections.Map<ustring, int> tokenIdMap;
91 private System.Collections.List<ustring> tokenNameList;
92 private System.Collections.List<ustring> tokenInfoList;
93 }
94 public int GetTokenId(const ustring& tokenName)
95 {
96 return TokenMap.Instance().GetTokenId(tokenName);
97 }
98
99 public ustring GetTokenName(int tokenId)
100 {
101 return TokenMap.Instance().GetTokenName(tokenId);
102 }
103
104 public ustring GetTokenInfo(int tokenId)
105 {
106 return TokenMap.Instance().GetTokenInfo(tokenId);
107 }
108 }