Brainforever
Jump to navigation
Jump to search
Brainforever is an esolang invented by User:None1. It is bf, but [CODE] is an infinite loop.
Examples
Infinite loop
[]
Print A infinitely
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++[.]
Truth Machine
It's impossible to write a Truth Machine in Brainforever.
Interpreter
Python
import sys
def bf(code):
s=[]
matches={}
tape=[0]*1000000
for i,j in enumerate(code):
if j=='[':
s.append(i)
if j==']':
m=s.pop()
matches[m]=i
matches[i]=m
cp=0
p=0
while cp<len(code):
if code[cp]=='+':
tape[p]=(tape[p]+1)%256
if code[cp]=='-':
tape[p]=(tape[p]-1)%256
if code[cp]==',':
c=sys.stdin.read(1)
tape[p]=(ord(c) if c else 0)%256
if code[cp]=='.':
print(chr(tape[p]),end='')
if code[cp]=='<':
p-=1
if code[cp]=='>':
p+=1
if code[cp]=='[':
if 0:
cp=matches[cp]
if code[cp]==']':
if 1:
cp=matches[cp]
cp+=1
bf(sys.stdin.read())