diff options
-rw-r--r-- | src/tree.cc | 8 | ||||
-rw-r--r-- | src/utils.cc | 8 | ||||
-rw-r--r-- | src/utils.h | 5 |
3 files changed, 13 insertions, 8 deletions
diff --git a/src/tree.cc b/src/tree.cc index 11bb299..900d891 100644 --- a/src/tree.cc +++ b/src/tree.cc @@ -117,7 +117,7 @@ Node* Tree::buildTree(const std::string& term) { elementIterator != topElements.end(); ++elementIterator ) { const std::string& element = *elementIterator; - const TokenType elementToken = determineToken(element[0]); + const TokenType elementToken = determineToken(element.front()); if ( elementToken != TokenType::VALUE_NUMBER && elementToken != TokenType::VALUE_IDENTIFIER && @@ -151,18 +151,18 @@ Node* Tree::buildTree(const std::string& term) { }; if ( subElements.size() == 1 ) { - switch ( determineToken(subElements[0][0]) ) { + switch ( determineToken(subElements.front()) ) { case TokenType::VALUE_NUMBER: case TokenType::OPERATOR_MINUS: { operands.push(this->addNode<OperandNode>( - doubleToString(subElements[0]) + doubleToString(subElements.front()) )); break; } case TokenType::VALUE_IDENTIFIER: { operands.push(this->addNode<ConstantNode>( - subElements[0], + subElements.front(), this->constants_ )); diff --git a/src/utils.cc b/src/utils.cc index 752b774..832b701 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -34,6 +34,10 @@ TokenType determineToken(const char tmp) { } } +TokenType determineToken(const std::string& tmp) { + return determineToken(tmp.front()); +} + PrecedenceLevel precedence(const TokenType token) { switch ( token ) { case TokenType::VALUE_NUMBER: @@ -61,7 +65,7 @@ PrecedenceLevel precedence(const TokenType token) { } } -std::vector<std::string> lexer(std::string term) { +std::vector<std::string> lexer(const std::string& term) { std::vector<std::string> resultBuffer; std::string levelBuffer; @@ -185,7 +189,7 @@ std::vector<std::string> lexer(std::string term) { if ( previousToken == TokenType::PARENTHESES_CLOSE && resultBuffer.size() == 1 ) { - resultBuffer = lexer(resultBuffer[0]); + resultBuffer = lexer(resultBuffer.front()); } return resultBuffer; diff --git a/src/utils.h b/src/utils.h index ca2c77f..63ccf55 100644 --- a/src/utils.h +++ b/src/utils.h @@ -28,9 +28,10 @@ enum class TokenType { VALUE_IDENTIFIER, }; -TokenType determineToken(char); +TokenType determineToken(const char); +TokenType determineToken(const std::string&); PrecedenceLevel precedence(TokenType); -std::vector<std::string> lexer(std::string); +std::vector<std::string> lexer(const std::string&); double doubleToString(const std::string&); |