elikaski / BF-it

A C-like language to Brainfuck compiler, written in Python
MIT License
120 stars 11 forks source link

Add support for Unary Minus and Unary Plus #50

Open NeeEoo opened 3 years ago

NeeEoo commented 3 years ago

Unary Plus is unneeded since it does nothing. Defined as +NUM Unary Minus is defined as -NUM They should not break BINOP.

elikaski commented 3 years ago

We don't have signed numbers

NeeEoo commented 3 years ago

Yea but it still might help to check if the number is negative such as -1. Currently you would do 0-1

elikaski commented 3 years ago

0-1 is 255 It is possible to support unary minus sign syntax-wise, but then we would have (-1 == 255) evaluate to true and so on I don't know if it's a desired behavior... What do you think?

NeeEoo commented 3 years ago

The resulting bf code would be [-]- since the compiler shouldn't assume the cell size. If i did 5-6 it would become -1. If it automatically set it to 255 and if the interpreter was 16-bit cells the check would fail.

NeeEoo commented 3 years ago

It would still be that 0-1 == 255. But for 16-bit interpreters it would be 0-1 == 65535

The compiler shouldn't convert -1 to the literal 255. It should use wrapping.