Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/neutrinozh/brainfuck
Brainfuck interpreter. Just for fun. Enjoy!
https://github.com/neutrinozh/brainfuck
brainfuck cpp interpreter
Last synced: 3 months ago
JSON representation
Brainfuck interpreter. Just for fun. Enjoy!
- Host: GitHub
- URL: https://github.com/neutrinozh/brainfuck
- Owner: NeutrinoZh
- License: mit
- Created: 2024-01-23T09:43:19.000Z (12 months ago)
- Default Branch: master
- Last Pushed: 2024-06-23T13:34:21.000Z (7 months ago)
- Last Synced: 2024-10-11T09:50:06.664Z (3 months ago)
- Topics: brainfuck, cpp, interpreter
- Language: C++
- Homepage:
- Size: 31.3 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Brainfuck interpreter
![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)
A simple Brainfuck interpreter written in C++. Brainfuck is a minimal and esoteric programming language with an extremely limited set of commands, making it an excellent subject for study and amusement.
Just for fun. Enjoy!
## Usage
1. Clone the repository:
```bash
git clone https://github.com/neutrinozh/brainfuck.git
```
2. Build the project:```bash
cd brainfuck
cmake -B ./build/
cmake --build ./build/
```
3. Run the interpreter with a Brainfuck program:```bash
cd ..
./build/brainfuck ./examples/hello-world.bf
```## Examples
Sample Brainfuck programs can be found in the `examples` directory. You can use them to test the interpreter.
## Brainfuck Syntax
Brainfuck consists of only 8 commands:
- `>`: Increment the pointer
- `<`: Decrement the pointer
- `+`: Increment the value at the current cell
- `-`: Decrement the value at the current cell
- `[`: Begin loop (jump forward to the corresponding `]` if the value at the current cell is 0)
- `]`: End loop (jump back to the corresponding `[` if the value at the current cell is nonzero)
- `,`: Input a character (ASCII)
- `.`: Output a character (ASCII)## Interpreter optimization
- Replacing multiple `>` or `<` with one instruction with a parameter of count increments or decrements pointer.
- Replacing multiple `+` or `-` with one instruction with a parameter of value for incrementing or decrementing the value of the current cell.
- Saving instruction numbers for `[` and `]` allows executing jumps between corresponding instructions without the need to iterate over all instructions, preventing delays in program execution.
- Optimizing `[+]` and `[-]` into one instruction `set_zero`## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE.txt) file for details.