Skip to content

Brainfuck Interpreter

Anar Software edited this page Jan 21, 2016 · 11 revisions

What is Brainfuck Interpreter?

Brainfuck Interpreter is a Java program that directly executes Brainfuck source code; parse the source code and perform its behavior directly.

Usage

java -jar BrainJuck.jar interpreter [-debug] source_file

source_file - Full path to Brainfuck source code file.

For example:

java -jar BrainJuck.jar interpreter /examples/Copyright.bf

-debug - Enables debug command # (hash / number sign), and also prints out executing stats at the end of the program.

For example:

java -jar BrainJuck.jar interpreter -debug /examples/Copyright.bf

It outputs

BrainJuck - Rapid Application Development with only 3 bits!
Copyright (c) 2016 Anar Software LLC. < http://anars.com >

Brainfuck Interpreter Statistics
=================================
Source Code File             : /examples/Copyright.bf
Source Code File Size        : 1963 bytes.
Number of Brainfuck Commands : 1963
Number of Commands Executed  : 6193
Total Executing Time         : 31 milliseconds.
Source Code Load Time        : 4 milliseconds.
Command Execution Time       : 27 milliseconds.
Number of Memory Cells Used  : 2
End of Execution Memory Dump :
{010} 000  000  000  000  000  000  000 	{.} .  .  .  .  .  .  .

Some Features

Cell Type

It uses 8-bit unsigned char memory cell, which are initially set to 0 (zero)

For example:

+.

It outputs ASCII 1 (one) to the console.

Cell Wrapping

Interpreter wraps the cell value to back 0 (zero) when larger than 8-bit (28 − 1 = 255) and wraps back to 255 (two hundred fifty five) when the cell value is less than 0 (zero) For example:

--.

It outputs ASCII 254 (two hundred fifty four) "■" (black square) to the console.

Dynamic Memory Allocation

It allocates memory dynamically when the cell value is increased or decreased.

For example:

The Interpreter doesn't allocate memory, when you run this code below.

>>>

However, it expands the memory size to 4 bytes, when you run this code below;

>>>+

Each memory cell 8-bit unsigned char, and initially set to 0 (zero).