根据 ecma262 的备选方案是什么意思?

What is the meaning of an alternative according to ecma262?

我一直在想 "alternative"ecma262.

中是什么意思

我看到术语 “替代” 在规范中被多次使用。

这里有一些例子:

引用自此 section

so, in this example, the nonterminal ForStatement actually has four alternative right-hand sides.

引用自此 section

A production that has multiple alternative definitions will typically have a distinct algorithm for each alternative

引用自此 section

a production that has multiple alternative definitions will typically have for each alternative a distinct algorithm for each applicable named static semantic rule.

“具有多个替代定义的作品”是什么意思?

我假设 alternative 表示作品的右侧,这里有一张简单的图片可以说明我的意思。

在图片上我们可以看到粉色覆盖的区域是整个Production.

红色覆盖的区域是非终端

最后我假设紫色覆盖的区域是替代

A production that has multiple alternative definitions will typically have a distinct algorithm for each alternative

然而这听起来还是不对,因为一个单独的作品怎么可能有多种选择呢?

这个词有its normal, English meaning:

offering or expressing a choice


所以举个例子:

so, in this example, the nonterminal ForStatement actually has four alternative right-hand sides.

就在那之前 lists 他们:

for ( LexicalDeclaration ; ) Statement
for ( LexicalDeclaration ; Expression ) Statement
for ( LexicalDeclaration Expression ; ) Statement
for ( LexicalDeclaration Expression ; Expression ) Statement 

您可以在关键字 for.

的右侧放置四个替代项

在形式语言理论中,产生式有 left-hand 边和 right-hand 边。但是在像 EcmaScript 规范这样不太正式的上下文中,将具有相同 left-hand 面的作品分组是很常见的。

因此,在正式语境中,您可能会看到:

A : B
A : C D

你会说“有 2 部作品,每部都有左轴和右轴。”

但在 EcmaScript 规范中,您可能会看到:

A :
  B
  C D

你会说“有 1 个产品,有一个 LHS 和 2 个备选方案。” (这避免了混淆“right-hand side”是指冒号后的所有内容,还是仅指一行。)

因此,当您问“一个单独的作品怎么可能有多种选择?”时,听起来您在考虑正式的语境,而这确实没有意义。但它在不太正式的上下文中确实有意义。

(请注意,EcmaScript 规范实际上使用了两种术语方案,但通常不难知道是哪一种。)