mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-18 13:49:59 +01:00
Fixes #93. Previously, "1 -1" was lexed as two number tokens: a positive literal and a negative literal. This caused problems when it came to parsing. Now the '-' and the second number are separate tokens. Note this is a breaking change, since `-16.sqrt` is now parsed as `-(16.sqrt)`, as opposed to `(-16).sqrt`. There is a small bit of overhead to doing it this way, but it might be possible to optimize that out in the compiler at some point in the future.
38 lines
919 B
Plaintext
38 lines
919 B
Plaintext
// * has higher precedence than +.
|
|
IO.print(2 + 3 * 4) // expect: 14
|
|
|
|
// * has higher precedence than -.
|
|
IO.print(20 - 3 * 4) // expect: 8
|
|
|
|
// / has higher precedence than +.
|
|
IO.print(2 + 6 / 3) // expect: 4
|
|
|
|
// / has higher precedence than -.
|
|
IO.print(2 - 6 / 3) // expect: 0
|
|
|
|
// < has higher precedence than ==.
|
|
IO.print(false == 2 < 1) // expect: true
|
|
|
|
// > has higher precedence than ==.
|
|
IO.print(false == 1 > 2) // expect: true
|
|
|
|
// <= has higher precedence than ==.
|
|
IO.print(false == 2 <= 1) // expect: true
|
|
|
|
// >= has higher precedence than ==.
|
|
IO.print(false == 1 >= 2) // expect: true
|
|
|
|
// Unary - has lower precedence than ..
|
|
IO.print(-"abc".count) // expect: -3
|
|
|
|
// 1 - 1 is not space-sensitive.
|
|
IO.print(1 - 1) // expect: 0
|
|
IO.print(1 -1) // expect: 0
|
|
IO.print(1- 1) // expect: 0
|
|
IO.print(1-1) // expect: 0
|
|
|
|
// TODO: %, associativity.
|
|
|
|
// Using () for grouping.
|
|
IO.print((2 * (6 - (2 + 2)))) // expect: 4
|