diff options
| author | 2016-01-30 17:52:00 +0100 | |
|---|---|---|
| committer | 2016-01-30 17:52:00 +0100 | |
| commit | 530c87f71366810549b718160bc59bda51f876b0 (patch) | |
| tree | 5245554bdb3ea5289f448c270f273ac783c079b2 /diceparser.cpp | |
| parent | c11896701cdc28e6a363af9242c111164f14e074 (diff) | |
| download | OneRoll-530c87f71366810549b718160bc59bda51f876b0.tar.gz OneRoll-530c87f71366810549b718160bc59bda51f876b0.zip | |
-rework arithmetic operator
Diffstat (limited to 'diceparser.cpp')
| -rw-r--r-- | diceparser.cpp | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/diceparser.cpp b/diceparser.cpp index 8d96d5a..98a8d29 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -711,12 +711,12 @@ bool DiceParser::readOperator(QString& str,ExecutionNode* previous) return false; } - ScalarOperatorNode* node = new ScalarOperatorNode(); - if(node->setOperatorChar(str[0])) + ScalarOperatorNode::ArithmeticOperator op; + if(m_parsingToolbox->readArithmeticOperator(str,op)) { - + ScalarOperatorNode* node = new ScalarOperatorNode(); + node->setArithmeticOperator(op); ExecutionNode* nodeExec = NULL; - str=str.remove(0,1);//removal of one character if(readExpression(str,nodeExec)) { node->setInternalNode(nodeExec); @@ -742,7 +742,6 @@ bool DiceParser::readOperator(QString& str,ExecutionNode* previous) else if(readInstructionOperator(str[0])) { str=str.remove(0,1); - delete node; ExecutionNode* nodeExec = NULL; if(readExpression(str,nodeExec)) { @@ -757,7 +756,6 @@ bool DiceParser::readOperator(QString& str,ExecutionNode* previous) } else { - delete node; while(readOption(str,previous,false)) { previous = getLatestNode(previous); @@ -973,27 +971,43 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous, bool hasDice)/ } bool DiceParser::readIfInstruction(QString& str,ExecutionNode*& trueNode,ExecutionNode*& falseNode) { + if(readBlocInstruction(str,trueNode)) + { + if(readBlocInstruction(str,falseNode)) + { + return true; + } + return true; + } + return false; +} +bool DiceParser::readBlocInstruction(QString& str,ExecutionNode*& resultnode) +{ if(str.startsWith('{')) { str=str.remove(0,1); ExecutionNode* node; + ScalarOperatorNode::ArithmeticOperator op; + ScalarOperatorNode* scalarNode = NULL; + if(m_parsingToolbox->readArithmeticOperator(str,op)) + { + scalarNode = new ScalarOperatorNode(); + scalarNode->setArithmeticOperator(op); + } if(readExpression(str,node)) { if(str.startsWith('}')) { - trueNode = node; - str=str.remove(0,1); - if(str.startsWith('{')) + if(NULL==scalarNode) + { + resultnode = node; + } + else { - str=str.remove(0,1); - ExecutionNode* node2; - readExpression(str,node2); - if(str.startsWith('}')) - { - falseNode=node2; - return true; - } + resultnode = scalarNode; + scalarNode->setInternalNode(node); } + str=str.remove(0,1); return true; } } |