diff --git a/parser.cpp b/parser.cpp index d516378..0906fa8 100644 --- a/parser.cpp +++ b/parser.cpp @@ -265,8 +265,8 @@ std::vector TreeNode::parseExpression(std::vector input) { parsedExpression[openCurlyBrace].text = "{}"; } for (int i = parsedExpression.size() - 1; i >= 0; - i--) // The unary "-" operator. - if (parsedExpression[i].text == "-" and + i--) // The unary "+" and "-" operators. + if ((parsedExpression[i].text == "-" or parsedExpression[i].text == "+") and i != int(parsedExpression.size()) - 1 and parsedExpression[i].children.size() == 0 and (!i or (!isComposedOfAlnumsAndOneDot(parsedExpression[i - 1].text) and diff --git a/tests.cpp b/tests.cpp index 10a4609..aaaf2fe 100644 --- a/tests.cpp +++ b/tests.cpp @@ -132,7 +132,8 @@ void interpreterTests() { not(2 < 3 < 1) and (-3 < -2 < -1) and (3 > 2 > 1) - )", "1"} + )", "1"}, + {"5 + + 1", "6"} }); for (unsigned int i = 0; i < tests.size(); i++) { std::string result = std::to_string(