https://github.com/datamine/rubeef
Brainfuck interpreter written in Ruby
https://github.com/datamine/rubeef
Last synced: about 2 months ago
JSON representation
Brainfuck interpreter written in Ruby
- Host: GitHub
- URL: https://github.com/datamine/rubeef
- Owner: Datamine
- Created: 2016-09-28T05:54:12.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-10-05T07:16:42.000Z (over 9 years ago)
- Last Synced: 2025-01-19T06:46:25.654Z (about 1 year ago)
- Language: Python
- Size: 4.01 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Brainfuck interpreter in Ruby
Run with `ruby brainfuck-interpreter.rb `
Some tests included, use `./runtest.sh ` to run the
ruby interpretation against one of the reference interpreters.
## Interesting things I learned:
If you process input using `require 'io/console'` and `STDIN.getch`, the enter/return
key (at least on OS X) is parsed as ASCII 13. If you use `STDIN.read(1)`, it's parsed
as ASCII 10. Same in python for `sys.stdin.read(1)`. This threw me off while trying
to handle input properly. Most bf scripts seem to be written to accommodate only
ASCII 10 as a newline indicator, not ASCII 13 as well (and feeding in one when the
script expects the other can result in all kinds of strange bugs).
## Caveats:
The canonical BF interpreter is really only meant to support 8-bit cells.
I did not put a size restriction on my cells, though it would be easy to do so.
## Credits:
- Python reference versions from https://github.com/pablojorge/brainfuck
- Test scripts from that repository as well, except for the following:
- `squares.bf` by [Daniel B Cristofani](http://www.hevanet.com/cristofd/brainfuck/)
- `a.bf` and `multiply.bf` from [LearnXinYminutes](https://learnxinyminutes.com/docs/bf/). Note that `multiply.bf` doesn't seem to work at the command line. It works in this [bf visualizer](https://fatiherikli.github.io/brainfuck-visualizer/#), so I'm not sure what's up with that.