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

22 views Asked by At

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?

1

There are 1 answers

0
Twareintor On

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.