# | 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 | > | 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) { | |
# | Line 243 | Line 244 | bool SelectionCompiler::internalCompile(){ | |
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 | ||
# | Line 340 | Line 344 | bool SelectionCompiler::lookingAtDecimal(bool allowNeg | |
344 | return false; | |
345 | } | |
346 | ||
347 | < | // to support 1.ca, let's check the character after the dot |
348 | < | // to determine if it is an alpha |
345 | < | if (ch == '.' && (ichT + 1 < cchScript) && std::isalpha(script[ichT + 1])) { |
347 | > | // to support DMPC.1, let's check the character before the dot |
348 | > | if (ch == '.' && (ichT > 0) && std::isalpha(script[ichT - 1])) { |
349 | return false; | |
350 | } | |
351 | ||
# | Line 419 | Line 422 | bool SelectionCompiler::lookingAtLookupToken() { | |
422 | return false; | |
423 | } | |
424 | case '?': // include question marks in identifier for atom expressions | |
425 | < | while (ichT < cchScript && (std::isalpha(ch = script[ichT]) ||std::isdigit(ch) || |
426 | < | ch == '_' || ch == '?') ||(ch == '^' && ichT > ichToken && std::isdigit(script[ichT - 1]))) { |
427 | < | // hack for insertion codes embedded in an atom expression :-( |
425 | < | // select c3^a |
425 | > | while (ichT < cchScript && !std::isspace(ch = script[ichT]) && (std::isalpha(ch) ||std::isdigit(ch) || |
426 | > | ch == '_' || ch == '?') ) { |
427 | > | |
428 | ++ichT; | |
429 | } | |
430 | break; | |
431 | } | |
432 | + | |
433 | cchToken = ichT - ichToken; | |
434 | + | |
435 | + | std::cout << "lookingAtLookupToken: encount " << script.substr(ichToken, cchToken) << std::endl; |
436 | return true; | |
437 | } | |
438 | ||
# | Line 560 | Line 565 | bool SelectionCompiler::clausePrimitive() { | |
565 | switch (tok) { | |
566 | case Token::within: | |
567 | return clauseWithin(); | |
568 | < | case Token::name : |
569 | < | return clauseName(Token::name); |
570 | < | case Token::index : |
571 | < | return clauseIndex(Token::index); |
572 | < | case Token::molname : |
573 | < | return clauseName(Token::molname); |
574 | < | case Token::molindex : |
570 | < | return clauseIndex(Token::molindex); |
571 | < | |
568 | > | |
569 | > | case Token::asterisk: |
570 | > | case Token::identifier: |
571 | > | return clauseChemObjName(); |
572 | > | |
573 | > | case Token::integer : |
574 | > | return clauseIndex(); |
575 | default: | |
576 | if ((tok & Token::atomproperty) == Token::atomproperty) { | |
577 | return clauseComparator(); | |
# | Line 601 | Line 604 | bool SelectionCompiler::clauseComparator() { | |
604 | } | |
605 | ||
606 | Token tokenValue = tokenNext(); | |
607 | < | if (tokenValue.tok != Token::integer) { |
608 | < | return integerExpected(); |
607 | > | if (tokenValue.tok != Token::integer && tokenValue.tok != Token::decimal) { |
608 | > | return numberExpected(); |
609 | } | |
610 | < | int val = tokenValue.intValue; |
611 | < | // note that a comparator instruction is a complicated instruction |
612 | < | // int intValue is the tok of the property you are comparing |
613 | < | // the value against which you are comparing is stored as an Integer |
614 | < | // in the object value |
610 | > | |
611 | > | float val; |
612 | > | if (tokenValue.value.type() == typeid(int)) { |
613 | > | val = boost::any_cast<int>(tokenValue.value); |
614 | > | } else if (tokenValue.value.type() == typeid(float)) { |
615 | > | val = boost::any_cast<float>(tokenValue.value); |
616 | > | } else { |
617 | > | return false; |
618 | > | } |
619 | > | |
620 | > | boost::any floatVal; |
621 | > | floatVal = val; |
622 | return addTokenToPostfix(Token(tokenComparator.tok, | |
623 | < | tokenAtomProperty.tok, boost::any(val))); |
623 | > | tokenAtomProperty.tok, floatVal)); |
624 | } | |
625 | ||
626 | bool SelectionCompiler::clauseWithin() { | |
# | Line 623 | Line 633 | bool SelectionCompiler::clauseWithin() { | |
633 | Token tokenDistance = tokenNext(); // distance | |
634 | switch(tokenDistance.tok) { | |
635 | case Token::integer: | |
626 | – | distance = float(tokenDistance.intValue); |
627 | – | break; |
636 | case Token::decimal: | |
637 | distance = tokenDistance.value; | |
638 | break; | |
# | Line 647 | Line 655 | bool SelectionCompiler::clauseWithin() { | |
655 | return addTokenToPostfix(Token(Token::within, distance)); | |
656 | } | |
657 | ||
658 | + | bool SelectionCompiler::clauseChemObjName() { |
659 | + | std::string chemObjName; |
660 | + | int tok = tokPeek(); |
661 | + | if (!clauseName(chemObjName)){ |
662 | + | return false; |
663 | + | } |
664 | ||
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 */ |
665 | ||
666 | + | tok = tokPeek(); |
667 | + | //allow two dot at most |
668 | + | if (tok == Token::dot) { |
669 | + | tokenNext(); |
670 | + | chemObjName += "."; |
671 | + | if (!clauseName(chemObjName)) { |
672 | + | return false; |
673 | + | } |
674 | + | tok = tokPeek(); |
675 | + | if (tok == Token::dot) { |
676 | + | tokenNext(); |
677 | + | chemObjName += "."; |
678 | + | |
679 | + | if (!clauseName(chemObjName)) { |
680 | + | return false; |
681 | + | } |
682 | + | } |
683 | + | } |
684 | + | |
685 | + | return addTokenToPostfix(Token(Token::name, chemObjName)); |
686 | } | |
687 | ||
688 | < | bool SelectionCompiler:: clauseIndex(int tok) { |
689 | < | //return addTokenToPostfix(Token(tok, )); /**@todo*/ |
690 | < | return true; |
688 | > | bool SelectionCompiler:: clauseName(std::string& name) { |
689 | > | |
690 | > | int tok = tokPeek(); |
691 | > | |
692 | > | if (tok == Token::asterisk || tok == Token::identifier || tok == Token::integer) { |
693 | > | |
694 | > | Token token = tokenNext(); |
695 | > | if (token.value.type() == typeid(std::string)) { |
696 | > | name += boost::any_cast<std::string>(token.value); |
697 | > | } else if (token.value.type() == typeid(int)){ |
698 | > | int intVal = boost::any_cast<int>(token.value); |
699 | > | char buffer[255]; |
700 | > | sprintf(buffer,"%d", intVal); |
701 | > | name += buffer; /** @todo */ |
702 | > | //name += toString<int>(intVal); |
703 | > | } |
704 | > | while(true){ |
705 | > | tok = tokPeek(); |
706 | > | switch (tok) { |
707 | > | case Token::asterisk : |
708 | > | name += "*"; |
709 | > | tokenNext(); |
710 | > | break; |
711 | > | case Token::identifier : |
712 | > | name += boost::any_cast<std::string>(tokenNext().value); |
713 | > | break; |
714 | > | case Token::integer : |
715 | > | name += toString(boost::any_cast<int>(tokenNext().value)); |
716 | > | break; |
717 | > | case Token::dot : |
718 | > | return true; |
719 | > | default : |
720 | > | return true; |
721 | > | } |
722 | > | } |
723 | > | |
724 | > | }else { |
725 | > | return false; |
726 | > | } |
727 | > | |
728 | } | |
729 | ||
730 | + | bool SelectionCompiler::clauseIndex(){ |
731 | + | Token token = tokenNext(); |
732 | + | if (token.tok == Token::integer) { |
733 | + | int index = boost::any_cast<int>(token.value); |
734 | + | int tok = tokPeek(); |
735 | + | std::cout << "Token::to is " << Token::to << ", tok = " << tok << std::endl; |
736 | + | if (tok == Token::to) { |
737 | + | tokenNext(); |
738 | + | tok = tokPeek(); |
739 | + | if (tok != Token::integer) { |
740 | + | return numberExpected(); |
741 | + | } |
742 | + | |
743 | + | boost::any intVal = tokenNext().value; |
744 | + | int first = index; |
745 | + | if (intVal.type() != typeid(int)){ |
746 | + | return false; |
747 | + | } |
748 | + | int second = boost::any_cast<int>(intVal); |
749 | + | |
750 | + | return addTokenToPostfix(Token(Token::index, boost::any(std::make_pair(first, second)))); |
751 | + | |
752 | + | }else { |
753 | + | return addTokenToPostfix(Token(Token::index, boost::any(index))); |
754 | + | } |
755 | + | } else { |
756 | + | return numberExpected(); |
757 | + | } |
758 | } | |
759 | + | |
760 | + | } |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |