In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

BrainCrash Interpreter

http://cfs.maxn.jp/neta/BrainCrash.php
「,」を実装するついでにいろいろやってみた
そのままRun推奨
Brainf*ckとしてを動作させるときはソースの先頭と末尾に[>]を追加
Get Adobe Flash player
by Susisu 27 Jun 2010
/**
 * Copyright Susisu ( http://wonderfl.net/user/Susisu )
 * GNU General Public License, v3 ( http://www.gnu.org/licenses/quick-guide-gplv3.html )
 * Downloaded from: http://wonderfl.net/c/g4PA
 */

/*
        http://cfs.maxn.jp/neta/BrainCrash.php
        「,」を実装するついでにいろいろやってみた
        そのままRun推奨
        Brainf*ckとしてを動作させるときはソースの先頭と末尾に[>]を追加
*/
package{
    import flash.display.*;
    import flash.text.*;
    import flash.events.*;
    import flash.geom.Rectangle;
    [SWF(width="320", height="320", backgroundColor="0x000000", frameRate="60")]
    public class Bfi2 extends Sprite{
        private var code:TextField=new TextField();
        private var ext:TextField=new TextField();
        private var button:Sprite=new Sprite();
        private var btf:TextField=new TextField();
        private var gct:TextField=new TextField();
        private var okb:Sprite=new Sprite();
        private var okt:TextField=new TextField();
        private var a:Array,q:Array,p:uint,n:uint,l:uint,t:uint,j:uint;
        public function Bfi2(){
            code.type=TextFieldType.INPUT;
            code.border=true;
            code.textColor=0x000000;
            code.backgroundColor=0xffffff;
            code.background=true;
            code.text="[>]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++++++++++.-.----------.+.+++++++++++++.------------.++++++.[-]<<<<<<<";
            code.x=10;
            code.y=10;
            code.width=300;
            code.height=160;
            code.wordWrap=true;
            addChild(code);

            ext.type=TextFieldType.INPUT;
            ext.border=true;
            ext.backgroundColor=0xffffff;
            ext.textColor=0x000000;
            ext.background=true;
            ext.text="";
            ext.x=10;
            ext.y=210;
            ext.width=300;
            ext.height=100;
            ext.wordWrap=true;
            addChild(ext);

            btf.text="Run";
            btf.selectable=false;
            btf.backgroundColor=0x000080;
            btf.textColor=0xffffff;
            btf.background=true;
            btf.border=true;
            btf.x=140;
            btf.y=180;
            btf.autoSize=TextFieldAutoSize.LEFT;
            button.addChild(btf);
            addChild(button);

            gct.type=TextFieldType.INPUT;
            gct.border=true;
            gct.backgroundColor=0xffffff;
            gct.textColor=0x000000;
            gct.background=true;
            gct.text="";
            gct.x=140;
            gct.y=50;
            gct.width=30;
            gct.height=20;
            gct.wordWrap=false;

            okt.text="OK";
            okt.selectable=false;
            okt.backgroundColor=0x000080;
            okt.textColor=0xffffff;
            okt.background=true;
            okt.border=true;
            okt.x=144;
            okt.y=80;
            okt.autoSize=TextFieldAutoSize.LEFT;
            okb.addChild(okt);
            
            okb.addEventListener(MouseEvent.CLICK,input);        
            button.addEventListener(MouseEvent.CLICK,init);
        }
        private function init(e:MouseEvent):void{
            ext.text="";
            a=new Array(30000);
            for(n=0;n<30000;n++)a[n]=0;
            a.splice(0,13,72,101,108,108,111,44,32,119,111,114,108,100,33);
            q=code.text.split("");
            p=0;
            n=0;
            l=q.length;
            run(e);
        }
        private function run(e:MouseEvent):void{
            for(;n<=l;n++){
                if(n==l){
                    while(a[p]!=0){
                        ext.appendText(String.fromCharCode(a[p]));
                        p++;
                    }
                    ext.appendText("[End]");
                    break;
                }
                if(q[n]==">"){if(p<30000)p++;}
                else if(q[n]=="<"){if(p>0)p--;}
                else if(q[n]=="+")a[p]=a[p]<255?a[p]+1:0;
                else if(q[n]=="-")a[p]=a[p]>0?a[p]-1:255;
                else if(q[n]==".")ext.appendText(String.fromCharCode(a[p]));
                else if(q[n]=="|"){a[p+1]|=a[p];p++;}
                else if(q[n]=="&"){a[p+1]&=a[p];p++;}
                else if(q[n]=="~")a[p]=~a[p]&0x000000FF;
                else if(q[n]=="^"){a[p+1]^=a[p];p++;}
                else if(q[n]==","){getChar();break;}
                else if(q[n]=="["){
                    if(a[p]==0){
                        t=0;
                        for(j=n+1;j<l;j++){
                            if(q[j]=="[")t++;
                            if(q[j]=="]"){
                        if(t>0)t--;
                        else{
                            n=j;
                            break;
                        }
                            }
                        }
                    }
                }
                else if(q[n]=="]"){
                    if(a[p]!=0){
                        t=0;
                        for(j=n-1;j>=0;j--){
                            if(q[j]=="]")t++;
                            if(q[j]=="["){
                        if(t>0)t--;
                        else{
                            n=j;
                            break;
                        }
                            }
                        }
                    }
                }
            }
        }
        private function getChar():void{
            gct.text="";
            addChild(gct);
            addChild(okb);
            stage.focus=gct;
            code.backgroundColor=0xc0c0c0;
            ext.backgroundColor=0xc0c0c0;
        }
        private function input(e:MouseEvent):void{
            a[p]=gct.text.charCodeAt(0);
            removeChild(gct);
            removeChild(okb);
            code.backgroundColor=0xffffff;
            ext.backgroundColor=0xffffff;
            n++;
            run(e);
        }
    }
}