diff options
author | Adrian Kummerländer | 2013-01-05 22:04:23 +0100 |
---|---|---|
committer | Adrian Kummerländer | 2013-01-05 22:04:23 +0100 |
commit | e3081360c65eb4994e7e8042898cec72de0d560b (patch) | |
tree | 2cac723733c674381ccaf32df5a64fe23b026467 | |
parent | 0ab1ad8c67ac5579e10104f53040d962a7f98f17 (diff) | |
download | SimpleParser-e3081360c65eb4994e7e8042898cec72de0d560b.tar SimpleParser-e3081360c65eb4994e7e8042898cec72de0d560b.tar.gz SimpleParser-e3081360c65eb4994e7e8042898cec72de0d560b.tar.bz2 SimpleParser-e3081360c65eb4994e7e8042898cec72de0d560b.tar.lz SimpleParser-e3081360c65eb4994e7e8042898cec72de0d560b.tar.xz SimpleParser-e3081360c65eb4994e7e8042898cec72de0d560b.tar.zst SimpleParser-e3081360c65eb4994e7e8042898cec72de0d560b.zip |
Folder structure change; Further improvements of parser code
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | main.cpp | 3 | ||||
-rw-r--r-- | src/parser.cpp (renamed from parser.cpp) | 4 | ||||
-rw-r--r-- | src/parser.h (renamed from parser.h) | 0 | ||||
-rw-r--r-- | src/tree.cpp (renamed from tree.cpp) | 12 | ||||
-rw-r--r-- | src/tree.h (renamed from tree.h) | 4 | ||||
-rw-r--r-- | test.cpp | 2 |
7 files changed, 19 insertions, 8 deletions
@@ -1,4 +1,4 @@ -LIB_FILES = tree.cpp parser.cpp +LIB_FILES = src/tree.cpp src/parser.cpp PROG_FILES = main.cpp TEST_FILES = test.cpp @@ -1,6 +1,7 @@ #include <iostream> #include <limits> -#include "parser.h" + +#include "src/parser.h" int main(int argc, char *argv[]) { diff --git a/parser.cpp b/src/parser.cpp index 683d26f..3aaf7e2 100644 --- a/parser.cpp +++ b/src/parser.cpp @@ -182,9 +182,9 @@ Node* Parser::buildTree(Tree *tree, std::string term) { double Parser::calculate(std::string term) { Tree termTree; - termTree.root = this->buildTree(&termTree, term); + termTree.setRoot(this->buildTree(&termTree, term)); - return termTree.root->solve(); + return termTree.solve(); } } @@ -64,7 +64,15 @@ char OperatorNode::getFunction() { return this->function_; } -Node* Tree::addOperand(Node **place, double value) { +void Tree::setRoot(Node* root) { + this->root_node_ = root; +} + +double Tree::solve() { + return this->root_node_->solve(); +} + +Node* Tree::addOperand(Node** place, double value) { this->node_collection_.emplace_back(new OperandNode(value)); if ( place != nullptr ) { @@ -74,7 +82,7 @@ Node* Tree::addOperand(Node **place, double value) { return this->node_collection_.back().get(); } -Node* Tree::addOperator(Node **place, char oper) { +Node* Tree::addOperator(Node** place, char oper) { this->node_collection_.emplace_back(new OperatorNode(oper)); if ( place != nullptr ) { @@ -55,7 +55,8 @@ class OperandNode: public Node { class Tree { public: - Node* root; + void setRoot(Node*); + double solve(); Node* addOperand(Node**, double); Node* addOperator(Node**, char); @@ -63,6 +64,7 @@ class Tree { std::string print(std::string); private: + Node* root_node_; std::vector<std::unique_ptr<Node>> node_collection_; }; @@ -1,4 +1,4 @@ -#include "parser.h" +#include "src/parser.h" #include "gtest/gtest.h" class ParserTest : public ::testing::Test { |