aboutsummaryrefslogtreecommitdiff
path: root/src/tree.cc
diff options
context:
space:
mode:
authorAdrian Kummerländer2013-10-19 20:11:56 +0200
committerAdrian Kummerländer2013-10-19 20:11:56 +0200
commit9a95b5d24b2b2f5111e1862875d4136964a59548 (patch)
tree9ac96fdf846ae19e2278f9540593823fa8ba3b21 /src/tree.cc
parentaca18e1803b3d54e6c9d7444e8b9c1bf09d12f52 (diff)
downloadSimpleParser-9a95b5d24b2b2f5111e1862875d4136964a59548.tar
SimpleParser-9a95b5d24b2b2f5111e1862875d4136964a59548.tar.gz
SimpleParser-9a95b5d24b2b2f5111e1862875d4136964a59548.tar.bz2
SimpleParser-9a95b5d24b2b2f5111e1862875d4136964a59548.tar.lz
SimpleParser-9a95b5d24b2b2f5111e1862875d4136964a59548.tar.xz
SimpleParser-9a95b5d24b2b2f5111e1862875d4136964a59548.tar.zst
SimpleParser-9a95b5d24b2b2f5111e1862875d4136964a59548.zip
Improvement: Replaced "priority" with TokenType
* Made implementation more expressive by replacing the integer priority with an strictly typed enum called TokenType ** Made removal of character comparisons from tree construction and lexer possible * As a side effect distinct numbers had to be assigned to each token ** Operators of same priority do not have identical numbers anymore
Diffstat (limited to 'src/tree.cc')
-rw-r--r--src/tree.cc10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/tree.cc b/src/tree.cc
index 1dcfca6..0f5c2d8 100644
--- a/src/tree.cc
+++ b/src/tree.cc
@@ -111,21 +111,19 @@ Node* Tree::buildTree(std::string term) {
std::vector<std::string> tmpLexer;
std::vector<std::string> lexerOutput = lexer(term);
- int8_t priority;
-
for ( auto termIter = lexerOutput.begin();
termIter != lexerOutput.end();
termIter++ ) {
- std::string& currTerm = (*termIter);
- priority = getPriority(currTerm[0]);
+ const std::string& currTerm = (*termIter);
+ const TokenType token = getTokenType(currTerm[0]);
- if ( priority != -1 && (*termIter).size() == 1 ) {
+ if ( token != TokenType::VALUE_NUMBER && (*termIter).size() == 1 ) {
if ( !operatorStack.empty() ) {
OperatorNode* lastNode(
static_cast<OperatorNode*>(topNodeFrom(operatorStack))
);
- if ( getPriority(lastNode->getFunction()) < priority ) {
+ if ( token > getTokenType(lastNode->getFunction()) ) {
operatorStack.push(
this->addOperator(nullptr, currTerm[0])
);