82 |
|
for ( ; true; ichToken += cchToken) { |
83 |
|
if (lookingAtLeadingWhitespace()) |
84 |
|
continue; |
85 |
< |
if (lookingAtComment()) |
86 |
< |
continue; |
85 |
> |
//if (lookingAtComment()) |
86 |
> |
// continue; |
87 |
|
bool endOfLine = lookingAtEndOfLine(); |
88 |
|
if (endOfLine || lookingAtEndOfStatement()) { |
89 |
|
if (tokCommand != Token::nada) { |
118 |
|
// continue; |
119 |
|
//} |
120 |
|
if (lookingAtDecimal((tokCommand & Token::negnums) != 0)) { |
121 |
< |
float value = lexi_cast<float>(script.substr(ichToken, ichToken + cchToken)); |
122 |
< |
ltoken.push_back(Token(Token::decimal, value));/**@todo*/ |
121 |
> |
float value = lexi_cast<float>(script.substr(ichToken, cchToken)); |
122 |
> |
std::cout << "encount an decimal: " << value << std::endl; |
123 |
> |
ltoken.push_back(Token(Token::decimal, boost::any(value))); |
124 |
|
continue; |
125 |
|
} |
126 |
|
if (lookingAtInteger((tokCommand & Token::negnums) != 0)) { |
127 |
< |
std::string intString = script.substr(ichToken, ichToken + cchToken); |
128 |
< |
int val = lexi_cast<int>(intString); |
129 |
< |
ltoken.push_back(Token(Token::integer, val, intString));/**@todo*/ |
127 |
> |
|
128 |
> |
int val = lexi_cast<int>(script.substr(ichToken, cchToken)); |
129 |
> |
std::cout << "encount an integer: " << val << std::endl; |
130 |
> |
ltoken.push_back(Token(Token::integer, boost::any(val))); |
131 |
|
continue; |
132 |
|
} |
133 |
|
} |
134 |
|
|
135 |
|
if (lookingAtLookupToken()) { |
136 |
< |
std::string ident = script.substr(ichToken, ichToken + cchToken); |
135 |
< |
|
136 |
> |
std::string ident = script.substr(ichToken, cchToken); |
137 |
|
Token token; |
138 |
|
Token* pToken = TokenMap::getInstance()->getToken(ident); |
139 |
|
if (pToken != NULL) { |
244 |
|
previousCharBackslash = ch == '\\' ? !previousCharBackslash : false; |
245 |
|
} |
246 |
|
cchToken = ichT - ichToken; |
247 |
+ |
|
248 |
+ |
|
249 |
+ |
std::cout << "lookingAtString: encount " << script.substr(ichToken, cchToken) << std::endl; |
250 |
|
return true; |
251 |
|
} |
252 |
|
|
423 |
|
return false; |
424 |
|
} |
425 |
|
case '?': // include question marks in identifier for atom expressions |
426 |
< |
while (ichT < cchScript && (std::isalpha(ch = script[ichT]) ||std::isdigit(ch) || |
427 |
< |
ch == '_' || ch == '?') ||(ch == '^' && ichT > ichToken && std::isdigit(script[ichT - 1]))) { |
428 |
< |
// hack for insertion codes embedded in an atom expression :-( |
425 |
< |
// select c3^a |
426 |
> |
while (ichT < cchScript && !std::isspace(ch = script[ichT]) && (std::isalpha(ch) ||std::isdigit(ch) || |
427 |
> |
ch == '_' || ch == '?') ) { |
428 |
> |
|
429 |
|
++ichT; |
430 |
|
} |
431 |
|
break; |
432 |
|
} |
433 |
+ |
|
434 |
|
cchToken = ichT - ichToken; |
435 |
+ |
|
436 |
+ |
std::cout << "lookingAtLookupToken: encount " << script.substr(ichToken, cchToken) << std::endl; |
437 |
|
return true; |
438 |
|
} |
439 |
|
|
566 |
|
switch (tok) { |
567 |
|
case Token::within: |
568 |
|
return clauseWithin(); |
569 |
< |
case Token::name : |
570 |
< |
return clauseName(Token::name); |
571 |
< |
case Token::index : |
572 |
< |
return clauseIndex(Token::index); |
573 |
< |
case Token::molname : |
574 |
< |
return clauseName(Token::molname); |
575 |
< |
case Token::molindex : |
570 |
< |
return clauseIndex(Token::molindex); |
571 |
< |
|
569 |
> |
|
570 |
> |
case Token::asterisk: |
571 |
> |
case Token::identifier: |
572 |
> |
return clauseChemObjName(); |
573 |
> |
|
574 |
> |
case Token::integer : |
575 |
> |
return clauseIndex(); |
576 |
|
default: |
577 |
|
if ((tok & Token::atomproperty) == Token::atomproperty) { |
578 |
|
return clauseComparator(); |
605 |
|
} |
606 |
|
|
607 |
|
Token tokenValue = tokenNext(); |
608 |
< |
if (tokenValue.tok != Token::integer) { |
609 |
< |
return integerExpected(); |
608 |
> |
if (tokenValue.tok != Token::integer && tokenValue.tok != Token::decimal) { |
609 |
> |
return numberExpected(); |
610 |
|
} |
611 |
< |
int val = tokenValue.intValue; |
612 |
< |
// note that a comparator instruction is a complicated instruction |
613 |
< |
// int intValue is the tok of the property you are comparing |
614 |
< |
// the value against which you are comparing is stored as an Integer |
615 |
< |
// in the object value |
611 |
> |
|
612 |
> |
float val; |
613 |
> |
if (tokenValue.value.type() == typeid(int)) { |
614 |
> |
val = boost::any_cast<int>(tokenValue.value); |
615 |
> |
} else if (tokenValue.value.type() == typeid(float)) { |
616 |
> |
val = boost::any_cast<float>(tokenValue.value); |
617 |
> |
} else { |
618 |
> |
return false; |
619 |
> |
} |
620 |
> |
|
621 |
> |
boost::any floatVal; |
622 |
> |
floatVal = val; |
623 |
|
return addTokenToPostfix(Token(tokenComparator.tok, |
624 |
< |
tokenAtomProperty.tok, boost::any(val))); |
624 |
> |
tokenAtomProperty.tok, floatVal)); |
625 |
|
} |
626 |
|
|
627 |
|
bool SelectionCompiler::clauseWithin() { |
634 |
|
Token tokenDistance = tokenNext(); // distance |
635 |
|
switch(tokenDistance.tok) { |
636 |
|
case Token::integer: |
626 |
– |
distance = float(tokenDistance.intValue); |
627 |
– |
break; |
637 |
|
case Token::decimal: |
638 |
|
distance = tokenDistance.value; |
639 |
|
break; |
656 |
|
return addTokenToPostfix(Token(Token::within, distance)); |
657 |
|
} |
658 |
|
|
659 |
+ |
bool SelectionCompiler::clauseChemObjName() { |
660 |
+ |
std::string chemObjName; |
661 |
+ |
int tok = tokPeek(); |
662 |
+ |
if (!clauseName(chemObjName)){ |
663 |
+ |
return false; |
664 |
+ |
} |
665 |
|
|
651 |
– |
bool SelectionCompiler:: clauseName(int tok) { |
652 |
– |
Token tokenName = tokenNext(); |
653 |
– |
std::string name = boost::any_cast<std::string>(tokenName.value); |
654 |
– |
return addTokenToPostfix(Token(tok, name)); /**@todo */ |
666 |
|
|
667 |
+ |
tok = tokPeek(); |
668 |
+ |
//allow two dot at most |
669 |
+ |
if (tok == Token::dot) { |
670 |
+ |
tokenNext(); |
671 |
+ |
chemObjName += "."; |
672 |
+ |
if (!clauseName(chemObjName)) { |
673 |
+ |
return false; |
674 |
+ |
} |
675 |
+ |
tok = tokPeek(); |
676 |
+ |
if (tok == Token::dot) { |
677 |
+ |
tokenNext(); |
678 |
+ |
chemObjName += "."; |
679 |
+ |
|
680 |
+ |
if (!clauseName(chemObjName)) { |
681 |
+ |
return false; |
682 |
+ |
} |
683 |
+ |
} |
684 |
+ |
} |
685 |
+ |
|
686 |
+ |
return addTokenToPostfix(Token(Token::name, chemObjName)); |
687 |
|
} |
688 |
|
|
689 |
< |
bool SelectionCompiler:: clauseIndex(int tok) { |
690 |
< |
//return addTokenToPostfix(Token(tok, )); /**@todo*/ |
691 |
< |
return true; |
689 |
> |
bool SelectionCompiler:: clauseName(std::string& name) { |
690 |
> |
|
691 |
> |
int tok = tokPeek(); |
692 |
> |
|
693 |
> |
if (tok == Token::asterisk || tok == Token::identifier) { |
694 |
> |
name += boost::any_cast<std::string>(tokenNext().value); |
695 |
> |
|
696 |
> |
while(true){ |
697 |
> |
tok = tokPeek(); |
698 |
> |
switch (tok) { |
699 |
> |
case Token::asterisk : |
700 |
> |
name += "*"; |
701 |
> |
tokenNext(); |
702 |
> |
break; |
703 |
> |
case Token::identifier : |
704 |
> |
name += boost::any_cast<std::string>(tokenNext().value); |
705 |
> |
break; |
706 |
> |
case Token::integer : |
707 |
> |
name += toString(boost::any_cast<int>(tokenNext().value)); |
708 |
> |
break; |
709 |
> |
case Token::dot : |
710 |
> |
return true; |
711 |
> |
default : |
712 |
> |
return true; |
713 |
> |
} |
714 |
> |
} |
715 |
> |
|
716 |
> |
}else { |
717 |
> |
return false; |
718 |
> |
} |
719 |
> |
|
720 |
|
} |
721 |
|
|
722 |
+ |
bool SelectionCompiler::clauseIndex(){ |
723 |
+ |
Token token = tokenNext(); |
724 |
+ |
if (token.tok == Token::integer) { |
725 |
+ |
int index = boost::any_cast<int>(token.value); |
726 |
+ |
int tok = tokPeek(); |
727 |
+ |
std::cout << "Token::to is " << Token::to << ", tok = " << tok << std::endl; |
728 |
+ |
if (tok == Token::to) { |
729 |
+ |
tokenNext(); |
730 |
+ |
tok = tokPeek(); |
731 |
+ |
if (tok != Token::integer) { |
732 |
+ |
return numberExpected(); |
733 |
+ |
} |
734 |
+ |
|
735 |
+ |
boost::any intVal = tokenNext().value; |
736 |
+ |
int first = index; |
737 |
+ |
if (intVal.type() != typeid(int)){ |
738 |
+ |
return false; |
739 |
+ |
} |
740 |
+ |
int second = boost::any_cast<int>(intVal); |
741 |
+ |
|
742 |
+ |
return addTokenToPostfix(Token(Token::index, boost::any(std::make_pair(first, second)))); |
743 |
+ |
|
744 |
+ |
}else { |
745 |
+ |
return addTokenToPostfix(Token(Token::index, boost::any(index))); |
746 |
+ |
} |
747 |
+ |
} else { |
748 |
+ |
return numberExpected(); |
749 |
+ |
} |
750 |
|
} |
751 |
+ |
|
752 |
+ |
} |