22
EV-EV
6y

Yeet I just made a brainfuck compiler with python

Comments
  • 3
    Compiler or interpreter?
  • 1
    I made a compiler and a 1/2 done interpreter
  • 0
    Sadly I forgot to push to GitHub, I will provide the link tomorrow ;(
  • 1
    But here is a sample of the compiled code:
    array=[]
    for x in range(50):
    array.append(0)
    ptr=0

    def right():
    global ptr,array
    ptr+=1
    def left():
    global ptr,array
    ptr-=1
    def plus():
    global ptr,array
    array[ptr]+=1
    def minus():
    global ptr,array
    array[ptr]-=1
    def dot():
    global ptr,array
    print(chr(array[ptr]), end='', flush=True)
    #do def comma

    #YOUR CODE IS BELOW HERE

    plus()
    plus()
    plus()
    plus()
    plus()
    plus()
    plus()
    plus()
    plus()
    plus()
    cptr0=ptr
    while array[cptr0]!=0:
    right()
    plus()
    plus()
    plus()
    plus()
    plus()
    plus()
    plus()
    right()
    plus()
    plus()
    plus()
    plus()
    plus()
    plus()
    plus()
    plus()
    plus()
    plus()
    ...
    left()
    left()
    left()
    left()
    left()
    left()
    minus()

    right()
    minus()
    dot()
    right()
    minus()
    minus()
    dot()
    right()
    plus()
    plus()
    plus()
    dot()
    right()
    plus()
    dot()
    right()
    dot()
    right()
    plus()
    dot()
  • 0
    @irene I never realised that source to source had a different name... Although does converting to C++ and compiling count as transpiling or compiling?
  • 0
    @EV-EV
    Transpiling is when you go source to source, so if you are taking one syntax and converting it to c++ it's transpiling

    Compiling is going from source to machine or executable code.
  • 0
  • 3
    Use LLVM boi

    Though if your overall program ends up with machine code (BF -> C/C++ -> binary) then I'd call it (the whole thing, along with the C/C++ toolchain) a compiler. Plenty of compilers use C as an intermediate representation (such as the old Haskell compilation path).
  • 0
    @irene primarily != exclusively. Did you read the paragraph that comes right after the one you copied pasted?
Add Comment