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:
@@ -10,5 +10,8 @@ IO.print(-4.2 % -3.1) // expect: -1.1
|
||||
// Left associative.
|
||||
IO.print(13 % 7 % 4) // expect: 2
|
||||
|
||||
// Precedence.
|
||||
IO.print(13 + 1 % 7) // expect: 14
|
||||
|
||||
// TODO: Unsupported RHS types.
|
||||
// TODO: Error on mod by zero.
|
||||
|
||||
Reference in New Issue
Block a user