03-30-2016, 02:40 PM
https://gist.github.com/anonymous/b9d2fb...0288a22a24
bfsint.py:
test.bfs:
This is a bf-based language.
Bash:
Meny ppl tried to fix it, no one could
bfsint.py:
Code:
#!/usr/bin/python3
# Python interpreter for Brainfuck# (bf#) by TheCrimulo
# bf# by TheCrimulo
# Open domain, feel free to use
#
# paukkupalika: brainkek
# me: yustin b-evr
import sys
# Get filename, open it and convert it to a plain string.
if len(sys.argv) == 1:
with open('bfsint.py', 'r+') as f:
for l in f.readlines():
print(l)
quit()
filename = sys.argv[1]
with open(filename, 'r') as f:
evr = f.read().replace('\n', '')
# Tape and pointers
tape = list(range(256))
for i in tape:
tape[i] = 0;
pointer_pos = 0
cycle = 0
# Extra vars
assign = []
stack = list(range(1))
for i in stack:
stack[i] = 0;
depthl = 0
depthlsave = 0
# Iterate through each character and interpret the actions
#for i in range(0, len(evr)):
i = 0
while i < len(evr):
cval = tape[pointer_pos]
if evr[i] == ">":
pointer_pos += 1
elif evr[i] == "<":
pointer_pos -= 1
elif evr[i] == "+":
tape[pointer_pos] += 1
elif evr[i] == "-":
tape[pointer_pos] -= 1
elif evr[i] == ".":
print('#i' + str(pointer_pos) + ': ' + str(cval))
elif evr[i] == "@":
asciival = str(chr(tape[pointer_pos]))
print('#a' + str(pointer_pos) + ': ' + asciival)
elif evr[i] == "$":
f = i + 1
while evr[f] != "*":
assign.append(evr[f])
f += 1
assl = ''.join(assign)
assld = int(assl, 16)
tape[pointer_pos] = assld
# $2A*[>++[>++<-]<-]
elif evr[i] == "[":
depthl += 1
depthlsave = depthl
if cval == 0:
while (evr[i] != "]") or (depthl != depthlsave):
i += 1
if evr[i] == "[":
depthl += 1
if evr[i] == "]":
depthl -= 1
continue
else:
stack.append(i)
elif evr[i] == "]":
if cval == 0:
if len(stack) == 1:
del stack[0]
continue
else:
lenstack = len(stack) - 1
del stack[lenstack]
continue
else:
i = stack[len(stack) - 1]
i += 1
test.bfs:
Code:
$2*.[>+++[>++<-]<-]
This is a bf-based language.
Bash:
Code:
thecrimulo@ubuntu:~/Escritorio/subatom/bf#$ python3 bfsint.py hworld.bfs
#i0: 2
Traceback (most recent call last):
File "bfsint.py", line 81, in <module>
del stack[lenstack]
IndexError: list assignment index out of range
Meny ppl tried to fix it, no one could