-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
增加op-expr, 这是我们更加熟悉的表达形式, 它使复杂计算也更加干练
- Loading branch information
Showing
6 changed files
with
379 additions
and
23 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "mindustry_logic_bang_lang" | ||
version = "0.10.6" | ||
version = "0.11.0" | ||
edition = "2021" | ||
|
||
authors = ["A4-Tacks <[email protected]>"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#** | ||
* 这是在0.11.0版本添加的表达式系统, 旨在更加干练的编写复杂运算 | ||
* 可以有限的以我们比较常见的表达式形式使用op来进行运算 | ||
* 这个语法可以看成在对sets左值为单个时的行为扩展 | ||
* 在sets左值为单个Value时, 右值将成为一个op-expr | ||
* | ||
* 以下为各种运算符的优先级与结合性: | ||
* | 符号 | 实际运算(op) | 优先级 | 结合性 | | ||
* | --------- | ------------ | ------ | ------ | | ||
* | `a ** b` | `a ** b` | -1 | RL | | ||
* | `! x` | `x != false` | -2 | R | | ||
* | `- x` | `0 - x` | -2 | R | | ||
* | `~ x` | `~ x` | -2 | R | | ||
* | `a * b` | `a * b` | -3 | LR | | ||
* | `a / b` | `a / b` | -3 | LR | | ||
* | `a % b` | `a % b` | -3 | LR | | ||
* | `a // b` | `a // b` | -3 | LR | | ||
* | `a + b` | `a + b` | -4 | LR | | ||
* | `a - b` | `a - b` | -4 | LR | | ||
* | `a << b` | `a << b` | -5 | LR | | ||
* | `a >> b` | `a >> b` | -5 | LR | | ||
* | `a & b` | `a & b` | -6 | LR | | ||
* | `a ^ b` | `a ^ b` | -7 | LR | | ||
* | `a | b` | `a | b` | -8 | LR | | ||
* | `a == b` | `a == b` | -9 | LR | | ||
* | `a != b` | `a != b` | -9 | LR | | ||
* | `a < b` | `a < b` | -9 | LR | | ||
* | `a > b` | `a > b` | -9 | LR | | ||
* | `a <= b` | `a <= b` | -9 | LR | | ||
* | `a >= b` | `a >= b` | -9 | LR | | ||
* | `a === b` | `a === b` | -9 | LR | | ||
* | `a && b` | `a && b` | -10 | LR | | ||
* | `a || b` | `a + b` | -11 | LR | | ||
* | ||
* 以上表格外, 还有一元与二元函数(其实就是op) | ||
* 它们的优先级与括号平级, | ||
* 二元函数有: `max` `min` `angle` `len` `noise`, | ||
* 一元函数的部分列举有: `log` `rand` ..., | ||
* | ||
* 具体参考op中没有符号的运算 | ||
*# | ||
|
||
x = 1 + 2 * 3; | ||
y = (1 + 2) * 3; | ||
z = min(a+b, c-d); | ||
#* A >>> | ||
op 'x' '1' + (op $ '2' * '3';); | ||
op 'y' (op $ '1' + '2';) * '3'; | ||
op 'z' min (op $ 'a' + 'b';) (op $ 'c' - 'd';); | ||
*# | ||
# 我们可以看出, 优先级生效了, 并且运算被正常解析为DExp树了 | ||
# 并且我们并没有遇到最后要经历一遭set的问题, 因为解析时有一个安全标记 | ||
# 这个标记将使我们可以正确的将op与set合并. | ||
# | ||
# 当然, 需要注意的是, | ||
# 虽然运算成员是Value, 但依旧不推荐使用`$`符号(返回句柄替换符) | ||
# 因为这并没有什么意义, 且如果在最外层, 那么因为最顶层op与set的合并, | ||
# 这个句柄将会指向set的更外层的DExp. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.