diff options
author | Adrian Kummerländer | 2013-09-27 18:02:33 +0200 |
---|---|---|
committer | Adrian Kummerländer | 2013-09-27 18:02:33 +0200 |
commit | c04051c034a5de33ba25e3182191d854edbbb516 (patch) | |
tree | 4b2834c80e06775eac0c2a6e49d8a66c93978d71 /src | |
parent | a0f0c005a39ddaf693c7de84d6ab1c380a93dca2 (diff) | |
download | SimpleParser-c04051c034a5de33ba25e3182191d854edbbb516.tar SimpleParser-c04051c034a5de33ba25e3182191d854edbbb516.tar.gz SimpleParser-c04051c034a5de33ba25e3182191d854edbbb516.tar.bz2 SimpleParser-c04051c034a5de33ba25e3182191d854edbbb516.tar.lz SimpleParser-c04051c034a5de33ba25e3182191d854edbbb516.tar.xz SimpleParser-c04051c034a5de33ba25e3182191d854edbbb516.tar.zst SimpleParser-c04051c034a5de33ba25e3182191d854edbbb516.zip |
Modified Makefile to generate shared library
* library is called libSimpleParser.so
* parser was renamed to clc
* test and clc are using the shared library
Diffstat (limited to 'src')
-rw-r--r-- | src/nodes.cc | 4 | ||||
-rw-r--r-- | src/parser.h | 12 | ||||
-rw-r--r-- | src/tree.cc | 50 |
3 files changed, 29 insertions, 37 deletions
diff --git a/src/nodes.cc b/src/nodes.cc index 4710400..390eac7 100644 --- a/src/nodes.cc +++ b/src/nodes.cc @@ -15,7 +15,7 @@ double OperandNode::solve() { } NodeType OperandNode::getType() { - return OPERAND_NODE; + return NodeType::OPERAND_NODE; } std::string OperandNode::print() { @@ -63,7 +63,7 @@ double OperatorNode::solve() { } NodeType OperatorNode::getType() { - return OPERATOR_NODE; + return NodeType::OPERATOR_NODE; } std::string OperatorNode::print() { diff --git a/src/parser.h b/src/parser.h index a27d1c0..54e540a 100644 --- a/src/parser.h +++ b/src/parser.h @@ -2,19 +2,11 @@ #define PARSER_SRC_PARSER_H_ #include <string> -#include <vector> - -#include "tree.h" namespace SimpleParser { -double calculate(std::string term) { - return Tree(term).solve(); -} - -std::string exportTree(std::string term) { - return Tree(term).print(); -} +double calculate(std::string); +std::string exportTree(std::string); } diff --git a/src/tree.cc b/src/tree.cc index 868183d..45484c6 100644 --- a/src/tree.cc +++ b/src/tree.cc @@ -18,30 +18,6 @@ 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 ) { - *place = this->node_collection_.back().get(); - } - - return this->node_collection_.back().get(); -} - -Node* Tree::addOperator(Node** place, char oper) { - this->node_collection_.emplace_back( - new OperatorNode(oper) - ); - - if ( place != nullptr ) { - *place = this->node_collection_.back().get(); - } - - return this->node_collection_.back().get(); -} - std::string Tree::print() { std::stringstream out; out.precision(std::numeric_limits<double>::digits10); @@ -65,7 +41,7 @@ std::string Tree::print() { << "\"];" << std::endl; - if ( (*it)->getType() == OPERATOR_NODE ) { + if ( (*it)->getType() == NodeType::OPERATOR_NODE ) { for ( auto iter = this->node_collection_.begin(); iter != this->node_collection_.end(); ++iter ) { @@ -96,6 +72,30 @@ std::string Tree::print() { return out.str(); } +Node* Tree::addOperand(Node** place, double value) { + this->node_collection_.emplace_back( + new OperandNode(value) + ); + + if ( place != nullptr ) { + *place = this->node_collection_.back().get(); + } + + return this->node_collection_.back().get(); +} + +Node* Tree::addOperator(Node** place, char oper) { + this->node_collection_.emplace_back( + new OperatorNode(oper) + ); + + if ( place != nullptr ) { + *place = this->node_collection_.back().get(); + } + + return this->node_collection_.back().get(); +} + Node* Tree::buildTree(std::string term) { std::stack<Node*> operandStack; std::stack<Node*> operatorStack; |