Skip to content

gpolic/brainfuck-interpreter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What is Brainfuck ?

Brainfuck is an esoteric programming language created in 1993 by Urban Müller, and notable for its extreme minimalism. The language consists of only eight simple commands and an instruction pointer. The language's name is a reference to the slang term brainfuck, which refers to things so complicated or unusual that they exceed the limits of one's understanding.

The Brainfuck Programming Language http://www.muppetlabs.com/~breadbox/bf/

This is a Brainfuck interpreter written in Java, and implements some basic optimizations. The implementation is using 60K memory cells of 8bit. The primary focus is to simplify the main interpreter loop for efficient execution.

Performance

On Intel i7 4790 Desktop CPU (Quad core with H/T) , Windows 7, Oracle JDK 64bit

mandelbrot.b completes in 8.8 sec

hanoi.b code will complete in 1.0 sec

long.b code will complete in 6.0 sec

On Intel Pentium T3400 Laptop (Dual core 2.16Ghz), Windows 7, Oracle JDK 64bit

mandelbrot.b will complete in 24.0 sec

hanoi.b completes in 4.5 sec

long.b code will complete in 16.5 sec

Usage:

Create a new interpreter instance, by calling BrainInt.newProgram(String). Pass your code in a String parameter.

Call the method executeBf() on the interpreter object, to run the program. By default the input and output on the executed code is set to standard System.in and System.out streams

Example:

String brainFuckCode = ">++++[>++++++<-]>-[[<+++++>>+<-]>-]<<[<]>>>>--.<<<-.>>>-.<.<.>---.<<+++.>>>++.<<---.[>]<<.";

BrainInt brainInterpreter = BrainInt.newProgram(brainFuckCode);
try {
	brainInterpreter.executeBf();
} catch (Exception e) { ... }

Various Brainfuck optimizations are found in this extensive work by Mats Linander: http://calmerthanyouare.org/2015/01/07/optimizing-brainfuck.html

GitHub page: https://github.com/matslina

Optimizations here are heavily influenced on Daniel Cristofani's "quick and dirty interpreter": http://www.hevanet.com/cristofd/brainfuck/qdb.c

How to test a Brainfuck interpeter/compiler? Run Daniel's short test programs: http://www.hevanet.com/cristofd/brainfuck/tests.b

Reference

Releases

No releases published

Packages

No packages published

Languages