fix: correct operator precedence for % token from PREC_TERM to PREC_FACTOR

The modulo operator was incorrectly assigned PREC_TERM precedence, making it
evaluate at the same level as + and -. This caused expressions like "13 + 1 % 7"
to parse as "(13 + 1) % 7" instead of the correct "13 + (1 % 7)".

Changed the grammar rule for TOKEN_PERCENT to use PREC_FACTOR, matching the
precedence of * and / operators. Added a precedence test case in mod.wren to
verify the fix.
This commit is contained in:
Evan Shaw
2015-01-21 20:49:43 +00:00
parent fccdf60ce8
commit ffcdd8ae9e
2 changed files with 4 additions and 1 deletions
+1 -1
View File
@@ -2183,7 +2183,7 @@ GrammarRule rules[] =
/* TOKEN_COMMA */ UNUSED,
/* TOKEN_STAR */ INFIX_OPERATOR(PREC_FACTOR, "* "),
/* TOKEN_SLASH */ INFIX_OPERATOR(PREC_FACTOR, "/ "),
/* TOKEN_PERCENT */ INFIX_OPERATOR(PREC_TERM, "% "),
/* TOKEN_PERCENT */ INFIX_OPERATOR(PREC_FACTOR, "% "),
/* TOKEN_PLUS */ INFIX_OPERATOR(PREC_TERM, "+ "),
/* TOKEN_MINUS */ OPERATOR("- "),
/* TOKEN_PIPE */ INFIX_OPERATOR(PREC_BITWISE, "| "),