简体   繁体   English

具有幂运算符的表达式求值器中的项的优先级和关联

[英]Priority and association of terms in an expression evaluator with exponentiation operator

I am developing an expression evaluator.我正在开发一个表达式评估器。 Which association is considered to be correct for an expression containing more than one exponentiation operator?对于包含多个幂运算符的表达式,哪个关联被认为是正确的? For example, for the expression "10-2^2^0.5" : "10-(2^2) ^0.5"= 8 or "10-2^ (2^0.5)" = 7.33485585731 ?例如,对于表达式"10-2^2^0.5""10-(2^2) ^0.5"= 8"10-2^ (2^0.5)" = 7.33485585731

The result differs across languages and (possible) interpreters.结果因语言和(可能的)解释器而异。 However, most of them uses right-associative rule.但是,它们中的大多数使用右关联规则。 In Lua print(10-2^2^0.5) returns 7.3348 and in Visual Basic, Console.WriteLine(10-2^2^0.5) returns 8. The fact that different systems uses different rules suggest me that there is no defined rule for that.在 Lua print(10-2^2^0.5)返回 7.3348 而在 Visual Basic 中, Console.WriteLine(10-2^2^0.5)返回 8。不同系统使用不同规则的事实表明我没有定义规则为了那个原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM