Module brainfuck

Author: Dennis Felsing

This module implements an interpreter for the brainfuck programming language as well as a compiler of brainfuck into efficient Nim code.

Example:

import brainfuck, streams

interpret("++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.")
# Prints "Hello World!"

proc mandelbrot = compileFile("examples/mandelbrot.b")
mandelbrot() # Draws a mandelbrot set

Procs

proc readCharEOF*(input: Stream): char
Read a character from an input stream and return a Unix EOF (-1). This is necessary because brainfuck assumes Unix EOF while streams use 0 for EOF.   Source
proc interpret*(code: string; input, output: Stream)

Interprets the brainfuck code string, reading from input and writing to output.

Example:

var inpStream = newStringStream("Hello World!\n")
var outStream = newFileStream(stdout)
interpret(readFile("examples/rot13.b"), inpStream, outStream)
  Source
proc interpret*(code, input: string): string

Interprets the brainfuck code string, reading from input and returning the result directly.

Example:

echo interpret(readFile("examples/rot13.b"), "Hello World!\n")
  Source
proc interpret*(code: string)

Interprets the brainfuck code string, reading from stdin and writing to stdout.

Example:

interpret(readFile("examples/rot13.b"))
  Source

Macros

macro compileString*(code: string; input, output: expr): stmt
Compiles the brainfuck code read from filename at compile time into Nim code that reads from the input variable and writes to the output variable, both of which have to be strings.   Source
macro compileString*(code: string): stmt
Compiles the brainfuck code string into Nim code that reads from stdin and writes to stdout.   Source
macro compileFile*(filename: string; input, output: expr): stmt

Compiles the brainfuck code read from filename at compile time into Nim code that reads from the input variable and writes to the output variable, both of which have to be strings.

Example:

proc rot13(input: string): string =
  compileFile("examples/rot13.b", input, result)
echo rot13("Hello World!\n")
  Source
macro compileFile*(filename: string): stmt

Compiles the brainfuck code read from filename at compile time into Nim code that reads from stdin and writes to stdout.

Example:

proc mandelbrot = compileFile("examples/mandelbrot.b")
mandelbrot()
  Source