Also, probably one of the simplest...
That's why I decided to write an interpreter for it!
This is the product of about 3 days of work, give or take, but the sessions were long and I put a lot into it.
If you're a Haskeller reading this, please feel free to critique it (I'm sure it could be improved in many places)!
If you're not, please feel free to check it out anyway! I encourage everyone to play around with brainfuck a little bit because it's actually a lot of fun.
If you're not familiar with the language, a quick look through brainfuck's Wikipedia page should help you to understand what's going on in brainfuck (it's not too complex).
With the interpreter, you can write a file, say thisisbf.b, containing the classic "Hello, world!" brainfuck program directly from the wikipedia page:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+++++ +++++ initialize counter (cell #0) to 10 | |
[ use loop to set the next four cells to 70/100/30/10 | |
> +++++ ++ add 7 to cell #1 | |
> +++++ +++++ add 10 to cell #2 | |
> +++ add 3 to cell #3 | |
> + add 1 to cell #4 | |
<<<< - decrement counter (cell #0) | |
] | |
> ++ . print 'H' | |
> + . print 'e' | |
+++++ ++ . print 'l' | |
. print 'l' | |
+++ . print 'o' | |
> ++ . print ' ' | |
<< +++++ +++++ +++++ . print 'W' | |
> . print 'o' | |
+++ . print 'r' | |
----- - . print 'l' | |
----- --- . print 'd' | |
> + . print '!' | |
> . print '\n' |
and pass it to the interpreter:
on Windows:
$ build\windows\fhck.exe thisisbrainfuck.bor Linux (or presumably Mac OSX, though I haven't tried):
$ build/linux/fhck thisisbrainfuck.b...and it should print "Hello, world!" to your console!
Neat, right? (I think so!)
Download link/source is located here: fhck 1.0
Enjoy!
No comments:
Post a Comment