Skip to content
/ bf Public

bf is a Brainfuck interpreter written in Elixir.

License

Notifications You must be signed in to change notification settings

lukad/bf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bf

bf is a simple Brainfuck interpreter written in Elixir.

Documentation

Documentation for the latest release is availabe at hexdocs.pm.

Installation

Automatic installation with mix:

mix escript.install bf

Manual installation

git clone https://github.com/lukad/bf.git
cd bf
MIX_ENV=prod mix do escript.build, escript.install

Usage

$ cat <<EOF> hello.bf
+++++ +++++             initialize counter (cell #0) to 10
[                       use loop to set the next four cells to 70/100/30/10
    > +++++ ++              add  7 to cell #1
    > +++++ +++++           add 10 to cell #2
    > +++                   add  3 to cell #3
    > +                     add  1 to cell #4
    <<<< -                  decrement counter (cell #0)
]
> ++ .                  print 'H'
> + .                   print 'e'
+++++ ++ .              print 'l'
.                       print 'l'
+++ .                   print 'o'
> ++ .                  print ' '
<< +++++ +++++ +++++ .  print 'W'
> .                     print 'o'
+++ .                   print 'r'
----- - .               print 'l'
----- --- .             print 'd'
> + .                   print '!'
> .                     print '\n'
EOF

$ bf hello.bf
Hello World!

Interpreter Info

  • Cells are 8 bits wide
  • Cells wrap around 256
    • 255 + 1 = 0
    • 0 - 1 = 255
  • The tape is 30000 cells large
  • The tape pointer wraps around 30000
  • '0' on STDIN signals EOF