aboutsummaryrefslogtreecommitdiff
path: root/src/tree.cc
diff options
context:
space:
mode:
authorAdrian Kummerländer2013-10-19 19:35:16 +0200
committerAdrian Kummerländer2013-10-19 19:35:16 +0200
commit754cc721222ccb01acc4d93ffd8f88f172a0cdd0 (patch)
treef386f8bbf9c6909c6d7a965bdb66ddd2b99ac65f /src/tree.cc
parentaca18e1803b3d54e6c9d7444e8b9c1bf09d12f52 (diff)
downloadSimpleParser-754cc721222ccb01acc4d93ffd8f88f172a0cdd0.tar
SimpleParser-754cc721222ccb01acc4d93ffd8f88f172a0cdd0.tar.gz
SimpleParser-754cc721222ccb01acc4d93ffd8f88f172a0cdd0.tar.bz2
SimpleParser-754cc721222ccb01acc4d93ffd8f88f172a0cdd0.tar.lz
SimpleParser-754cc721222ccb01acc4d93ffd8f88f172a0cdd0.tar.xz
SimpleParser-754cc721222ccb01acc4d93ffd8f88f172a0cdd0.tar.zst
SimpleParser-754cc721222ccb01acc4d93ffd8f88f172a0cdd0.zip
POC: alphabetic constants
* New priority for alphabetic characters * Overloaded OperandNode constructor * Currently not usable, only basic proof of concept
Diffstat (limited to 'src/tree.cc')
-rw-r--r--src/tree.cc32
1 files changed, 25 insertions, 7 deletions
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<OperatorNode*>(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)