erg/doc/zh_CN/compiler/parsing.md

31 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 解析 Erg 语言
## 处理空白
在 Erg 的语法中,特别的是 space-sensitive根据空白进行区分这一点。这是为了弥补的省略导致的表现力下降。同样的语法也可以在可以省略<gtr=“4/>的 Nim 中看到。
```erg
f +1 == f(+1)
f + 1 == `+`(f, 1)
f (1,) == f((1,))
f(1,) == f(1)
(f () -> ...) == f(() -> ...)
(f() -> ...) == (f() -> ...)
```
## 左侧值,右侧值
在 Erg 中,所谓左边值并不是的左侧这样简单的值。实际上,<gtr=“6/>的左侧也存在右边值(非常容易混淆),<gtr=“7/>的右侧也存在左边值。甚至在右边值中存在左边值。
```erg
# iは左辺値、Array(Int)と[1, 2, 3]は右辺値
i: Array(Int) = [1, 2, 3]
# `[1, 2, 3].iter().map i -> i + 1`は右辺値だが、->の左側のiは左辺値
a = [1, 2, 3].iter().map i -> i + 1
# {x = 1; y = 2}は右辺値だが、x, yは左辺値
r = {x = 1; y = 2}
```
左边值、右边值的正确定义是“如果可以评价的话是右边值,如果不是的话是左边值”。以这一代码为例。第 2 个<gtr=“9/>是可以评价的右边值,第 1 个<gtr=“10/>是左边值。