49 |
|
/** |
50 |
|
* @class Token |
51 |
|
* @todo document |
52 |
+ |
* @note translate from jmol |
53 |
|
*/ |
54 |
|
class Token { |
55 |
|
|
56 |
|
public: |
57 |
|
|
58 |
+ |
static std::map<std::string, Token> tokenMap; |
59 |
+ |
|
60 |
|
int tok; |
61 |
< |
int intValue; |
61 |
> |
Object value; |
62 |
> |
int intValue = Integer.MAX_VALUE; |
63 |
> |
|
64 |
> |
Token(int tok, int intValue, Object value) { |
65 |
> |
this.tok = tok; |
66 |
> |
this.intValue = intValue; |
67 |
> |
this.value = value; |
68 |
> |
} |
69 |
> |
|
70 |
> |
Token(int tok, int intValue) { |
71 |
> |
this.tok = tok; |
72 |
> |
this.intValue = intValue; |
73 |
> |
} |
74 |
> |
|
75 |
> |
Token(int tok) { |
76 |
> |
this.tok = tok; |
77 |
> |
} |
78 |
> |
|
79 |
> |
Token(int tok, Object value) { |
80 |
> |
this.tok = tok; |
81 |
> |
this.value = value; |
82 |
> |
} |
83 |
|
|
84 |
|
const static int nada = 0; |
85 |
|
const static int identifier = 1; |
86 |
|
const static int integer = 2; |
87 |
|
const static int decimal = 3; |
88 |
|
const static int string = 4; |
89 |
< |
const static int seqcode = 5; |
90 |
< |
const static int unknown = 6; |
91 |
< |
const static int keyword = 7; |
92 |
< |
const static int whitespace = 8; |
93 |
< |
const static int comment = 9; |
94 |
< |
const static int endofline = 10; |
71 |
< |
const static int endofstatement = 11; |
89 |
> |
const static int unknown = 5; |
90 |
> |
const static int keyword = 6; |
91 |
> |
const static int whitespace = 7; |
92 |
> |
const static int comment = 8; |
93 |
> |
const static int endofline = 9; |
94 |
> |
const static int endofstatement = 10; |
95 |
|
|
96 |
|
const static int command = (1 << 8); |
97 |
|
const static int expressionCommand = (1 << 9); // expression command |
98 |
< |
const static int expression = (1 << 15); /// expression term |
98 |
> |
const static int expression = (1 << 10); /// expression term |
99 |
|
|
100 |
|
// every property is also valid in an expression context |
101 |
< |
const static int atomproperty = (1 << 16) | expression; |
101 |
> |
const static int atomproperty = (1 << 11) | expression; |
102 |
|
// every predefined is also valid in an expression context |
103 |
< |
const static int comparator = (1 << 17) | expression; |
104 |
< |
const static int predefinedset = (1 << 18) | expression; |
82 |
< |
// generally, the minus sign is used to denote atom ranges |
83 |
< |
// this property is used for the few commands which allow negative integers |
84 |
< |
const static int negnums = (1 << 21); |
85 |
< |
// for some commands the 'set' is optional |
103 |
> |
const static int comparator = (1 << 12) | expression; |
104 |
> |
const static int predefinedset = (1 << 13) | expression; |
105 |
|
|
87 |
– |
// These are unrelated |
88 |
– |
const static int varArgCount = (1 << 4); |
89 |
– |
const static int onDefault1 = (1 << 5) | 1; |
90 |
– |
|
106 |
|
// rasmol commands |
107 |
|
const static int define = command | expressionCommand |1; |
108 |
|
const static int select = command |expressionCommand |2 ; |
116 |
|
const static int opOr = expression | 4; |
117 |
|
const static int opNot = expression | 5; |
118 |
|
const static int within = expression | 6; |
119 |
< |
const static int plus = expression | 7; |
120 |
< |
const static int pick = expression | 8; |
106 |
< |
const static int asterisk = expression | 9; |
107 |
< |
const static int dot = expression | 11; |
108 |
< |
const static int leftsquare = expression | 12; |
109 |
< |
const static int rightsquare = expression | 13; |
110 |
< |
const static int colon = expression | 14; |
111 |
< |
const static int slash = expression | 15; |
119 |
> |
const static int asterisk = expression | 7; |
120 |
> |
const static int dot = expression | 8; |
121 |
|
|
122 |
|
// miguel 2005 01 01 |
123 |
|
// these are used to demark the beginning and end of expressions |
133 |
|
const static int _bondedcount = atomproperty | 6; |
134 |
|
const static int _groupID = atomproperty | 7; |
135 |
|
const static int _atomID = atomproperty | 8; |
127 |
– |
const static int _structure = atomproperty | 9; |
128 |
– |
const static int occupancy = atomproperty | 10; |
129 |
– |
const static int polymerLength= atomproperty | 11; |
136 |
|
|
137 |
|
const static int opGT = comparator | 0; |
138 |
|
const static int opGE = comparator | 1; |
145 |
|
const static int y = expression | 3; |
146 |
|
const static int z = expression | 4; |
147 |
|
const static int none = expression | 5; |
148 |
< |
|
143 |
< |
|
144 |
< |
const static Token tokenAll(all, "all"); |
145 |
< |
const static Token tokenAnd(opAnd, "and"); |
146 |
< |
const static Token tokenElemno(elemno, "elemno"); |
148 |
> |
|
149 |
|
const static Token tokenExpressionBegin(expressionBegin, "expressionBegin"); |
150 |
|
const static Token tokenExpressionEnd(expressionEnd, "expressionEnd"); |
151 |
|
|
152 |
+ |
}; |
153 |
|
|
154 |
< |
const static String[] comparatorNames = {">", ">=", "<=", "<", "=", "!="}; |
152 |
< |
const static String[] atomPropertyNames = { |
153 |
< |
"atomno", "elemno", "resno", "radius", "temperature", "model", |
154 |
< |
"_bondedcount", "_groupID", "_atomID", "_structure"}; |
154 |
> |
}; |
155 |
|
|
156 |
– |
/* |
157 |
– |
Note that the RasMol scripting language is case-insensitive. |
158 |
– |
So, the compiler turns all identifiers to lower-case before |
159 |
– |
looking up in the hash table. |
160 |
– |
Therefore, the left column of this array *must* be lower-case |
161 |
– |
*/ |
156 |
|
|
157 |
< |
const static Object[] arrayPairs = { |
157 |
> |
class TokenMap { |
158 |
> |
const static Object[] arrayPairs = { |
159 |
|
// commands |
160 |
< |
"define", new Token(define, varArgCount, "define"), |
161 |
< |
"select", new Token(select, varArgCount, "select"), |
160 |
> |
"define", new Token(define, "define"), |
161 |
> |
"select", new Token(select, "select"), |
162 |
|
// atom expressions |
163 |
|
"(", new Token(leftparen, "("), |
164 |
|
")", new Token(rightparen, ")"), |
165 |
|
"-", new Token(hyphen, "-"), |
166 |
|
"and", tokenAnd, |
172 |
– |
"&", null, |
173 |
– |
"&&", null, |
167 |
|
"or", new Token(opOr, "or"), |
175 |
– |
",", null, |
176 |
– |
"|", null, |
177 |
– |
"||", null, |
168 |
|
"not", new Token(opNot, "not"), |
179 |
– |
"!", null, |
169 |
|
"<", new Token(opLT, "<"), |
170 |
|
"<=", new Token(opLE, "<="), |
171 |
|
">=", new Token(opGE, ">="), |
172 |
|
">", new Token(opGT, ">="), |
173 |
|
"==", new Token(opEQ, "=="), |
185 |
– |
"=", null, |
174 |
|
"!=", new Token(opNE, "!="), |
187 |
– |
"<>", null, |
188 |
– |
"/=", null, |
175 |
|
"within", new Token(within, "within"), |
190 |
– |
"+", new Token(plus, "+"), |
191 |
– |
"pick", new Token(pick, "pick"), |
176 |
|
".", new Token(dot, "."), |
193 |
– |
"[", new Token(leftsquare, "["), |
194 |
– |
"]", new Token(rightsquare, "]"), |
195 |
– |
":", new Token(colon, ":"), |
196 |
– |
"/", new Token(slash, "/"), |
197 |
– |
|
177 |
|
"atomno", new Token(atomno, "atomno"), |
178 |
|
"elemno", tokenElemno, |
200 |
– |
"_e", tokenElemno, |
201 |
– |
"resno", new Token(resno, "resno"), |
202 |
– |
"temperature", new Token(temperature, "temperature"), |
203 |
– |
"relativetemperature", null, |
179 |
|
"_bondedcount", new Token(_bondedcount, "_bondedcount"), |
180 |
|
"_groupID", new Token(_groupID, "_groupID"), |
181 |
< |
"_g", null, |
207 |
< |
"_atomID", new Token(_atomID, "_atomID"), |
208 |
< |
"_a", null, |
209 |
< |
"_structure", new Token(_structure, "_structure"), |
210 |
< |
"occupancy", new Token(occupancy, "occupancy"), |
211 |
< |
"polymerlength",new Token(polymerLength, "polymerlength"), |
212 |
< |
|
181 |
> |
"_atomID", new Token(_atomID, "_atomID"), |
182 |
|
"x", new Token(x, "x"), |
183 |
|
"y", new Token(y, "y"), |
184 |
|
"z", new Token(z, "z"), |
185 |
|
"*", new Token(asterisk, "*"), |
186 |
|
"all", tokenAll, |
187 |
|
"none", new Token(none, "none"), |
219 |
– |
|
220 |
– |
}; |
188 |
|
|
222 |
– |
|
223 |
– |
static Hashtable map = new Hashtable(); |
224 |
– |
static { |
225 |
– |
Token tokenLast = null; |
226 |
– |
String stringThis; |
227 |
– |
Token tokenThis; |
228 |
– |
for (int i = 0; i + 1 < arrayPairs.length; i += 2) { |
229 |
– |
stringThis = (String) arrayPairs[i]; |
230 |
– |
tokenThis = (Token) arrayPairs[i + 1]; |
231 |
– |
if (tokenThis == null) |
232 |
– |
tokenThis = tokenLast; |
233 |
– |
if (map.get(stringThis) != null) |
234 |
– |
System.out.println("duplicate token definition:" + stringThis); |
235 |
– |
map.put(stringThis, tokenThis); |
236 |
– |
tokenLast = tokenThis; |
237 |
– |
} |
238 |
– |
} |
239 |
– |
|
240 |
– |
|
189 |
|
}; |
190 |
|
|
191 |
|
} |
192 |
|
|
193 |
< |
#endif |
193 |
> |
#endif |