gbdev / rgbds

Rednex Game Boy Development System - An assembly toolchain for the Nintendo Game Boy and Game Boy Color
https://rgbds.gbdev.io
MIT License
1.33k stars 176 forks source link

can't subtract in `set` statements #222

Closed yenatch closed 5 years ago

yenatch commented 6 years ago

been meaning to report this for some time. either of the following produce a syntax error:

x = y - 5
x set y - 5

the following does work however:

x = y + -5
AntonioND commented 6 years ago

This seems to be caused by the two following lines (T_ID can be a const, so it is ambiguous):

https://github.com/rednex/rgbds/blob/8954858bf79a9ad48eacb063d42b47882ede1175/src/asm/asmy.y#L1150-L1156

I added the second line (even though I knew there was a syntax conflict) to fix another problem. If you subtract two labels, the result is known if:

However, without the check, this would also work in the following case:

However, I'd swear I've seen this problem long before the patch that introduced the check.

AntonioND commented 6 years ago

Yes, this bug has always been there: http://gbdev.gg8.se/wiki/articles/RGBDS

Subtracting a numeric constant from a data structure symbol (rb, rw, ...) produces a parse error. It's still possible, however, to add a negative number.

pinobatch commented 5 years ago

I've made a couple test cases for this parser issue bug222test1.s.txt bug222test2.s.txt