# | Line 82 | Line 82 | bool SelectionCompiler::internalCompile(){ | |
---|---|---|
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) { | |
# | Line 118 | Line 118 | bool SelectionCompiler::internalCompile(){ | |
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 | > | ltoken.push_back(Token(Token::decimal, boost::any(value))); |
123 | continue; | |
124 | } | |
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(Token(Token::integer, val, intString));/**@todo*/ |
126 | > | |
127 | > | int val = lexi_cast<int>(script.substr(ichToken, cchToken)); |
128 | > | ltoken.push_back(Token(Token::integer, boost::any(val))); |
129 | continue; | |
130 | } | |
131 | } | |
132 | ||
133 | if (lookingAtLookupToken()) { | |
134 | < | std::string ident = script.substr(ichToken, ichToken + cchToken); |
135 | < | |
134 | > | std::string ident = script.substr(ichToken, cchToken); |
135 | Token token; | |
136 | Token* pToken = TokenMap::getInstance()->getToken(ident); | |
137 | if (pToken != NULL) { | |
# | Line 243 | Line 242 | bool SelectionCompiler::internalCompile(){ | |
242 | previousCharBackslash = ch == '\\' ? !previousCharBackslash : false; | |
243 | } | |
244 | cchToken = ichT - ichToken; | |
245 | + | |
246 | return true; | |
247 | } | |
248 | ||
# | Line 340 | Line 340 | bool SelectionCompiler::lookingAtDecimal(bool allowNeg | |
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 |
345 | < | 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 | ||
# | Line 419 | Line 418 | bool SelectionCompiler::lookingAtLookupToken() { | |
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 :-( |
425 | < | // 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 | ||
# | Line 564 | Line 564 | bool SelectionCompiler::clausePrimitive() { | |
564 | case Token::asterisk: | |
565 | case Token::identifier: | |
566 | return clauseChemObjName(); | |
567 | < | |
567 | > | |
568 | > | case Token::integer : |
569 | > | return clauseIndex(); |
570 | default: | |
571 | if ((tok & Token::atomproperty) == Token::atomproperty) { | |
572 | return clauseComparator(); | |
# | Line 597 | Line 599 | bool SelectionCompiler::clauseComparator() { | |
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 |
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, boost::any(val))); |
618 | > | tokenAtomProperty.tok, floatVal)); |
619 | } | |
620 | ||
621 | bool SelectionCompiler::clauseWithin() { | |
# | Line 619 | Line 628 | bool SelectionCompiler::clauseWithin() { | |
628 | Token tokenDistance = tokenNext(); // distance | |
629 | switch(tokenDistance.tok) { | |
630 | case Token::integer: | |
622 | – | distance = float(tokenDistance.intValue); |
623 | – | break; |
631 | case Token::decimal: | |
632 | distance = tokenDistance.value; | |
633 | break; | |
# | Line 654 | Line 661 | bool SelectionCompiler::clauseChemObjName() { | |
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 | if (!clauseName(chemObjName)) { | |
675 | return false; | |
676 | } | |
# | Line 672 | Line 684 | bool SelectionCompiler:: clauseName(std::string& name) | |
684 | ||
685 | int tok = tokPeek(); | |
686 | ||
687 | < | if (tok == Token::asterisk || tok == Token::identifier) { |
688 | < | name += boost::any_cast<std::string>(tokenNext().value); |
689 | < | |
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) { | |
# | Line 701 | Line 722 | bool SelectionCompiler:: clauseName(std::string& name) | |
722 | ||
723 | } | |
724 | ||
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 | + | } |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |