diff options
author | Adrian Kummerländer | 2013-10-19 20:53:51 +0200 |
---|---|---|
committer | Adrian Kummerländer | 2013-10-19 20:53:51 +0200 |
commit | c292b29f3bb87cf11edf899c023cfb574c20ed6c (patch) | |
tree | ca1915dd4ed8edff605b77e6db9820b9e5d9232b /src/tree.cc | |
parent | 754cc721222ccb01acc4d93ffd8f88f172a0cdd0 (diff) | |
parent | 9a95b5d24b2b2f5111e1862875d4136964a59548 (diff) | |
download | SimpleParser-c292b29f3bb87cf11edf899c023cfb574c20ed6c.tar SimpleParser-c292b29f3bb87cf11edf899c023cfb574c20ed6c.tar.gz SimpleParser-c292b29f3bb87cf11edf899c023cfb574c20ed6c.tar.bz2 SimpleParser-c292b29f3bb87cf11edf899c023cfb574c20ed6c.tar.lz SimpleParser-c292b29f3bb87cf11edf899c023cfb574c20ed6c.tar.xz SimpleParser-c292b29f3bb87cf11edf899c023cfb574c20ed6c.tar.zst SimpleParser-c292b29f3bb87cf11edf899c023cfb574c20ed6c.zip |
Merge branch 'master' into feature_constants
Conflicts:
src/tree.cc
src/utils.cc
Diffstat (limited to 'src/tree.cc')
-rw-r--r-- | src/tree.cc | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/src/tree.cc b/src/tree.cc index 81de460..2dfb786 100644 --- a/src/tree.cc +++ b/src/tree.cc @@ -123,21 +123,21 @@ Node* Tree::buildTree(std::string term) { std::vector<std::string> tmpLexer; std::vector<std::string> lexerOutput = lexer(term); - int8_t priority; - for ( auto termIter = lexerOutput.begin(); termIter != lexerOutput.end(); termIter++ ) { - std::string& currTerm = (*termIter); - priority = getPriority(currTerm[0]); + const std::string& currTerm = (*termIter); + const TokenType token = getTokenType(currTerm[0]); - if ( priority != -1 && priority != 100 && (*termIter).size() == 1 ) { + if ( token != TokenType::VALUE_NUMBER && + token != TokenType::VALUE_IDENTIFIER && + (*termIter).size() == 1 ) { if ( !operatorStack.empty() ) { OperatorNode* lastNode( static_cast<OperatorNode*>(topNodeFrom(operatorStack)) ); - if ( getPriority(lastNode->getFunction()) < priority ) { + if ( token > getTokenType(lastNode->getFunction()) ) { operatorStack.push( this->addOperator(nullptr, currTerm[0]) ); @@ -164,20 +164,30 @@ Node* Tree::buildTree(std::string term) { tmpLexer = lexer(*termIter); if ( tmpLexer.size() == 1 ) { - if ( getPriority(tmpLexer[0][0]) == -1 ) { - double value; - std::istringstream convertStream(tmpLexer[0]); - convertStream >> value; - - operandStack.push( - this->addOperand(nullptr,value) - ); - } else if ( getPriority(tmpLexer[0][0]) == 100 ) { - operandStack.push( - this->addOperand(nullptr,tmpLexer[0]) - ); + switch ( getTokenType(tmpLexer[0][0]) ) { + case TokenType::VALUE_NUMBER: { + double value; + std::istringstream convertStream(tmpLexer[0]); + convertStream >> value; + + operandStack.push( + this->addOperand(nullptr,value) + ); + + break; + } + case TokenType::VALUE_IDENTIFIER: { + operandStack.push( + this->addOperand(nullptr,tmpLexer[0]) + ); + + break; + } + default: { + throw operator_exception(); + } } - } else if ( tmpLexer.size() > 1 ) { + } else { operandStack.push( buildTree(*termIter) ); |