为什么Go语言中缺少布尔类型的令牌类型?

huangapple go评论85阅读模式
英文:

Why is the Token type for Bool Missing in Go?

问题

我已经在审查《Go Token 文档》(https://cs.opensource.google/go/go/+/refs/tags/go1.17:src/go/token/token.go),并注意到 Go Token 类型中缺少 bool 类型。

是否有特定原因导致它未被包含在内?

英文:

I have been reviewing the Go Token Documentation and I have noted that the Go Token type for bool is missing.

Is there a reason why it's not included?

答案1

得分: 5

truefalse预声明标识符,而不是保留字。

在AST级别上,预声明标识符与其他标识符一样处理。预声明标识符由IDENT标记类型表示,并由scanIdentifier方法进行扫描。

假设没有遮蔽,这些标识符在名称解析期间绑定到全局块中的truefalse

英文:

true and false are predeclared identifiers, not reserved words.

At the level of the AST, predeclared identifiers are handled like all other identifiers. Predeclared identifiers are represented by the IDENT token type and are scanned by the scanIdentifier method.

Assuming no shadowing, the identifiers are bound to true and false in the universal block during name resolution.

huangapple
  • 本文由 发表于 2021年9月7日 00:45:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/69077925.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定