gpt4 book ai didi

javascript - 此语法是否通过右递归定义右结合性

转载 作者:行者123 更新时间:2023-11-30 15:04:19 25 4
gpt4 key购买 nike

我正在阅读 this article关于将 ** 运算符添加到 EcmaScript 规范中,作者声明如下:

Exponentiation must be evaluated before multiplication and more importantly, the BNF grammar must be written such that the operator’s right-associativity is clearly defined (unlike MultiplicativeExpression, which is left-associative).

并且他在文法中定义了新的非终结符号ExponentiationExpression为:

ExponentiationExpression : 
UnaryExpression[?Yield]
UnaryExpression[?Yield] ** ExponentiationExpression[?Yield]

MultiplicativeExpression[Yield] :
ExponentiationExpression[?Yield]
MultiplicativeExpression[?Yield] MultiplicativeOperator ExponentiationExpression[?Yield]

This article指出:

To write a grammar that correctly expresses operator associativity:

  • For left associativity, use left recursion.
  • For right associativity, use right recursion.

他似乎遵循了该规则并通过对此处的 ExponentiationExpression 使用右递归 来定义结合律:

ExponentiationExpression -> UnaryExpression[?Yield] ** ExponentiationExpression[?Yield]

我说得对吗?

最佳答案

Am I right?

关于javascript - 此语法是否通过右递归定义右结合性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46025375/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com