This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Gumball's profile picture

Brainf*** Interpreter

Started by Gumball, 12 December 2015 - 09:14 PM
Gumball #1
Posted 12 December 2015 - 10:14 PM
Since Brainf*** is so amazingly simple, I gave it a go. 20 seconds later this happened.

Same syntax, but I added a few other things so its a bit more fun to play around with.

Characters:
Spoiler> increment data pointer
< decrement data pointer
+ increment current data value from current data pointer
- decrement current data value from current data pointer
, current data pointer is now 1 character input as numerical code
. show current data pointer as character
[ open loop
] close loop
* (not in regular Brainfudge) Terminates program
% (not regular) Sets current loop to a for loop. Make a normal loop, but it will loop only as many times as the current data pointer was.
^ (not regular) Sets current loop to a while loop. (Default loop type is while, btw)
~ (not regular) Program sleeps depending on the current data pointer.

Character numerical codes are:
SpoilerAlphabet in lowercase, 1-26
Alphabet in UPPERCASE, 27-52
Numbers 1-9 then 0, 53-63
Shift codes, aka !@#$%^&amp;*() going from 64-73
And then just regular space, as 74
"Grammar":
SpoilerOnly real thing to know is: While loops only exit until current byte is equal to zero.

Pastebin: pastebin get mmjv002n brainf
Edited on 13 December 2015 - 08:25 AM
FUNCTION MAN! #2
Posted 13 December 2015 - 01:21 AM
If you want compatibility, use string.char to make a character and string.byte to read a character.
Gumball #3
Posted 13 December 2015 - 07:45 AM
If you want compatibility, use string.char to make a character and string.byte to read a character.

Oh, thanks, I was wondering how to return a character as a numerical code and get it as one. Thanks :D/>

Edit: Updated that, also added a debug and normal mode (WIP)
Edited on 13 December 2015 - 07:05 AM