DEV Community

Cover image for I Wrote a BrainF*** Interpreter and REPL in TypeScript!
Andrew (he/him)
Andrew (he/him)

Posted on

I Wrote a BrainF*** Interpreter and REPL in TypeScript!

Photo by Robina Weermeijer on Unsplash

This was my first time ever coding in TypeScript, my first npm package, and more. Let me know if you have any comments or suggestions!

Try out the sample code on the GitHub repo!

GitHub logo awwsmm / BrainScript

A BrainF*** interpreter written in TypeScript


A BrainF*** (BF) interpreter and REPL, written in TypeScript.


Install from npm with

$ npm i brainscript

Or try it online at

var lib = require("brainscript")"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.")
Enter fullscreen mode Exit fullscreen mode


BrainScript provides a BF interpreter bf which can be used in interactive or batch mode, as well as a BF REPL brain.

bf can be used to batch process BF code, returning any resulting output as a string

const output: string = bf("++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.")

console.log(output) // Hello World!\n
Enter fullscreen mode Exit fullscreen mode

...but it also provides basic interactive capabilities for programs which require user input

// input.ts
Enter fullscreen mode Exit fullscreen mode
$ npx ts-node input.ts

    Please provide a single character for ',' input:
    : !

Enter fullscreen mode Exit fullscreen mode

brain is an interactive REPL which accepts single- or…

Top comments (5)

ben profile image
Ben Halpern


awwsmm profile image
Andrew (he/him)


not_jffrydsr profile image

Brilliant, a true expression of love for programming. 🌟
I think the first Web Framework for BF should appropriately be called "Mind R*pe".

bassochette profile image
Julien Prugne

I can't decide on 2 comments:

1 - Brilliant!
2 - what have you brought to this cursed land

Anyway I like it

n8chz profile image
Lorraine Lee

Capital! Wanna go for the gusto and write the compiler? You got this!