The readme text for ASM6 says that the unary '-' operator has the second highest precedence (below only parantheses), but the program itself gives it the lowest precedence. When the unary '-' operator is processed, it is given a precedence of WHOLE_EXP, which is the lowest precedence in the program. Indeed, with tests, I have seen that a statement such as:
-5 + 3 * 9
is processed as though it were written:
-(5 + 3 * 9)
when, suggesting from the readme, it should be instead processed as though it were written:
(-5) + 3 * 9
Which yield two different results. It seems that every unary operator in ASM6 has this error. This would be easy to fix by adding a new precedence type higher than MULDIV, such as UNARY. Perhaps we can easily fix this?
Possible Error With Unary '-' Operator in ASM6
Moderator: Moderators
C puts all its unary prefix operators in the same precedence, including ! and * and sizeof. So I guess it'd have precedent. But watch out: the < (extract bits 7-0) and > (extract bits 15-8) operators are also unary, and you'd need to parenthesize their arguments if they're calculated:
Code: Select all
lda #>(table + 8)
sta 1
lda #<(table + 8)
sta 0