diff options
Diffstat (limited to 'src/nodes.cc')
-rw-r--r-- | src/nodes.cc | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/src/nodes.cc b/src/nodes.cc index 283b583..256a609 100644 --- a/src/nodes.cc +++ b/src/nodes.cc @@ -30,29 +30,23 @@ OperatorNode::OperatorNode(TokenType token): double OperatorNode::solve() const { switch ( this->operator_ ) { - case TokenType::OPERATOR_MULTIPLY: { - return this->leftChild->solve() * this->rightChild->solve(); - } case TokenType::OPERATOR_PLUS: { return this->leftChild->solve() + this->rightChild->solve(); } case TokenType::OPERATOR_MINUS: { return this->leftChild->solve() - this->rightChild->solve(); } + case TokenType::OPERATOR_MULTIPLY: { + return this->leftChild->solve() * this->rightChild->solve(); + } + case TokenType::OPERATOR_DIVIDE: { + return this->leftChild->solve() / this->rightChild->solve(); + } case TokenType::OPERATOR_POWER: { return std::pow( this->leftChild->solve(), this->rightChild->solve() ); } - case TokenType::OPERATOR_DIVIDE: { - const double rightChild{ this->rightChild->solve() }; - - if ( rightChild != 0 ) { - return this->leftChild->solve() / rightChild; - } else { - throw divide_exception(); - } - } default: { throw operator_exception(); } |