Skip to content

mreza0100/bf-Interpreter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go get -u github.com/mreza0100/brainfuck

Usage

myCustomWritter := new(bytes.Buffer)
bf := brainfuck.New(&brainfuck.NewOptions{
      // inline documention for each of them is accessible in the source code
      MemorySize:     100,
      IsMemoryStatic: true,
      Verbos:         false,
      Writter:        myCustomWritter,
      Reader:         nil, // will fallback to os.Stdin
})
instructions := "++++[-.>+<]"
bf.Run(strings.NewReader(instructions))
// continue to run more instructions
instructions = ">."
bf.Run(strings.NewReader(instructions))

Custom Commands

bf := brainfuck.New(&brainfuck.NewOptions{Verbos: true, StaticMemory: false, MemorySize: 10})

err := bf.AddCustomCommand('@', func(ctl brainfuck.CommandsCtl) {
      // you have tools to do almost anything
      ctl.GetMemory()
      ctl.GetPointerPosition()

      ctl.Print()
      ctl.MoveForward()
      ctl.MoveBackward()
      ctl.Increment()
      ctl.Decrement()
      ctl.Read()
})
if err != nil {
      panic(err)
}

err = bf.RemoveCustomCommand('@')
if err != nil {
      // error in case of custom instruction not found
      panic(err)
}

bf.Run(strings.NewReader("@"))

About

Brainfuck Interpreter written in Go

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages