diff options
| -rw-r--r-- | diceparser.cpp | 17 | ||||
| -rw-r--r-- | diceparser.h | 2 | ||||
| -rw-r--r-- | main.cpp | 34 | ||||
| -rw-r--r-- | node/node.pri | 6 | ||||
| -rw-r--r-- | node/parenthesesnode.cpp | 29 | ||||
| -rw-r--r-- | node/parenthesesnode.h | 17 |
6 files changed, 85 insertions, 20 deletions
diff --git a/diceparser.cpp b/diceparser.cpp index ae0cdc6..b7bd952 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -225,6 +225,13 @@ bool DiceParser::readDiceExpression(QString& str,ExecutionNode* & node) { int number=1; bool returnVal=false; + if(readParantheses(str)) + { + str=str.remove(0,number.size()); + + readDiceExpression(); + + } bool hasRead = readNumber(str,number); @@ -491,6 +498,16 @@ bool DiceParser::readLogicOperator(QString& str,BooleanCondition::LogicOperator& return false; } +bool DiceParser::readParentheses(QString& str) +{ + if(str.startsWith("(")) + { + str=str.remove(0,1); + return true; + } + else + return false; +} ExecutionNode* DiceParser::addSort(ExecutionNode* e,bool b) { diff --git a/diceparser.h b/diceparser.h index 92c7248..48f2e0d 100644 --- a/diceparser.h +++ b/diceparser.h @@ -127,7 +127,7 @@ private: bool readLogicOperator(QString& str,BooleanCondition::LogicOperator& condition); - + bool readParentheses(QString& str); private: QMap<QString,DiceOperator>* m_mapDiceOp; @@ -11,23 +11,23 @@ int main(int argc, char *argv[]) QStringList commands; - commands << "3D100" - << "3D100" - << "10D10e[>=6]s" - << "100190D6666666s" - << "10D10e10s" - << "10D10s" - << "15D10e10c[8-10]" - << "15D10c[>7]" - << "1D8+2D6+7" - << "D25" - << "8+8+8" - << "1D20-88" - << "100*1D20*2D6" - << "100/28*3" - << "100/8" - << "100*3*8" - << "100*3*8"; + commands << "2D10+(4*1D10)"; +// << "3D100" +// << "10D10e[>=6]s" +// << "100190D6666666s" +// << "10D10e10s" +// << "10D10s" +// << "15D10e10c[8-10]" +// << "15D10c[>7]" +// << "1D8+2D6+7" +// << "D25" +// << "8+8+8" +// << "1D20-88" +// << "100*1D20*2D6" +// << "100/28*3" +// << "100/8" +// << "100*3*8" +// << "100*3*8"; diff --git a/node/node.pri b/node/node.pri index 090483e..4a7d55d 100644 --- a/node/node.pri +++ b/node/node.pri @@ -8,7 +8,8 @@ HEADERS += \ node/sortresult.h \ node/keepdiceexecnode.h \ node/countexecutenode.h \ - node/explosedicenode.h + node/explosedicenode.h \ + node/parenthesesnode.h SOURCES += \ node/dicerollernode.cpp \ @@ -20,4 +21,5 @@ SOURCES += \ node/sortresult.cpp \ node/keepdiceexecnode.cpp \ node/countexecutenode.cpp \ - node/explosedicenode.cpp + node/explosedicenode.cpp \ + node/parenthesesnode.cpp diff --git a/node/parenthesesnode.cpp b/node/parenthesesnode.cpp new file mode 100644 index 0000000..7bd5a6a --- /dev/null +++ b/node/parenthesesnode.cpp @@ -0,0 +1,29 @@ +#include "parenthesesnode.h" + +ParenthesesNode::ParenthesesNode() +{ + +} +void ParenthesesNode::setInternelNode(ExecutionNode* node) +{ + m_internalNode = node; +} +void ParenthesesNode::run(ExecutionNode* /*previous*/) +{ + if(NULL!=m_internalNode) + { + m_internalNode->run(this); + ExecutionNode* temp=m_internalNode; + while(NULL!=temp->getNextNode()) + { + temp=temp->getNextNode(); + } + m_result = m_internalNode->getResult(); + } + + + if(NULL!=m_nextNode) + { + m_nextNode->run(this); + } +} diff --git a/node/parenthesesnode.h b/node/parenthesesnode.h new file mode 100644 index 0000000..3347ba4 --- /dev/null +++ b/node/parenthesesnode.h @@ -0,0 +1,17 @@ +#ifndef PARENTHESESNODE_H +#define PARENTHESESNODE_H + +#include "executionnode.h" + +class ParenthesesNode : public ExecutionNode +{ +public: + ParenthesesNode(); + virtual void run(ExecutionNode* previous = NULL)=0; + + void setInternelNode(ExecutionNode* node); +private: + ExecutionNode* m_internalNode; +}; + +#endif // PARENTHESESNODE_H |