feat: split monolithic PREC_BITWISE into separate precedence levels for |, ^, &, and << >> in wren_compiler.c

Add new Precedence enum values (PREC_BITWISE_OR, PREC_BITWISE_XOR, PREC_BITWISE_AND, PREC_BITWISE_SHIFT) and a PREC_TERNARY level between assignment and logical operators. Update and_(), or_(), and conditional() to use the refined precedence constants. Include a test file verifying correct associativity and precedence ordering among bitwise operators (|, &, ^, <<) in expressions.
This commit is contained in:
Bob Nystrom
2015-02-25 15:14:31 +00:00
2 changed files with 49 additions and 21 deletions
+23
View File
@@ -0,0 +1,23 @@
// << have higher precedence than |.
IO.print(2 | 1 << 1) // expect: 2
IO.print(1 << 1 | 2) // expect: 2
// << has higher precedence than &.
IO.print(2 & 1 << 1) // expect: 2
IO.print(1 << 1 & 2) // expect: 2
// << has higher precedence than ^.
IO.print(2 ^ 1 << 1) // expect: 0
IO.print(1 << 1 ^ 2) // expect: 0
// & has higher precedence than |.
IO.print(1 & 1 | 2) // expect: 3
IO.print(2 | 1 & 1) // expect: 3
// & has higher precedence than ^.
IO.print(1 & 1 ^ 2) // expect: 3
IO.print(2 ^ 1 & 1) // expect: 3
// ^ has higher precedence than |.
IO.print(1 ^ 1 | 1) // expect: 1
IO.print(1 | 1 ^ 1) // expect: 1