# A whole Brainf\*\*\* Compiler

**URL:** <https://forum.kirupa.com/t/a-whole-brainf-compiler/175560>\
**Category:** Uncategorized\
**Created:** [January 15, 2006, 9:37pm UTC](https://forum.kirupa.com/t/a-whole-brainf-compiler/175560 "2006-01-15T21:37:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![McGiver](https://avatars.discourse-cdn.com/v4/letter/m/6de8d8/32.png) [@McGiver](https://forum.kirupa.com/u/McGiver)\
**Post date:** [January 15, 2006, 9:37pm UTC](https://forum.kirupa.com/t/a-whole-brainf-compiler/175560/1 "2006-01-15T21:37:36Z")

</div>

I guess I really fathom kirupa’s rules, but I wanted to do this for a very long time:

A compiler/interpreter in Flash! :jailbreak

the Language is Brainf uck (BF, and I hope the mod’s don’t sue me for that name: I didn’t invent it)

> [@by Ben Olmstead](#):
>
> Believe it or not this language is indeed Turing complete!  
> Combines the speed of BASIC with the ease of INTERCAL and  
> the readability of an IOCCC entry!

(but forget about the speed thing - seriously: a lot worse with my compiler)

since the Forum’s swearing blocker blocked any attempt to post a link to anything containing BF, I suggest you to google for  
Brainf uck wikipedia

here a list of the commands

```auto
Character Meaning
>
	increment the pointer (to point to the next cell to the right).
<
	decrement the pointer (to point to the next cell to the left).
+
	increment (increase by one) the byte at the pointer.
-
	decrement (decrease by one) the byte at the pointer.
.
	output the value of the byte at the pointer.
,
	accept one byte of input, storing its value in the byte at the pointer.
[
	jump forward to the command after the corresponding ] if the byte at the pointer is zero.
]
	jump back to the command after the corresponding [ if the byte at the pointer is nonzero.

```

I hope you will be abled to keep the commands 😉

so here it comes:

```auto
for (i=(a = ["code (press Shift+Enter to compile)","input", "output","dynamic", "input","input", "status","dynamic"]).length-1;i>0;i-=2) {
	_root.createTextField(a[i-1]+"title", 10+i+1, 10, 240*(Math.log((i-1)/2+1))+10, 500, 20).text = a[i-1];
	_root.createTextField(a[i-1], 10+i, 10, 240*(Math.log((i-1)/2+1))+30, 500, 85/((i-1)/2+0.6)).type =a*;
	_root[a[i-1]].border = true;
}

_root.onEnterFrame = function() {
	((run == ((_root[a[0]].multiline=1)-(_root[a[2]].multiline=1)) || run == undefined) && (Key.isDown(Key.SHIFT) && Key.isDown(Key.ENTER))) ? pocket=[(n=20)-20, (maxIterations=10000)-10000, awaitingInput=0, (run=1)-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] : 1;
	if (run && awaitingInput == 1) {
		_root[a[6]].text = "awaiting input";
		((Key.isDown(Key.ENTER) && _root[a[4]].text.length>0)) ? inputstack=_root[a[4]].text : 1;
		((Key.isDown(Key.ENTER) && _root[a[4]].text.length>0)) ? _root[a[4]].text="" : 1;
		(inputstack.length>0) ? pocket[n]=inputstack.charCodeAt(0) : 1;
		(inputstack.length>0) ? awaitingInput=2 : 1;
		(inputstack.length>0) ? inputstack=inputstack.substring(1) : 1;
	} else {
		for (((awaitingInput == 0) && (run == 1) && (Key.isDown(Key.SHIFT) && Key.isDown(Key.ENTER))) ? _root[a[(i=0)+2]].text="" : 1; (run == 1) && (maxIterations>0) && (i<_root[a[0]].text.length) && ((awaitingInput == 2) || (awaitingInput == 0 && (Key.isDown(Key.SHIFT) && Key.isDown(Key.ENTER)))); i++) {
			(_root[a[0]].text.charAt(i) == ">") ? n++ : loops=0;
			(_root[a[0]].text.charAt(i) == "<") ? n-- : loops=0;
			(_root[a[0]].text.charAt(i) == "+") ? pocket[n]++ : 0;
			(_root[a[0]].text.charAt(i) == "-") ? pocket[n]-- : 0;
			(_root[a[0]].text.charAt(i) == ",") ? awaitingInput=1 : _root[a[3]].text="compiling";
			(_root[a[0]].text.charAt(i) == ".") ? _root[a[2]].text += String.fromCharCode(pocket[n]) : _root[a[6]].text="compiling";
			for (maxIterations--; (maxIterations>0) && (pocket[n] != 0) && (_root[a[0]].text.charAt(i) == "]" || loops>0) && (i>=0); i--) {
				(_root[a[0]].text.charAt(i) == "]") ? loops++ : 1;
				(_root[a[0]].text.charAt(i) == "[") ? loops-- : 1;
			}
			(maxIterations>0) ? _root[a[6]].text="finished" : _root[a[6]].text="safety quit, more than "+10000+" iterations";
		}
		(i == _root[a[0]].text.length || !(maxIterations>0)) ? run=0 : 1;
	}
};

```

I hope this is valid 🙂

try to use this link:

-\> [http://www.digitalhalo.de/kirupa/bfc\_18.html&lt;-](http://www.digitalhalo.de/kirupa/bfc_18.html&lt;-)

see also  
[COLOR=“DarkOrange”]-\>[sharks](http://www.kirupa.com/forum/showthread.php?t=205743)  
-\>[flower chain](http://www.kirupa.com/forum/showthread.php?t=205347)[/COLOR]

the attached is a little slow, and seems to have problems with shift+enter ☹
