diff options
author | Adrian Kummerländer | 2011-11-20 17:53:15 +0100 |
---|---|---|
committer | Adrian Kummerländer | 2011-11-20 17:53:15 +0100 |
commit | c0933381497401a9439446d9470dd617b08b88ed (patch) | |
tree | 63a7904cbd8ee3791eb3f03815d4b1f777d5f331 | |
parent | 64c34a42ce96c8368b8dc0636e8a452def6f8ea5 (diff) | |
download | SimpleParser-c0933381497401a9439446d9470dd617b08b88ed.tar SimpleParser-c0933381497401a9439446d9470dd617b08b88ed.tar.gz SimpleParser-c0933381497401a9439446d9470dd617b08b88ed.tar.bz2 SimpleParser-c0933381497401a9439446d9470dd617b08b88ed.tar.lz SimpleParser-c0933381497401a9439446d9470dd617b08b88ed.tar.xz SimpleParser-c0933381497401a9439446d9470dd617b08b88ed.tar.zst SimpleParser-c0933381497401a9439446d9470dd617b08b88ed.zip |
Added support for signed numbers
-rw-r--r-- | main.cpp | 2 | ||||
-rw-r--r-- | parser.cpp | 4 |
2 files changed, 3 insertions, 3 deletions
@@ -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 ) { @@ -38,7 +38,7 @@ vector<string>* 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<string>::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<OperatorNode*>( operatorStack->top() ); |