/contrib/brainfuck/README.md

https://gitlab.com/oytunistrator/nit · Markdown · 34 lines · 24 code · 10 blank · 0 comment · 0 complexity · d3d374e1837c7bc30537b8ad82bda8e0 MD5 · raw file

  1. # Brainfuck
  2. Brainfuck is as its name implies a simple Brainfuck interpreter written in Nit.
  3. It has almost as much purposes as the language itself, except it provides a good example for Nit programs that work while being concise.
  4. [Specification](http://www.muppetlabs.com/~breadbox/bf/)
  5. The language is designed to need only a few things :
  6. * One instruction pointer to the current instruction
  7. * One array of Bytes for all manipulations of data
  8. * One data pointer to select where to write/read data
  9. Brainfuck a small instruction set, only eight instructions :
  10. * `>`: Increments the data pointer
  11. * `<`: Decrements the data pointer
  12. * `+`: Increments the byte in the current cell
  13. * `-`: Decrements the byte in the current cell
  14. * `[`: If the current cell's value is 0, jumps to the matching `]`
  15. * `]`: If the current cell's value is non-zero, jumps to the matching `[`
  16. * `.`: Writes the current cell's value to stdout
  17. * `,`: Reads a char from stdin and stores it in the current cell
  18. ## How to use
  19. First, compile the interpreter with the Nit compiler/interpreter, and launch the program on a brainfuck source file for interpretation.
  20. Example:
  21. ~~~
  22. nitc ./brainfuck.nit
  23. ./brainfuck ./examples/hello.bf
  24. ~~~