--- trunk/src/selection/SelectionCompiler.cpp 2005/02/03 23:14:05 283 +++ trunk/src/selection/SelectionCompiler.cpp 2005/02/07 19:13:18 295 @@ -82,8 +82,8 @@ bool SelectionCompiler::internalCompile(){ for ( ; true; ichToken += cchToken) { if (lookingAtLeadingWhitespace()) continue; - if (lookingAtComment()) - continue; + //if (lookingAtComment()) + // continue; bool endOfLine = lookingAtEndOfLine(); if (endOfLine || lookingAtEndOfStatement()) { if (tokCommand != Token::nada) { @@ -118,21 +118,22 @@ bool SelectionCompiler::internalCompile(){ // continue; //} if (lookingAtDecimal((tokCommand & Token::negnums) != 0)) { - float value = lexi_cast(script.substr(ichToken, ichToken + cchToken)); - ltoken.push_back(Token(Token::decimal, value));/**@todo*/ + float value = lexi_cast(script.substr(ichToken, cchToken)); + std::cout << "encount an decimal: " << value << std::endl; + ltoken.push_back(Token(Token::decimal, boost::any(value))); continue; } if (lookingAtInteger((tokCommand & Token::negnums) != 0)) { - std::string intString = script.substr(ichToken, ichToken + cchToken); - int val = lexi_cast(intString); - ltoken.push_back(Token(Token::integer, val, intString));/**@todo*/ + + int val = lexi_cast(script.substr(ichToken, cchToken)); + std::cout << "encount an integer: " << val << std::endl; + ltoken.push_back(Token(Token::integer, boost::any(val))); continue; } } if (lookingAtLookupToken()) { - std::string ident = script.substr(ichToken, ichToken + cchToken); - + std::string ident = script.substr(ichToken, cchToken); Token token; Token* pToken = TokenMap::getInstance()->getToken(ident); if (pToken != NULL) { @@ -243,6 +244,9 @@ bool SelectionCompiler::internalCompile(){ previousCharBackslash = ch == '\\' ? !previousCharBackslash : false; } cchToken = ichT - ichToken; + + + std::cout << "lookingAtString: encount " << script.substr(ichToken, cchToken) << std::endl; return true; } @@ -419,15 +423,17 @@ bool SelectionCompiler::lookingAtLookupToken() { return false; } case '?': // include question marks in identifier for atom expressions - while (ichT < cchScript && (std::isalpha(ch = script[ichT]) ||std::isdigit(ch) || - ch == '_' || ch == '?') ||(ch == '^' && ichT > ichToken && std::isdigit(script[ichT - 1]))) { - // hack for insertion codes embedded in an atom expression :-( - // select c3^a + while (ichT < cchScript && !std::isspace(ch = script[ichT]) && (std::isalpha(ch) ||std::isdigit(ch) || + ch == '_' || ch == '?') ) { + ++ichT; } break; } + cchToken = ichT - ichToken; + + std::cout << "lookingAtLookupToken: encount " << script.substr(ichToken, cchToken) << std::endl; return true; } @@ -564,7 +570,9 @@ bool SelectionCompiler::clausePrimitive() { case Token::asterisk: case Token::identifier: return clauseChemObjName(); - + + case Token::integer : + return clauseIndex(); default: if ((tok & Token::atomproperty) == Token::atomproperty) { return clauseComparator(); @@ -597,16 +605,23 @@ bool SelectionCompiler::clauseComparator() { } Token tokenValue = tokenNext(); - if (tokenValue.tok != Token::integer) { - return integerExpected(); + if (tokenValue.tok != Token::integer && tokenValue.tok != Token::decimal) { + return numberExpected(); } - int val = tokenValue.intValue; - // note that a comparator instruction is a complicated instruction - // int intValue is the tok of the property you are comparing - // the value against which you are comparing is stored as an Integer - // in the object value + + float val; + if (tokenValue.value.type() == typeid(int)) { + val = boost::any_cast(tokenValue.value); + } else if (tokenValue.value.type() == typeid(float)) { + val = boost::any_cast(tokenValue.value); + } else { + return false; + } + + boost::any floatVal; + floatVal = val; return addTokenToPostfix(Token(tokenComparator.tok, - tokenAtomProperty.tok, boost::any(val))); + tokenAtomProperty.tok, floatVal)); } bool SelectionCompiler::clauseWithin() { @@ -619,8 +634,6 @@ bool SelectionCompiler::clauseWithin() { Token tokenDistance = tokenNext(); // distance switch(tokenDistance.tok) { case Token::integer: - distance = float(tokenDistance.intValue); - break; case Token::decimal: distance = tokenDistance.value; break; @@ -654,11 +667,16 @@ bool SelectionCompiler::clauseChemObjName() { tok = tokPeek(); //allow two dot at most if (tok == Token::dot) { + tokenNext(); + chemObjName += "."; if (!clauseName(chemObjName)) { return false; } tok = tokPeek(); if (tok == Token::dot) { + tokenNext(); + chemObjName += "."; + if (!clauseName(chemObjName)) { return false; } @@ -701,5 +719,34 @@ bool SelectionCompiler:: clauseName(std::string& name) } +bool SelectionCompiler::clauseIndex(){ + Token token = tokenNext(); + if (token.tok == Token::integer) { + int index = boost::any_cast(token.value); + int tok = tokPeek(); + std::cout << "Token::to is " << Token::to << ", tok = " << tok << std::endl; + if (tok == Token::to) { + tokenNext(); + tok = tokPeek(); + if (tok != Token::integer) { + return numberExpected(); + } + + boost::any intVal = tokenNext().value; + int first = index; + if (intVal.type() != typeid(int)){ + return false; + } + int second = boost::any_cast(intVal); + return addTokenToPostfix(Token(Token::index, boost::any(std::make_pair(first, second)))); + + }else { + return addTokenToPostfix(Token(Token::index, boost::any(index))); + } + } else { + return numberExpected(); + } } + +}