40 |
|
*/ |
41 |
|
|
42 |
|
#include "selection/SelectionCompiler.hpp" |
43 |
+ |
#include "utils/StringUtils.hpp" |
44 |
|
namespace oopse { |
45 |
|
|
46 |
|
bool SelectionCompiler::compile(const std::string& filename, const std::string& script) { |
51 |
|
lineIndices.clear(); |
52 |
|
aatokenCompiled.clear(); |
53 |
|
|
54 |
< |
if (internalcompile()) { |
54 |
> |
if (internalCompile()) { |
55 |
|
return true; |
56 |
|
} |
57 |
|
|
58 |
|
int icharEnd; |
59 |
< |
if ((icharEnd = script.find('\r', ichCurrentCommand)) == std::string:npos && |
60 |
< |
(icharEnd = script.find('\n', ichCurrentCommand)) == std::string:npos) { |
59 |
> |
if ((icharEnd = script.find('\r', ichCurrentCommand)) == std::string::npos && |
60 |
> |
(icharEnd = script.find('\n', ichCurrentCommand)) == std::string::npos) { |
61 |
|
icharEnd = script.size(); |
62 |
|
} |
63 |
|
errorLine = script.substr(ichCurrentCommand, icharEnd); |
72 |
|
|
73 |
|
error = false; |
74 |
|
|
75 |
< |
std::vector<Token> lltoken; |
75 |
> |
//std::vector<Token> lltoken; |
76 |
> |
aatokenCompiled.clear(); |
77 |
|
std::vector<Token> ltoken; |
78 |
|
|
79 |
< |
//Token tokenCommand = null; |
80 |
< |
int tokCommand = Token.nada; |
79 |
> |
Token tokenCommand; |
80 |
> |
int tokCommand = Token::nada; |
81 |
|
|
82 |
|
for ( ; true; ichToken += cchToken) { |
83 |
|
if (lookingAtLeadingWhitespace()) |
84 |
|
continue; |
85 |
< |
if (lookingAtComment()) |
86 |
< |
continue; |
87 |
< |
boolean endOfLine = lookingAtEndOfLine(); |
85 |
> |
//if (lookingAtComment()) |
86 |
> |
// continue; |
87 |
> |
bool endOfLine = lookingAtEndOfLine(); |
88 |
|
if (endOfLine || lookingAtEndOfStatement()) { |
89 |
< |
if (tokCommand != Token.nada) { |
89 |
> |
if (tokCommand != Token::nada) { |
90 |
|
if (! compileCommand(ltoken)) { |
91 |
|
return false; |
92 |
|
} |
93 |
< |
lltoken.push_back(atokenCommand); |
94 |
< |
/** @todo*/ |
95 |
< |
int iCommand = lltoken.size(); |
96 |
< |
lineNumbers[iCommand] = lineCurrent; |
97 |
< |
lineIndices[iCommand] = (short) ichCurrentCommand; |
96 |
< |
ltoken.clear(); |
97 |
< |
tokCommand = Token.nada; |
93 |
> |
aatokenCompiled.push_back(atokenCommand); |
94 |
> |
lineNumbers.push_back(lineCurrent); |
95 |
> |
lineIndices.push_back(ichCurrentCommand); |
96 |
> |
ltoken.clear(); |
97 |
> |
tokCommand = Token::nada; |
98 |
|
} |
99 |
|
|
100 |
|
if (ichToken < cchScript) { |
105 |
|
break; |
106 |
|
} |
107 |
|
|
108 |
< |
if (tokCommand != Token.nada) { |
108 |
> |
if (tokCommand != Token::nada) { |
109 |
|
if (lookingAtString()) { |
110 |
|
std::string str = getUnescapedStringLiteral(); |
111 |
< |
ltoken.push_back(Token(Token.string, str)); |
111 |
> |
ltoken.push_back(Token(Token::string, str)); |
112 |
|
continue; |
113 |
|
} |
114 |
< |
if ((tokCommand & Token.specialstring) != 0 && |
115 |
< |
lookingAtSpecialString()) { |
116 |
< |
std::string str = script.substr(ichToken, ichToken + cchToken); |
117 |
< |
ltoken.push_back(Token(Token.string, str)); |
114 |
> |
//if ((tokCommand & Token::specialstring) != 0 && |
115 |
> |
// lookingAtSpecialString()) { |
116 |
> |
// std::string str = script.substr(ichToken, ichToken + cchToken); |
117 |
> |
// ltoken.push_back(Token(Token::string, str)); |
118 |
> |
// continue; |
119 |
> |
//} |
120 |
> |
if (lookingAtDecimal((tokCommand & Token::negnums) != 0)) { |
121 |
> |
float value = lexi_cast<float>(script.substr(ichToken, cchToken)); |
122 |
> |
ltoken.push_back(Token(Token::decimal, boost::any(value))); |
123 |
|
continue; |
124 |
|
} |
125 |
< |
if (lookingAtDecimal((tokCommand & Token.negnums) != 0)) { |
126 |
< |
float value = lexi_cast<float>((script.substr(ichToken, ichToken + cchToken)); |
127 |
< |
ltoken.push_back(Token(Token.decimal, new Float(value)));/**@todo*/ |
125 |
> |
if (lookingAtInteger((tokCommand & Token::negnums) != 0)) { |
126 |
> |
|
127 |
> |
int val = lexi_cast<int>(script.substr(ichToken, cchToken)); |
128 |
> |
ltoken.push_back(Token(Token::integer, boost::any(val))); |
129 |
|
continue; |
130 |
|
} |
125 |
– |
if (lookingAtInteger((tokCommand & Token.negnums) != 0)) { |
126 |
– |
std::string intString = script.substr(ichToken, ichToken + cchToken); |
127 |
– |
int val = lexi_cast<int>(intString); |
128 |
– |
ltoken.push_back(new Token(Token.integer, val, intString));/**@todo*/ |
129 |
– |
continue; |
130 |
– |
} |
131 |
|
} |
132 |
|
|
133 |
|
if (lookingAtLookupToken()) { |
134 |
< |
std::string ident = script.subst(ichToken, ichToken + cchToken); |
135 |
< |
|
136 |
< |
/**@todo */ |
137 |
< |
Token token = (Token) Token.map.get(ident); |
138 |
< |
if (token == NULL) { |
139 |
< |
|
134 |
> |
std::string ident = script.substr(ichToken, cchToken); |
135 |
> |
Token token; |
136 |
> |
Token* pToken = TokenMap::getInstance()->getToken(ident); |
137 |
> |
if (pToken != NULL) { |
138 |
> |
token = *pToken; |
139 |
> |
} else { |
140 |
> |
token = Token(Token::identifier, ident); |
141 |
|
} |
141 |
– |
Token token(Token.identifier, ident); |
142 |
– |
|
142 |
|
|
143 |
|
int tok = token.tok; |
144 |
|
|
145 |
|
switch (tokCommand) { |
146 |
< |
case Token.nada: |
146 |
> |
case Token::nada: |
147 |
|
ichCurrentCommand = ichToken; |
148 |
|
//tokenCommand = token; |
149 |
|
tokCommand = tok; |
150 |
< |
if ((tokCommand & Token.command) == 0) |
150 |
> |
if ((tokCommand & Token::command) == 0) |
151 |
|
return commandExpected(); |
152 |
|
break; |
153 |
|
|
154 |
< |
case Token.define: |
154 |
> |
case Token::define: |
155 |
|
if (ltoken.size() == 1) { |
156 |
|
// we are looking at the variable name |
157 |
< |
if (tok != Token.identifier && |
158 |
< |
(tok & Token.predefinedset) != Token.predefinedset) |
157 |
> |
if (tok != Token::identifier && |
158 |
> |
(tok & Token::predefinedset) != Token::predefinedset) |
159 |
|
return invalidExpressionToken(ident); |
160 |
|
} else { |
161 |
|
// we are looking at the expression |
162 |
< |
if (tok != Token.identifier && tok != Token.set && |
163 |
< |
(tok & (Token.expression | Token.predefinedset)) == 0) |
162 |
> |
if (tok != Token::identifier && |
163 |
> |
(tok & (Token::expression | Token::predefinedset)) == 0) |
164 |
|
return invalidExpressionToken(ident); |
165 |
|
} |
166 |
|
|
167 |
|
break; |
168 |
|
|
169 |
< |
case Token.select: |
170 |
< |
if (tok != Token.identifier && (tok & Token.expression) == 0) |
169 |
> |
case Token::select: |
170 |
> |
if (tok != Token::identifier && (tok & Token::expression) == 0) |
171 |
|
return invalidExpressionToken(ident); |
172 |
|
break; |
173 |
|
} |
182 |
|
return unrecognizedToken(); |
183 |
|
} |
184 |
|
|
186 |
– |
aatokenCompiled.push_back(lltoken); |
185 |
|
return true; |
186 |
|
} |
187 |
|
|
234 |
|
int ichT = ichToken + 1; |
235 |
|
// while (ichT < cchScript && script.charAt(ichT++) != chFirst) |
236 |
|
char ch; |
237 |
< |
boolean previousCharBackslash = false; |
237 |
> |
bool previousCharBackslash = false; |
238 |
|
while (ichT < cchScript) { |
239 |
< |
ch = script.[ichT++]; |
239 |
> |
ch = script[ichT++]; |
240 |
|
if (ch == '"' && !previousCharBackslash) |
241 |
|
break; |
242 |
|
previousCharBackslash = ch == '\\' ? !previousCharBackslash : false; |
243 |
|
} |
244 |
|
cchToken = ichT - ichToken; |
245 |
+ |
|
246 |
|
return true; |
247 |
|
} |
248 |
|
|
249 |
|
|
250 |
|
std::string SelectionCompiler::getUnescapedStringLiteral() { |
251 |
< |
StringBuffer sb = new StringBuffer(cchToken - 2); |
251 |
> |
/** @todo */ |
252 |
> |
std::string sb(cchToken - 2, ' '); |
253 |
> |
|
254 |
|
int ichMax = ichToken + cchToken - 1; |
255 |
|
int ich = ichToken + 1; |
256 |
|
|
293 |
|
} |
294 |
|
} |
295 |
|
} |
296 |
< |
sb.append(ch); |
296 |
> |
sb.append(1, ch); |
297 |
|
} |
298 |
|
|
299 |
< |
return "" + sb; |
299 |
> |
return sb; |
300 |
|
} |
301 |
|
|
302 |
< |
static int SelectionCompiler::getHexitValue(char ch) { |
302 |
> |
int SelectionCompiler::getHexitValue(char ch) { |
303 |
|
if (ch >= '0' && ch <= '9') |
304 |
|
return ch - '0'; |
305 |
|
else if (ch >= 'a' && ch <= 'f') |
320 |
|
return cchToken > 0; |
321 |
|
} |
322 |
|
|
323 |
< |
bool SelectionCompiler::lookingAtDecimal(boolean allowNegative) { |
323 |
> |
bool SelectionCompiler::lookingAtDecimal(bool allowNegative) { |
324 |
|
if (ichToken == cchScript) { |
325 |
|
return false; |
326 |
|
} |
329 |
|
if (script[ichT] == '-') { |
330 |
|
++ichT; |
331 |
|
} |
332 |
< |
boolean digitSeen = false; |
332 |
> |
bool digitSeen = false; |
333 |
|
char ch = 'X'; |
334 |
|
while (ichT < cchScript && std::isdigit(ch = script[ichT])) { |
335 |
|
++ichT; |
340 |
|
return false; |
341 |
|
} |
342 |
|
|
343 |
< |
// to support 1.ca, let's check the character after the dot |
344 |
< |
// to determine if it is an alpha |
344 |
< |
if (ch == '.' && (ichT + 1 < cchScript) && std::isalpha(script[ichT + 1])) { |
343 |
> |
// to support DMPC.1, let's check the character before the dot |
344 |
> |
if (ch == '.' && (ichT > 0) && std::isalpha(script[ichT - 1])) { |
345 |
|
return false; |
346 |
|
} |
347 |
|
|
354 |
|
return digitSeen; |
355 |
|
} |
356 |
|
|
357 |
< |
bool SelectionCompiler::lookingAtInteger(boolean allowNegative) { |
357 |
> |
bool SelectionCompiler::lookingAtInteger(bool allowNegative) { |
358 |
|
if (ichToken == cchScript) { |
359 |
|
return false; |
360 |
|
} |
418 |
|
return false; |
419 |
|
} |
420 |
|
case '?': // include question marks in identifier for atom expressions |
421 |
< |
while (ichT < cchScript && (std::isalpha(ch = script[ichT]) ||std::isdigit(ch) || |
422 |
< |
ch == '_' || ch == '?') ||(ch == '^' && ichT > ichToken && std::isdigit(script[ichT - 1]))) { |
423 |
< |
// hack for insertion codes embedded in an atom expression :-( |
424 |
< |
// select c3^a |
421 |
> |
while (ichT < cchScript && !std::isspace(ch = script[ichT]) && (std::isalpha(ch) ||std::isdigit(ch) || |
422 |
> |
ch == '_' || ch == '?') ) { |
423 |
> |
|
424 |
|
++ichT; |
425 |
|
} |
426 |
|
break; |
427 |
|
} |
428 |
+ |
|
429 |
|
cchToken = ichT - ichToken; |
430 |
+ |
|
431 |
|
return true; |
432 |
|
} |
433 |
|
|
434 |
< |
bool SelectionCompiler::compileCommand(Vector ltoken) { |
435 |
< |
/** todo */ |
435 |
< |
Token tokenCommand = (Token)ltoken.firstElement(); |
434 |
> |
bool SelectionCompiler::compileCommand(const std::vector<Token>& ltoken) { |
435 |
> |
const Token& tokenCommand = ltoken[0]; |
436 |
|
int tokCommand = tokenCommand.tok; |
437 |
< |
|
438 |
< |
atokenCommand = new Token[ltoken.size()]; |
439 |
< |
ltoken.copyInto(atokenCommand); |
440 |
< |
if ((tokCommand & Token.expressionCommand) != 0 && !compileExpression()) { |
437 |
> |
|
438 |
> |
atokenCommand = ltoken; |
439 |
> |
if ((tokCommand & Token::expressionCommand) != 0 && !compileExpression()) { |
440 |
|
return false; |
441 |
|
} |
442 |
+ |
|
443 |
|
return true; |
444 |
|
} |
445 |
|
|
447 |
|
/** todo */ |
448 |
|
int i = 1; |
449 |
|
int tokCommand = atokenCommand[0].tok; |
450 |
< |
if (tokCommand == Token.define) |
451 |
< |
i = 2; |
452 |
< |
else if ((tokCommand & Token.embeddedExpression) != 0) { |
453 |
< |
// look for the open parenthesis |
454 |
< |
while (i < atokenCommand.length && |
455 |
< |
atokenCommand[i].tok != Token.leftparen) |
450 |
> |
if (tokCommand == Token::define) { |
451 |
> |
i = 2; |
452 |
> |
} else if ((tokCommand & Token::embeddedExpression) != 0) { |
453 |
> |
// look for the open parenthesis |
454 |
> |
while (i < atokenCommand.size() && |
455 |
> |
atokenCommand[i].tok != Token::leftparen) |
456 |
|
++i; |
457 |
|
} |
458 |
< |
if (i >= atokenCommand.length) |
459 |
< |
return true; |
458 |
> |
|
459 |
> |
if (i >= atokenCommand.size()) { |
460 |
> |
return true; |
461 |
> |
} |
462 |
|
return compileExpression(i); |
463 |
|
} |
464 |
|
|
465 |
|
|
466 |
< |
bool SelectionCompiler::addTokenToPostfix(Token token) { |
466 |
> |
bool SelectionCompiler::addTokenToPostfix(const Token& token) { |
467 |
|
ltokenPostfix.push_back(token); |
468 |
|
return true; |
469 |
|
} |
470 |
|
|
471 |
|
bool SelectionCompiler::compileExpression(int itoken) { |
472 |
< |
ltokenPostfix = new Vector(); |
473 |
< |
for (int i = 0; i < itoken; ++i) |
472 |
> |
ltokenPostfix.clear(); |
473 |
> |
for (int i = 0; i < itoken; ++i) { |
474 |
|
addTokenToPostfix(atokenCommand[i]); |
475 |
< |
|
475 |
> |
} |
476 |
> |
|
477 |
|
atokenInfix = atokenCommand; |
478 |
|
itokenInfix = itoken; |
479 |
|
|
480 |
< |
addTokenToPostfix(Token.tokenExpressionBegin); |
480 |
> |
addTokenToPostfix(Token::tokenExpressionBegin); |
481 |
|
if (!clauseOr()) { |
482 |
|
return false; |
483 |
|
} |
484 |
|
|
485 |
< |
addTokenToPostfix(Token.tokenExpressionEnd); |
486 |
< |
if (itokenInfix != atokenInfix.length) { |
485 |
> |
addTokenToPostfix(Token::tokenExpressionEnd); |
486 |
> |
if (itokenInfix != atokenInfix.size()) { |
487 |
|
return endOfExpressionExpected(); |
488 |
|
} |
489 |
|
|
492 |
|
} |
493 |
|
|
494 |
|
Token SelectionCompiler::tokenNext() { |
495 |
< |
if (itokenInfix == atokenInfix.length) |
496 |
< |
return null; |
497 |
< |
return atokenInfix[itokenInfix++]; |
495 |
> |
if (itokenInfix == atokenInfix.size()) { |
496 |
> |
return Token(); |
497 |
> |
} |
498 |
> |
return atokenInfix[itokenInfix++]; |
499 |
|
} |
500 |
|
|
501 |
< |
Object SelectionCompiler::valuePeek() { |
502 |
< |
if (itokenInfix == atokenInfix.length) { |
503 |
< |
return null; |
501 |
> |
boost::any SelectionCompiler::valuePeek() { |
502 |
> |
if (itokenInfix == atokenInfix.size()) { |
503 |
> |
return boost::any(); |
504 |
|
} else { |
505 |
|
return atokenInfix[itokenInfix].value; |
506 |
|
} |
507 |
|
} |
508 |
|
|
509 |
|
int SelectionCompiler::tokPeek() { |
510 |
< |
if (itokenInfix == atokenInfix.length) { |
510 |
> |
if (itokenInfix == atokenInfix.size()) { |
511 |
|
return 0; |
512 |
|
}else { |
513 |
|
return atokenInfix[itokenInfix].tok; |
519 |
|
return false; |
520 |
|
} |
521 |
|
|
522 |
< |
while (tokPeek() == Token.opOr) { |
522 |
> |
while (tokPeek() == Token::opOr) { |
523 |
|
Token tokenOr = tokenNext(); |
524 |
|
if (!clauseAnd()) { |
525 |
|
return false; |
534 |
|
return false; |
535 |
|
} |
536 |
|
|
537 |
< |
while (tokPeek() == Token.opAnd) { |
537 |
> |
while (tokPeek() == Token::opAnd) { |
538 |
|
Token tokenAnd = tokenNext(); |
539 |
|
if (!clauseNot()) { |
540 |
|
return false; |
545 |
|
} |
546 |
|
|
547 |
|
bool SelectionCompiler::clauseNot() { |
548 |
< |
if (tokPeek() == Token.opNot) { |
548 |
> |
if (tokPeek() == Token::opNot) { |
549 |
|
Token tokenNot = tokenNext(); |
550 |
|
if (!clauseNot()) { |
551 |
|
return false; |
558 |
|
bool SelectionCompiler::clausePrimitive() { |
559 |
|
int tok = tokPeek(); |
560 |
|
switch (tok) { |
561 |
< |
case Token.within: |
561 |
> |
case Token::within: |
562 |
|
return clauseWithin(); |
563 |
< |
case Token.hyphen: // selecting a negative residue spec |
564 |
< |
case Token.integer: |
565 |
< |
case Token.seqcode: |
566 |
< |
case Token.asterisk: |
567 |
< |
case Token.leftsquare: |
568 |
< |
case Token.identifier: |
569 |
< |
case Token.x: |
566 |
< |
case Token.y: |
567 |
< |
case Token.z: |
568 |
< |
case Token.colon: |
569 |
< |
return clauseResidueSpec(); |
563 |
> |
|
564 |
> |
case Token::asterisk: |
565 |
> |
case Token::identifier: |
566 |
> |
return clauseChemObjName(); |
567 |
> |
|
568 |
> |
case Token::integer : |
569 |
> |
return clauseIndex(); |
570 |
|
default: |
571 |
< |
if ((tok & Token.atomproperty) == Token.atomproperty) { |
571 |
> |
if ((tok & Token::atomproperty) == Token::atomproperty) { |
572 |
|
return clauseComparator(); |
573 |
|
} |
574 |
< |
if ((tok & Token.predefinedset) != Token.predefinedset) { |
574 |
> |
if ((tok & Token::predefinedset) != Token::predefinedset) { |
575 |
|
break; |
576 |
|
} |
577 |
|
// fall into the code and below and just add the token |
578 |
< |
case Token.all: |
579 |
< |
case Token.none: |
578 |
> |
case Token::all: |
579 |
> |
case Token::none: |
580 |
|
return addTokenToPostfix(tokenNext()); |
581 |
< |
case Token.leftparen: |
581 |
> |
case Token::leftparen: |
582 |
|
tokenNext(); |
583 |
|
if (!clauseOr()) { |
584 |
|
return false; |
585 |
|
} |
586 |
< |
if (tokenNext().tok != Token.rightparen) { |
586 |
> |
if (tokenNext().tok != Token::rightparen) { |
587 |
|
return rightParenthesisExpected(); |
588 |
|
} |
589 |
|
return true; |
594 |
|
bool SelectionCompiler::clauseComparator() { |
595 |
|
Token tokenAtomProperty = tokenNext(); |
596 |
|
Token tokenComparator = tokenNext(); |
597 |
< |
if ((tokenComparator.tok & Token.comparator) == 0) { |
597 |
> |
if ((tokenComparator.tok & Token::comparator) == 0) { |
598 |
|
return comparisonOperatorExpected(); |
599 |
|
} |
600 |
|
|
601 |
|
Token tokenValue = tokenNext(); |
602 |
< |
if (tokenValue.tok != Token.integer) { |
603 |
< |
return integerExpected(); |
602 |
> |
if (tokenValue.tok != Token::integer && tokenValue.tok != Token::decimal) { |
603 |
> |
return numberExpected(); |
604 |
|
} |
605 |
< |
int val = tokenValue.intValue; |
606 |
< |
// note that a comparator instruction is a complicated instruction |
607 |
< |
// int intValue is the tok of the property you are comparing |
608 |
< |
// the value against which you are comparing is stored as an Integer |
609 |
< |
// in the object value |
610 |
< |
return addTokenToPostfix(new Token(tokenComparator.tok, |
611 |
< |
tokenAtomProperty.tok, |
612 |
< |
new Integer(val))); |
605 |
> |
|
606 |
> |
float val; |
607 |
> |
if (tokenValue.value.type() == typeid(int)) { |
608 |
> |
val = boost::any_cast<int>(tokenValue.value); |
609 |
> |
} else if (tokenValue.value.type() == typeid(float)) { |
610 |
> |
val = boost::any_cast<float>(tokenValue.value); |
611 |
> |
} else { |
612 |
> |
return false; |
613 |
> |
} |
614 |
> |
|
615 |
> |
boost::any floatVal; |
616 |
> |
floatVal = val; |
617 |
> |
return addTokenToPostfix(Token(tokenComparator.tok, |
618 |
> |
tokenAtomProperty.tok, floatVal)); |
619 |
|
} |
620 |
|
|
621 |
|
bool SelectionCompiler::clauseWithin() { |
622 |
|
tokenNext(); // WITHIN |
623 |
< |
if (tokenNext().tok != Token.leftparen) { // ( |
623 |
> |
if (tokenNext().tok != Token::leftparen) { // ( |
624 |
|
return leftParenthesisExpected(); |
625 |
|
} |
626 |
|
|
627 |
< |
Object distance; |
627 |
> |
boost::any distance; |
628 |
|
Token tokenDistance = tokenNext(); // distance |
629 |
|
switch(tokenDistance.tok) { |
630 |
< |
case Token.integer: |
631 |
< |
distance = new Float((tokenDistance.intValue * 4) / 1000f); |
626 |
< |
break; |
627 |
< |
case Token.decimal: |
630 |
> |
case Token::integer: |
631 |
> |
case Token::decimal: |
632 |
|
distance = tokenDistance.value; |
633 |
|
break; |
634 |
|
default: |
635 |
|
return numberOrKeywordExpected(); |
636 |
|
} |
637 |
|
|
638 |
< |
if (tokenNext().tok != Token.opOr) { // , |
638 |
> |
if (tokenNext().tok != Token::opOr) { // , |
639 |
|
return commaExpected(); |
640 |
|
} |
641 |
|
|
643 |
|
return false; |
644 |
|
} |
645 |
|
|
646 |
< |
if (tokenNext().tok != Token.rightparen) { // )T |
646 |
> |
if (tokenNext().tok != Token::rightparen) { // )T |
647 |
|
return rightParenthesisExpected(); |
648 |
|
} |
649 |
|
|
650 |
< |
return addTokenToPostfix(new Token(Token.within, distance)); |
650 |
> |
return addTokenToPostfix(Token(Token::within, distance)); |
651 |
|
} |
652 |
|
|
653 |
< |
bool SelectionCompiler:: clauseChemObject() { |
654 |
< |
} |
653 |
> |
bool SelectionCompiler::clauseChemObjName() { |
654 |
> |
std::string chemObjName; |
655 |
> |
int tok = tokPeek(); |
656 |
> |
if (!clauseName(chemObjName)){ |
657 |
> |
return false; |
658 |
> |
} |
659 |
|
|
652 |
– |
bool SelectionCompiler:: clauseMolecule() { |
653 |
– |
} |
660 |
|
|
661 |
< |
bool SelectionCompiler:: clauseMolName() { |
662 |
< |
} |
661 |
> |
tok = tokPeek(); |
662 |
> |
//allow two dot at most |
663 |
> |
if (tok == Token::dot) { |
664 |
> |
tokenNext(); |
665 |
> |
chemObjName += "."; |
666 |
> |
if (!clauseName(chemObjName)) { |
667 |
> |
return false; |
668 |
> |
} |
669 |
> |
tok = tokPeek(); |
670 |
> |
if (tok == Token::dot) { |
671 |
> |
tokenNext(); |
672 |
> |
chemObjName += "."; |
673 |
|
|
674 |
< |
bool SelectionCompiler:: clauseMolIndex() { |
675 |
< |
} |
674 |
> |
if (!clauseName(chemObjName)) { |
675 |
> |
return false; |
676 |
> |
} |
677 |
> |
} |
678 |
> |
} |
679 |
|
|
680 |
< |
bool SelectionCompiler:: clauseName() { |
680 |
> |
return addTokenToPostfix(Token(Token::name, chemObjName)); |
681 |
|
} |
682 |
|
|
683 |
< |
bool SelectionCompiler:: clauseIndex() { |
665 |
< |
} |
683 |
> |
bool SelectionCompiler:: clauseName(std::string& name) { |
684 |
|
|
685 |
< |
bool SelectionCompiler:: clauseStuntDoubleName() { |
685 |
> |
int tok = tokPeek(); |
686 |
> |
|
687 |
> |
if (tok == Token::asterisk || tok == Token::identifier || tok == Token::integer) { |
688 |
> |
|
689 |
> |
Token token = tokenNext(); |
690 |
> |
if (token.value.type() == typeid(std::string)) { |
691 |
> |
name += boost::any_cast<std::string>(token.value); |
692 |
> |
} else if (token.value.type() == typeid(int)){ |
693 |
> |
int intVal = boost::any_cast<int>(token.value); |
694 |
> |
char buffer[255]; |
695 |
> |
sprintf(buffer,"%d", intVal); |
696 |
> |
name += buffer; /** @todo */ |
697 |
> |
//name += toString<int>(intVal); |
698 |
> |
} |
699 |
> |
while(true){ |
700 |
> |
tok = tokPeek(); |
701 |
> |
switch (tok) { |
702 |
> |
case Token::asterisk : |
703 |
> |
name += "*"; |
704 |
> |
tokenNext(); |
705 |
> |
break; |
706 |
> |
case Token::identifier : |
707 |
> |
name += boost::any_cast<std::string>(tokenNext().value); |
708 |
> |
break; |
709 |
> |
case Token::integer : |
710 |
> |
name += toString(boost::any_cast<int>(tokenNext().value)); |
711 |
> |
break; |
712 |
> |
case Token::dot : |
713 |
> |
return true; |
714 |
> |
default : |
715 |
> |
return true; |
716 |
> |
} |
717 |
> |
} |
718 |
> |
|
719 |
> |
}else { |
720 |
> |
return false; |
721 |
> |
} |
722 |
> |
|
723 |
|
} |
724 |
|
|
725 |
< |
bool SelectionCompiler:: clauseStuntDoubleIndex() { |
725 |
> |
bool SelectionCompiler::clauseIndex(){ |
726 |
> |
Token token = tokenNext(); |
727 |
> |
if (token.tok == Token::integer) { |
728 |
> |
int index = boost::any_cast<int>(token.value); |
729 |
> |
int tok = tokPeek(); |
730 |
> |
std::cout << "Token::to is " << Token::to << ", tok = " << tok << std::endl; |
731 |
> |
if (tok == Token::to) { |
732 |
> |
tokenNext(); |
733 |
> |
tok = tokPeek(); |
734 |
> |
if (tok != Token::integer) { |
735 |
> |
return numberExpected(); |
736 |
> |
} |
737 |
> |
|
738 |
> |
boost::any intVal = tokenNext().value; |
739 |
> |
int first = index; |
740 |
> |
if (intVal.type() != typeid(int)){ |
741 |
> |
return false; |
742 |
> |
} |
743 |
> |
int second = boost::any_cast<int>(intVal); |
744 |
> |
|
745 |
> |
return addTokenToPostfix(Token(Token::index, boost::any(std::make_pair(first, second)))); |
746 |
> |
|
747 |
> |
}else { |
748 |
> |
return addTokenToPostfix(Token(Token::index, boost::any(index))); |
749 |
> |
} |
750 |
> |
} else { |
751 |
> |
return numberExpected(); |
752 |
> |
} |
753 |
|
} |
754 |
|
|
755 |
|
} |