diff --git a/src/shunting-yard.c b/src/shunting-yard.c index c30f821..85534f4 100644 --- a/src/shunting-yard.c +++ b/src/shunting-yard.c @@ -53,6 +53,7 @@ static const Token NO_TOKEN = {TOKEN_NONE, NULL}; static const Operator OPERATORS[] = { {"!", 1, 1, OPERATOR_UNARY, OPERATOR_RIGHT}, {"~", 1, 1, OPERATOR_UNARY, OPERATOR_RIGHT}, + {"-", 1, 1, OPERATOR_UNARY, OPERATOR_RIGHT}, {"*", 1, 2, OPERATOR_BINARY, OPERATOR_LEFT}, {"/", 1, 2, OPERATOR_BINARY, OPERATOR_LEFT}, {"%", 1, 2, OPERATOR_BINARY, OPERATOR_LEFT}, diff --git a/tests/test-shunting-yard.c b/tests/test-shunting-yard.c index 4345b8d..f9c636a 100644 --- a/tests/test-shunting-yard.c +++ b/tests/test-shunting-yard.c @@ -71,6 +71,15 @@ static void test_modulus() ASSERT_RESULT("5 %5", 0); } +static void test_negation() +{ + ASSERT_RESULT("-1", -1); + ASSERT_RESULT("(-1)", -1); + ASSERT_RESULT("(-1) + 1", 0); + ASSERT_RESULT("(-1) + (-1)", -2); + ASSERT_RESULT("-1 + -1", -2); + ASSERT_RESULT("-1 + --1", 0); +} static void test_functions() {