此语法是否通过右递归定义右结合性
Does this grammar define right-associativity by right recursion
我正在阅读 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?
是.
我正在阅读 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?
是.