From 79a4a02b58206b086ee3be4af399572bf6992b87 Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Wed, 20 Jul 2022 09:21:21 +0900 Subject: [PATCH] Resolve long-standing left/right binding issue with '**' --- src/compiler.c | 2 +- test/testPow.krk | 1 + test/testPow.krk.expect | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 test/testPow.krk create mode 100644 test/testPow.krk.expect diff --git a/src/compiler.c b/src/compiler.c index cad094f..fed6db8 100644 --- a/src/compiler.c +++ b/src/compiler.c @@ -812,7 +812,7 @@ static void compare(int exprType, RewindState *rewind) { static void binary(int exprType, RewindState *rewind) { KrkTokenType operatorType = parser.previous.type; ParseRule * rule = getRule(operatorType); - parsePrecedence((Precedence)(rule->precedence + 1)); + parsePrecedence((Precedence)(rule->precedence + (rule->precedence != PREC_EXPONENT))); invalidTarget(exprType, "operator"); switch (operatorType) { diff --git a/test/testPow.krk b/test/testPow.krk new file mode 100644 index 0000000..8958df4 --- /dev/null +++ b/test/testPow.krk @@ -0,0 +1 @@ +print(2**3**4) diff --git a/test/testPow.krk.expect b/test/testPow.krk.expect new file mode 100644 index 0000000..5305e62 --- /dev/null +++ b/test/testPow.krk.expect @@ -0,0 +1 @@ +2417851639229258349412352