Skip to content

Commit

Permalink
Added support for unary + operator
Browse files Browse the repository at this point in the history
  • Loading branch information
FlatAssembler committed Sep 13, 2024
1 parent 187e9b7 commit 93de450
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ std::vector<TreeNode> TreeNode::parseExpression(std::vector<TreeNode> 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
Expand Down
3 changes: 2 additions & 1 deletion tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 93de450

Please sign in to comment.