struct Interpreter

Overview

This is the library for handling brainfuck code. The struct Interpreter can be instantiated like so...

Interpreter.new("+++++++++[>++++++++++<-]>.")

Where the arguments to the initializer is a string containing the brainfuck code.

Defined in:

interpreter.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(str : String) #

[View source]

Instance Method Detail

def bracket_map : Hash(Int32, Int32) #

Stores the start and end positions of loops in a hash


[View source]
def code : String #

The code string that is passed to the program by the user with -d and --data flags


[View source]
def consume #

consumes a single char at a time


[View source]
def create_bracket_map(str : String) #

[View source]
def interpret #

Iterates through the code string and compares each character against a case statement for that character raises a custom BrainFuckError when a unknown BF command is given


[View source]
def mem : Array(UInt8) #

A 30k length array of memory as specified in the BF spec. It starts initialize to 0


[View source]
def pc : Int32 #

The Program Counter keeps track of how far along we are in the code And is set to the start or end of the loop when it hits [ or ]


[View source]
def sp : Int32 #

Stack Pointer indexes into the area in memory that is modified by the + and - instructions


[View source]