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

Comparing trunk/src/selection/SelectionCompiler.cpp (file contents):
Revision 283 by tim, Thu Feb 3 23:14:05 2005 UTC vs.
Revision 303 by tim, Mon Feb 7 22:36:32 2005 UTC

# 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 564 | Line 569 | bool SelectionCompiler::clausePrimitive() {
569          case Token::asterisk:
570          case Token::identifier:
571              return clauseChemObjName();
572 <      
572 >
573 >        case Token::integer :
574 >            return clauseIndex();
575          default:
576              if ((tok & Token::atomproperty) == Token::atomproperty) {
577                  return clauseComparator();
# Line 597 | 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 619 | Line 633 | bool SelectionCompiler::clauseWithin() {
633      Token tokenDistance = tokenNext();       // distance
634      switch(tokenDistance.tok) {
635          case Token::integer:
622            distance = float(tokenDistance.intValue);
623            break;
636          case Token::decimal:
637              distance = tokenDistance.value;
638              break;
# Line 654 | Line 666 | bool SelectionCompiler::clauseChemObjName() {
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              }
# Line 672 | Line 689 | bool SelectionCompiler:: clauseName(std::string& name)
689  
690      int tok = tokPeek();
691  
692 <    if (tok == Token::asterisk || tok == Token::identifier) {
693 <        name += boost::any_cast<std::string>(tokenNext().value);
694 <        
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) {
# Line 701 | Line 727 | bool SelectionCompiler:: clauseName(std::string& name)
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 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines