Question

Is it possible to change the default operator precedence values in dart? I would like the precedence ordering of +, -, *, /, ^ to be consistent with mathematical notation with bitwise XOR representing power (+, -, *, and / are appropriately ordered, but ^ is lower than all of these).

In other words, is it possible to change precedences such that the following statements are equivalent:

a + b ^ c = a + (b ^ c),

for a, b, c of an appropriate class with relevant operators overriden.

(Precedence values given at very bottom of https://www.dartlang.org/docs/spec/latest/dart-language-specification.html#h.sn1uuf2ffwwd)

Was it helpful?

Solution

It is not possible to manipulate the operator precedence.

Experience with quite a few other programming languages tells that this is almost never possible in a programming language.

OTHER TIPS

I'd say yes it's possible: that's what commas are good for. Unfortunately you have to use the commas every time you want to deviate from the built-in precedence. (Other use of commas is to emphasize built-in precedence, but that is often scolded by linting and style enforcing tools).

The built-in operators' precedence is given and fixed as others indicated. As the standard specification you cited quotes "Operator precedence is given implicitly by the grammar."

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top