(-) precedence
|
12-08-2022, 05:43 PM
Post: #9
|
|||
|
|||
RE: (-) precedence
I think some of the confusion may stem from early textbooks that demonstrated parsers that treated negative numbers as self-contained entities. So, -2 was treated as the number -2, rather than the number 2 to which a unary minus is applied.
If you use the latter approach, and then optimize for negative numbers by transforming "number with unary minus applied" to "negative number" after parsing, then everything is fine, but if you use the former approach, you end up with unary minus having highest priority -- and then you have to make sure that unary minus applied to anything that isn't a number literal behaves the same way, and then you end up with -2^2 being something different than 0-2^2, and that makes mathematicians sad. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)