(- (expt 3 2))
is always -9 without needing to ask which has higher precedence. (expt -3 2)
is likewise always 9. There is no question if - is a binary or unary operator in prefix notation and what its order of operation should be.Likewise, in dc
3 _ 2 ^ p
_3 2 ^ p
and 3 2 ^ _ p
where '_' is the negation operator (it can be used for writing -3 directly as _3, but _ 3 is a parse error) return their results without any question of order of operations.When you start touching infix, you get into https://en.wikipedia.org/wiki/Shunting_yard_algorithm which was not a fun part of my compiler class.
(And yes, I do recognize your credentials ... I still think that lisp and forth (above examples for dc) are better notational systems for working with computers even if it takes a bit of head wrapping for humans).