From 0985a623e4cbd14da77fddf1bb1a9ca3384b28ea Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Wed, 10 Jun 2015 20:32:13 +0200 Subject: Changed token determination regarding identifier values * all non operator and digit tokens are now identifier tokens as this seems more intuitive than generating number token lists containing non-digit values * renamed lexer-local `level` variable to `nesting` as to avoid confusion between nesting state and predecence levels --- src/tree.cc | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'src/tree.cc') diff --git a/src/tree.cc b/src/tree.cc index f8c17ae..8e29255 100644 --- a/src/tree.cc +++ b/src/tree.cc @@ -12,7 +12,7 @@ namespace { using SimpleParser::Node; - inline boost::optional top(const std::stack stack) { + boost::optional top(const std::stack stack) { if ( !stack.empty() ) { return boost::make_optional( stack.top() @@ -22,7 +22,7 @@ namespace { } } - inline boost::optional pop(std::stack& stack) { + boost::optional pop(std::stack& stack) { if ( boost::optional node{ top(stack) } ) { stack.pop(); @@ -63,7 +63,7 @@ std::string Tree::print() const { for ( auto&& node : this->node_collection_ ) { out << "node" - << nodeIndex + << nodeIndex << " [ label = \"" << node->print() << "\"]; "; @@ -74,9 +74,9 @@ std::string Tree::print() const { for ( auto&& child : this->node_collection_ ) { if ( node->isParentOf(child.get()) ) { out << "\"node" - << nodeIndex + << nodeIndex << "\" -> \"node" - << childIndex + << childIndex << "\"; "; } @@ -134,10 +134,10 @@ Node* Tree::buildTree(const std::string& term) { OperatorNode*const lastOperator{ static_cast(*lastNode) }; - + if ( precedence(elementToken) > precedence(lastOperator->token()) ) { - operators.emplace( + operators.emplace( this->addNode(elementToken) ); } else { @@ -145,9 +145,7 @@ Node* Tree::buildTree(const std::string& term) { boost::optional rightChild { pop(operands) }; boost::optional leftChild { pop(operands) }; - if ( currentOperator && - rightChild && - leftChild ) { + if ( currentOperator && rightChild && leftChild ) { static_cast( *currentOperator )->setChildren( @@ -172,7 +170,7 @@ Node* Tree::buildTree(const std::string& term) { }; if ( subElements.size() == 1 ) { - switch ( determineToken(subElements.front()) ) { + switch ( determineToken(subElements.front().front()) ) { case TokenType::VALUE_NUMBER: case TokenType::OPERATOR_MINUS: { operands.emplace( @@ -210,9 +208,7 @@ Node* Tree::buildTree(const std::string& term) { boost::optional rightChild { pop(operands) }; boost::optional leftChild { pop(operands) }; - if ( currentOperator && - rightChild && - leftChild ) { + if ( currentOperator && rightChild && leftChild ) { static_cast( *currentOperator )->setChildren( -- cgit v1.2.3