Brainf**k mIRC interpreter

By [Plornt] on Apr 28, 2011

Thanks to http://www.mathematik.uni-marburg.de/~schmidtm/brainfuck.php for the C code ofwhich I converted into mirc... painstakingly after realising I did a few things wrong...

It does seem to work, I think its 100% working but I may have implemented somthing incorrectly.

Basic examples work fine so you know...

/bf ++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.

Outputs: Hello World!

alias splitchr return $chr(32)
alias maxexecute return 10
alias memorytest {
  var %myCode plornt=Hello my name is plornt;test=2;out>plornt;

}
on *:INPUT:@Brainfuck:{
  if ($lines(datadump.txt)) {
    noop $bf(-continue,$1-,$read(datadump.txt,1),$read(datadump.txt,2),$read(datadump.txt,3),$read(datadump.txt,4))
  }
}
;Very useful alias when things piss you right off.
alias haltbf .remove datadump.txt

alias bf {
  window -e @brainfuck
  if ($1 != -continue) {
    bset -t &bfuck 1 $1-
    bset &mpointer 1 0
    var %spointer 1, %bpointer 1, %kl 0, %len $bvar(&bfuck,0)
  }
  else {
    ;Continue where we left off :P I suppose its easier to set the data first then input the stuff you inputted.
    var %spointer $gettok($3,1,32)
    var %bpointer $gettok($3,2,32)
    bset &bfuck 1 $4
    bset &mpointer 1 $5
    var %input $2 $+ -
    bset -t &mpointer %bpointer $right($left(%input,1),1)
    var %input $right(%input,$calc($len(%input) - 1))
    if ($6) { 
      bset &output 1 $6
    }
    var %len $bvar(&bfuck,0)
  }
  var %time $ctime
  while (%spointer <= %len) {
    if ($calc($ctime - %time) >= $maxexecute) {
      break
      msg $chan BrainF**k code halted: Max execute time of $duration($maxexecute) reached. 
    }
    var %byte = $chr($bvar(&bfuck,%spointer))
    var %mpvar = $bvar(&mpointer,%bpointer)
    if (%byte == +) bset &mpointer %bpointer $calc(%mpvar + 1)
    elseif (%byte == -) bset &mpointer %bpointer $calc(%mpvar - 1) 
    elseif (%byte == >) inc %bpointer
    elseif (%byte == <) dec %bpointer
    elseif (%byte == .) {
      echo @brainfuck -> $replace($chr(%mpvar),$chr(32), )
      bset &output $calc($bvar(&output,0) + 1) $iif(%mpvar,$v1,32)
    }
    elseif (%byte == ,) {
      if (!%input) {
        echo @brainfuck (Requesting more input) Type somthing to continue: 
        ;Saving status
        inc %spointer
        write -c datadump.txt
        write datadump.txt %spointer %bpointer
        write datadump.txt $bvar(&bfuck,1,$bvar(&bfuck,0))
        write datadump.txt $bvar(&mpointer,1,$bvar(&mpointer,0))
        write datadump.txt $bvar(&output,1,$bvar(&output,0))
        goto end
      }
      else {
        bset &mpointer %bpointer $iif($len(%input) != 1,$asc($right($left(%input,1),1)),0)
        if ($len(%input) != 1) var %input $right(%input,$calc($len(%input) - 1))
      }
    }
    elseif (%byte == $chr(91)) {
      if (%mpvar == 0) {
        inc %spointer 
        var %byte = $chr($bvar(&bfuck,%spointer))
        while (%kl > 0 || %byte != $chr(93)) {
          if (%byte == $chr(91)) inc %kl
          if (%byte == $chr(93)) dec %kl
          inc %spointer
          var %byte = $chr($bvar(&bfuck,%spointer))
        }
      }
    }
    elseif (%byte == $chr(93)) {
      if (%mpvar != 0) {
        dec %spointer
        var %byte = $chr($bvar(&bfuck,%spointer))
        while (%kl > 0 || %byte != $chr(91)) {
          if (%byte == $chr(91)) dec %kl
          if (%byte == $chr(93)) inc %kl
          dec %spointer
          var %byte = $chr($bvar(&bfuck,%spointer))
        }
        dec %spointer
      }
    }
    inc %spointer
  }
  haltbf
  echo @brainfuck Brainfuck output: $bvar(&output,1,$bvar(&output,0)).text
  :end
}

Comments

Sign in to comment.
Jordyk19   -  Jun 10, 2011

Very nice.

 Respond  
Person   -  Jun 10, 2011

I dont get what this script is for, i tried out the command and it just opened another window saying Hello World ....

 Respond  
troll   -  Apr 30, 2011

whats it do ?

 Respond  
[Plornt]   -  Apr 28, 2011

Updated: Now accepts input :)

type:
/bf >,[>,]<[.<]

Whatever you type in from there will be reversed :D

, is basically feed in next line of input.

Go here: Edited link - now a spam site as of October 9th

for epic brainfuck lines ofwhich you can use :) My personal favourite is the binary converter

 Respond  
Ahmed Zaggoudi   -  Apr 28, 2011

Cool +1

 Respond  
[Plornt]   -  Apr 28, 2011

Doesnt seem to take spaces very nicely >.> (Ok fixed in next version just messing about with , now)

/bf +++++++[>+++++++<-]>>++++++++[>+++++++++<-]<.>>[<<+.>>-]<<+.

is fun!

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.