ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/selection/SelectionCompiler.cpp
(Generate patch)

Comparing trunk/src/selection/SelectionCompiler.cpp (file contents):
Revision 295 by tim, Mon Feb 7 19:13:18 2005 UTC vs.
Revision 452 by tim, Tue Apr 5 23:09:48 2005 UTC

# Line 119 | Line 119 | bool SelectionCompiler::internalCompile(){
119              //}
120              if (lookingAtDecimal((tokCommand & Token::negnums) != 0)) {
121                  float value = lexi_cast<float>(script.substr(ichToken, cchToken));        
122                std::cout << "encount an decimal: " << value << std::endl;
122                  ltoken.push_back(Token(Token::decimal, boost::any(value)));
123                  continue;
124              }
125              if (lookingAtInteger((tokCommand & Token::negnums) != 0)) {
126  
127                  int val = lexi_cast<int>(script.substr(ichToken, cchToken));
129                std::cout << "encount an integer: " << val << std::endl;
128                  ltoken.push_back(Token(Token::integer,   boost::any(val)));
129                  continue;
130              }
# Line 244 | Line 242 | bool SelectionCompiler::internalCompile(){
242        previousCharBackslash = ch == '\\' ? !previousCharBackslash : false;
243      }
244      cchToken = ichT - ichToken;
247
245  
249    std::cout << "lookingAtString: encount " << script.substr(ichToken, cchToken) << std::endl;
246      return true;
247    }
248  
# Line 344 | 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
349 <    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 389 | Line 384 | bool SelectionCompiler::lookingAtLookupToken() {
384          case '(':
385          case ')':
386          case ',':
392        case '*':
393        case '-':
387          case '[':
388          case ']':
396        case '+':
397        case ':':
398        case '@':
399        case '.':
400        case '%':
389          break;
390          case '&':
391          case '|':
# Line 422 | Line 410 | bool SelectionCompiler::lookingAtLookupToken() {
410              if ((ch < 'a' || ch > 'z') && (ch < 'A' && ch > 'Z') && ch != '_') {
411                  return false;
412              }
413 +        case '*':
414          case '?': // include question marks in identifier for atom expressions
415 <            while (ichT < cchScript && !std::isspace(ch = script[ichT]) && (std::isalpha(ch) ||std::isdigit(ch) ||
416 <                ch == '_' || ch == '?') ) {
415 >            while (ichT < cchScript && !std::isspace(ch = script[ichT]) &&
416 >                    (std::isalpha(ch) ||std::isdigit(ch) || ch == '_' || ch == '.' || ch == '*' || ch == '?' || ch == '+' || ch == '-' || ch == '[' || ch == ']') ){
417  
418                  ++ichT;
419              }
# Line 433 | Line 422 | bool SelectionCompiler::lookingAtLookupToken() {
422  
423      cchToken = ichT - ichToken;
424  
436    std::cout << "lookingAtLookupToken: encount " << script.substr(ichToken, cchToken) << std::endl;
425      return true;
426   }
427  
# Line 657 | Line 645 | bool SelectionCompiler::clauseChemObjName() {
645   }
646  
647   bool SelectionCompiler::clauseChemObjName() {
648 <    std::string chemObjName;
649 <    int tok = tokPeek();
662 <    if (!clauseName(chemObjName)){
663 <        return false;
664 <    }
648 >    Token token = tokenNext();
649 >    if (token.tok == Token::identifier && token.value.type() == typeid(std::string)) {
650  
651 <
652 <    tok = tokPeek();
653 <    //allow two dot at most
654 <    if (tok == Token::dot) {
655 <        tokenNext();
656 <        chemObjName += ".";
657 <        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 <    }
651 >        std::string name = boost::any_cast<std::string>(token.value);
652 >        if (isNameValid(name)) {
653 >            return addTokenToPostfix(Token(Token::name, name));
654 >        } else {
655 >            return compileError("invalid name: " + name);
656 >        }
657 >    }
658  
659 <    return addTokenToPostfix(Token(Token::name, chemObjName));
659 >    return false;
660 >        
661   }
662  
663 < bool SelectionCompiler:: clauseName(std::string& name) {
663 > bool SelectionCompiler::isNameValid(const std::string& name) {
664 >          int nbracket = 0;
665 >    int ndot = 0;
666 >    for (int i =0 ; i < name.size(); ++i) {
667 >        switch(name[i]) {
668  
669 <    int tok = tokPeek();
670 <
671 <    if (tok == Token::asterisk || tok == Token::identifier) {
672 <        name += boost::any_cast<std::string>(tokenNext().value);
673 <        
674 <        while(true){
675 <            tok = tokPeek();
676 <            switch (tok) {
677 <                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 <            }
669 >          case '[' :
670 >              ++nbracket;
671 >              break;
672 >          case ']' :
673 >              --nbracket;
674 >              break;
675 >          case '.' :
676 >              ++ndot;
677 >              break;      
678          }
715        
716    }else {
717        return false;
679      }
680  
681 +    //only allow 3 dots at most
682 +    return (ndot <=3 && nbracket == 0) ? true : false;
683   }
684  
685   bool SelectionCompiler::clauseIndex(){

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines