From c0933381497401a9439446d9470dd617b08b88ed Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Sun, 20 Nov 2011 17:53:15 +0100 Subject: Added support for signed numbers --- main.cpp | 2 +- parser.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/main.cpp b/main.cpp index 2bc682a..d3c3799 100644 --- a/main.cpp +++ b/main.cpp @@ -11,7 +11,7 @@ int main(int argc, char *argv[]) Parser *parser = new Parser(); try { - std::cout << parser->calculate(inputTerm, false).result << std::endl; + std::cout << parser->calculate(inputTerm, true).result << std::endl; } catch ( exception &e ) { diff --git a/parser.cpp b/parser.cpp index 47516b3..757f8c5 100644 --- a/parser.cpp +++ b/parser.cpp @@ -38,7 +38,7 @@ vector* Parser::lexer(string term) for ( termIter = term.begin(); termIter != term.end(); termIter++ ) { priority = this->getPriority( *termIter ); - if ( priority == -1 ) { + if ( priority == -1 || ( termIter == term.begin() && priority == 10 ) ) { if ( level > 0 ) { tmp += *termIter; } @@ -117,7 +117,7 @@ Node* Parser::buildTree(Tree **tree, string term) for ( vector::iterator termIter = lexerOutput->begin(); termIter != lexerOutput->end(); termIter++ ) { priority = this->getPriority( (*termIter)[0] ); - if ( priority != -1 ) { + if ( priority != -1 && (*termIter).size() == 1 ) { if ( !operatorStack->empty() ) { OperatorNode *lastNode = static_cast( operatorStack->top() ); -- cgit v1.2.3