1 |
/* |
2 |
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 |
* |
4 |
* The University of Notre Dame grants you ("Licensee") a |
5 |
* non-exclusive, royalty free, license to use, modify and |
6 |
* redistribute this software in source and binary code form, provided |
7 |
* that the following conditions are met: |
8 |
* |
9 |
* 1. Acknowledgement of the program authors must be made in any |
10 |
* publication of scientific results based in part on use of the |
11 |
* program. An acceptable form of acknowledgement is citation of |
12 |
* the article in which the program was described (Matthew |
13 |
* A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
14 |
* J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
15 |
* Parallel Simulation Engine for Molecular Dynamics," |
16 |
* J. Comput. Chem. 26, pp. 252-271 (2005)) |
17 |
* |
18 |
* 2. Redistributions of source code must retain the above copyright |
19 |
* notice, this list of conditions and the following disclaimer. |
20 |
* |
21 |
* 3. Redistributions in binary form must reproduce the above copyright |
22 |
* notice, this list of conditions and the following disclaimer in the |
23 |
* documentation and/or other materials provided with the |
24 |
* distribution. |
25 |
* |
26 |
* This software is provided "AS IS," without a warranty of any |
27 |
* kind. All express or implied conditions, representations and |
28 |
* warranties, including any implied warranty of merchantability, |
29 |
* fitness for a particular purpose or non-infringement, are hereby |
30 |
* excluded. The University of Notre Dame and its licensors shall not |
31 |
* be liable for any damages suffered by licensee as a result of |
32 |
* using, modifying or distributing the software or its |
33 |
* derivatives. In no event will the University of Notre Dame or its |
34 |
* licensors be liable for any lost revenue, profit or data, or for |
35 |
* direct, indirect, special, consequential, incidental or punitive |
36 |
* damages, however caused and regardless of the theory of liability, |
37 |
* arising out of the use of or inability to use software, even if the |
38 |
* University of Notre Dame has been advised of the possibility of |
39 |
* such damages. |
40 |
*/ |
41 |
|
42 |
#ifndef SELECTION_TOKEN_HPP |
43 |
#define SELECTION_TOKEN_HPP |
44 |
|
45 |
|
46 |
namespace oopse { |
47 |
|
48 |
|
49 |
/** |
50 |
* @class Token |
51 |
* @todo document |
52 |
*/ |
53 |
class Token { |
54 |
|
55 |
public: |
56 |
|
57 |
int tok; |
58 |
int intValue; |
59 |
|
60 |
const static int nada = 0; |
61 |
const static int identifier = 1; |
62 |
const static int integer = 2; |
63 |
const static int decimal = 3; |
64 |
const static int string = 4; |
65 |
const static int seqcode = 5; |
66 |
const static int unknown = 6; |
67 |
const static int keyword = 7; |
68 |
const static int whitespace = 8; |
69 |
const static int comment = 9; |
70 |
const static int endofline = 10; |
71 |
const static int endofstatement = 11; |
72 |
|
73 |
const static int command = (1 << 8); |
74 |
const static int expressionCommand = (1 << 9); // expression command |
75 |
const static int expression = (1 << 15); /// expression term |
76 |
|
77 |
// every property is also valid in an expression context |
78 |
const static int atomproperty = (1 << 16) | expression; |
79 |
// every predefined is also valid in an expression context |
80 |
const static int comparator = (1 << 17) | expression; |
81 |
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 |
86 |
|
87 |
// These are unrelated |
88 |
const static int varArgCount = (1 << 4); |
89 |
const static int onDefault1 = (1 << 5) | 1; |
90 |
|
91 |
// rasmol commands |
92 |
const static int define = command | expressionCommand |1; |
93 |
const static int select = command |expressionCommand |2 ; |
94 |
const static int all = expression | 11 ; |
95 |
|
96 |
// atom expression operators |
97 |
const static int leftparen = expression | 0; |
98 |
const static int rightparen = expression | 1; |
99 |
const static int hyphen = expression | 2; |
100 |
const static int opAnd = expression | 3; |
101 |
const static int opOr = expression | 4; |
102 |
const static int opNot = expression | 5; |
103 |
const static int within = expression | 6; |
104 |
const static int plus = expression | 7; |
105 |
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; |
112 |
|
113 |
// miguel 2005 01 01 |
114 |
// these are used to demark the beginning and end of expressions |
115 |
// they do not exist in the source code, but are emitted by the |
116 |
// expression compiler |
117 |
const static int expressionBegin = expression | 100; |
118 |
const static int expressionEnd = expression | 101; |
119 |
|
120 |
const static int atomno = atomproperty | 0; |
121 |
const static int elemno = atomproperty | 1; |
122 |
const static int resno = atomproperty | 2; |
123 |
const static int radius = atomproperty | 3 ; |
124 |
const static int _bondedcount = atomproperty | 6; |
125 |
const static int _groupID = atomproperty | 7; |
126 |
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; |
130 |
|
131 |
const static int opGT = comparator | 0; |
132 |
const static int opGE = comparator | 1; |
133 |
const static int opLE = comparator | 2; |
134 |
const static int opLT = comparator | 3; |
135 |
const static int opEQ = comparator | 4; |
136 |
const static int opNE = comparator | 5; |
137 |
|
138 |
const static int x = expression |2; |
139 |
const static int y = expression | 3; |
140 |
const static int z = expression | 4; |
141 |
const static int none = expression | 5; |
142 |
|
143 |
|
144 |
const static Token tokenAll(all, "all"); |
145 |
const static Token tokenAnd(opAnd, "and"); |
146 |
const static Token tokenElemno(elemno, "elemno"); |
147 |
const static Token tokenExpressionBegin(expressionBegin, "expressionBegin"); |
148 |
const static Token tokenExpressionEnd(expressionEnd, "expressionEnd"); |
149 |
|
150 |
|
151 |
const static String[] comparatorNames = {">", ">=", "<=", "<", "=", "!="}; |
152 |
const static String[] atomPropertyNames = { |
153 |
"atomno", "elemno", "resno", "radius", "temperature", "model", |
154 |
"_bondedcount", "_groupID", "_atomID", "_structure"}; |
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 |
*/ |
162 |
|
163 |
const static Object[] arrayPairs = { |
164 |
// commands |
165 |
"define", new Token(define, varArgCount, "define"), |
166 |
"select", new Token(select, varArgCount, "select"), |
167 |
// atom expressions |
168 |
"(", new Token(leftparen, "("), |
169 |
")", new Token(rightparen, ")"), |
170 |
"-", new Token(hyphen, "-"), |
171 |
"and", tokenAnd, |
172 |
"&", null, |
173 |
"&&", null, |
174 |
"or", new Token(opOr, "or"), |
175 |
",", null, |
176 |
"|", null, |
177 |
"||", null, |
178 |
"not", new Token(opNot, "not"), |
179 |
"!", null, |
180 |
"<", new Token(opLT, "<"), |
181 |
"<=", new Token(opLE, "<="), |
182 |
">=", new Token(opGE, ">="), |
183 |
">", new Token(opGT, ">="), |
184 |
"==", new Token(opEQ, "=="), |
185 |
"=", null, |
186 |
"!=", new Token(opNE, "!="), |
187 |
"<>", null, |
188 |
"/=", null, |
189 |
"within", new Token(within, "within"), |
190 |
"+", new Token(plus, "+"), |
191 |
"pick", new Token(pick, "pick"), |
192 |
".", new Token(dot, "."), |
193 |
"[", new Token(leftsquare, "["), |
194 |
"]", new Token(rightsquare, "]"), |
195 |
":", new Token(colon, ":"), |
196 |
"/", new Token(slash, "/"), |
197 |
|
198 |
"atomno", new Token(atomno, "atomno"), |
199 |
"elemno", tokenElemno, |
200 |
"_e", tokenElemno, |
201 |
"resno", new Token(resno, "resno"), |
202 |
"temperature", new Token(temperature, "temperature"), |
203 |
"relativetemperature", null, |
204 |
"_bondedcount", new Token(_bondedcount, "_bondedcount"), |
205 |
"_groupID", new Token(_groupID, "_groupID"), |
206 |
"_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 |
|
213 |
"x", new Token(x, "x"), |
214 |
"y", new Token(y, "y"), |
215 |
"z", new Token(z, "z"), |
216 |
"*", new Token(asterisk, "*"), |
217 |
"all", tokenAll, |
218 |
"none", new Token(none, "none"), |
219 |
|
220 |
}; |
221 |
|
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 |
|
241 |
}; |
242 |
|
243 |
} |
244 |
|
245 |
#endif |