From 754cc721222ccb01acc4d93ffd8f88f172a0cdd0 Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Sat, 19 Oct 2013 19:35:16 +0200 Subject: POC: alphabetic constants * New priority for alphabetic characters * Overloaded OperandNode constructor * Currently not usable, only basic proof of concept --- src/tree.cc | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'src/tree.cc') diff --git a/src/tree.cc b/src/tree.cc index 1dcfca6..81de460 100644 --- a/src/tree.cc +++ b/src/tree.cc @@ -84,6 +84,18 @@ Node* Tree::addOperand(Node** place, double value) { return this->node_collection_.back().get(); } +Node* Tree::addOperand(Node** place, std::string 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) @@ -119,7 +131,7 @@ Node* Tree::buildTree(std::string term) { std::string& currTerm = (*termIter); priority = getPriority(currTerm[0]); - if ( priority != -1 && (*termIter).size() == 1 ) { + if ( priority != -1 && priority != 100 && (*termIter).size() == 1 ) { if ( !operatorStack.empty() ) { OperatorNode* lastNode( static_cast(topNodeFrom(operatorStack)) @@ -152,13 +164,19 @@ Node* Tree::buildTree(std::string term) { tmpLexer = lexer(*termIter); if ( tmpLexer.size() == 1 ) { - double value; - std::istringstream convertStream(tmpLexer[0]); - convertStream >> value; + if ( getPriority(tmpLexer[0][0]) == -1 ) { + double value; + std::istringstream convertStream(tmpLexer[0]); + convertStream >> value; - operandStack.push( - this->addOperand(nullptr,value) - ); + operandStack.push( + this->addOperand(nullptr,value) + ); + } else if ( getPriority(tmpLexer[0][0]) == 100 ) { + operandStack.push( + this->addOperand(nullptr,tmpLexer[0]) + ); + } } else if ( tmpLexer.size() > 1 ) { operandStack.push( buildTree(*termIter) -- cgit v1.2.3