Rough Book

random musings of just another computer nerd

Tag: computing

A brainfuck interpreter in bAdkOde

A few days before I left India, I started writing a brainfuck interpreter in bAdkOde. I finished implemented all the instructions, excepting for looping. I actually finished the code (and fixed all bugs) while I was in the air, flying from Dubai to Los Angeles. Emirates Airlines has power-plugs for your laptop on the seat. It’s pretty sweet!

An interesting thing I noticed was that I couldn’t perfectly emulate the input instruction. I’m feeding the brainfuck code to the interpreter from STDIN and so that might be the problem. I’ve noticed that brainfuck interpreters written in brainfuck have the same problem. You have to specify program input before hand. This is what I’ve decided to do. You write brainfuck code, and then mark the end of program code by an exclamation mark. After the exclamation mark, you provide any input, and then mark the end of input by another exclamation mark. Programs that do not have any input end with two exclamation marks. After I finished writing the interpreter, I commented it. While I was doing this, I noticed a lack of labels in bAdkOde. So, I decided to update the interpreter to include them. Speaking of which, I really ought to rewrite the interpreter sometime…

Anyway, here is the code to the interpreter. I’m providing a link to it, because the commented version is rather large. But here’s the expanded (without labels or macros), unformatted version:

>3a>1b{!b?b>b[a)b-91b{=b+1[b>1b}+91b-93b{=b-1[b>1b}+93b(b+1a-33b}>0[a+1a>2b>a[b>1b{!b?b>b[a+1a-33b}>1b>a[b>0a>[aa>ab{=a>1a>[ab>3a{![a)a>[aa-62a{=a+1b-30000b)a>ba{+b>1b>[bb)b>0b-1b>0a}{-a+30000b)b>0a}(b(a+62a}+62a-60a{=a-1b)a>1a>[aa-ab>ba{-b>1a>[aa+30000a>ab)b>0b>0a-1a}{+a>1a>[aa+ab)b>0a-1a}(b(a+60a}+60a-43a{=a+1[b+43a}+43a-45a{=a-1[b+45a}+45a-46a{=a"[b+46a}+46a-44a{=a)a>2a>[aa>[a[b>2a+1[a(a+44a}+44a-91a{=a(a)b)a>[bb{=b>0b>1[b{![b(a+1a)a>[aa)a-91a{=a+1[a>1a}+91a-93a{=a-1[a>1a}+93a(a}(a-1a)a>1b}(a(b)a+91a}+91a-93a{=a(a)b)a>[bb{!b>0b>0[b-1[b{![b(a-1a)a>[aa)a-91a{=a+1[a>1a}+91a-93a{=a-1[a>1a}+93a(a}>0b}(a(b)a+93a}+93a(a+1a}>1a>0b}{!b"85"110"109"97"116"99"104"101"100"32"98"114"97"99"107"101"116"115>0b}

Also, this is additional proof for Turing Completeness. Yes, I’m a nerd! 🙂

bAdkOde is Turing Complete

In my previous post, I suggested that bAdkOde might be Turing Complete by writing a quine. One of the ways to actually prove Turing Completeness is to try and write an interpreter for another Turing-Complete language in bAdkOde. Another approach involves providing a direct translation from another Turing-Complete language into bAdkOde. Here, I prove the Turing Completeness of bAdkOde by providing a direct translation from Brainfuck into bAdkOde.
Read the rest of this entry »

A bAdkOde quine (which suggests that bAdkOde is Turing Complete)

On the bAdkOde project page, I mentioned that I didn’t know whether bAdkOde is Turing Complete (although I suspected it). I also mentioned that if I was able to write a quine in bAdkOde, then it would probably mean that it is Turing Complete. I was able to write one after going through this excellent quine tutorial by Dave Cope.
Read the rest of this entry »

All original content on these pages is fingerprinted and certified by Digiprove
%d bloggers like this: