Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dqn/bigbrain
High-level programming language that can be compiled to Brainfuck
https://github.com/dqn/bigbrain
brainfuck
Last synced: 14 days ago
JSON representation
High-level programming language that can be compiled to Brainfuck
- Host: GitHub
- URL: https://github.com/dqn/bigbrain
- Owner: dqn
- License: mit
- Created: 2020-08-23T07:53:22.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2022-02-05T08:31:19.000Z (almost 3 years ago)
- Last Synced: 2024-08-01T17:40:01.060Z (3 months ago)
- Topics: brainfuck
- Language: TypeScript
- Homepage:
- Size: 1.06 MB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Bigbrain
[![CI](https://github.com/dqn/bigbrain/workflows/CI/badge.svg)](https://github.com/dqn/bigbrain/actions)
High-level programming language that can be compiled to Brainfuck.
[Online Demo](https://bigbrain-dqn.vercel.app/)
## Usage
```bash
$ git clone [email protected]:dqn/bigbrain.git
$ cd bigbrain
$ yarn
$ yarn bigbrain ./example.bigbrain
```## Example
```
x = input();for (i = 1; i <= x; ++i) {
if (i % 3 == 0 && i % 5 == 0) {
putchar(102);
putchar(105);
putchar(122);
putchar(122);
putchar(98);
putchar(117);
putchar(122);
putchar(122);
// => fizzbuzz
} else if (i % 3 == 0) {
putchar(102);
putchar(105);
putchar(122);
putchar(122);
// => fizz
} else if (i % 5 == 0) {
putchar(98);
putchar(117);
putchar(122);
putchar(122);
// => buzz
} else {
print(i);
// => (raw number)
}
putchar(10);
// => \n
}
```Output:
```
>>,<<[-]>>[<<+>>>+<-]>[-]+<<[-]>>[<<+>+>-]<[-]<[>+>+<<-]>>[<<+>>-]<<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<[-<[>>+>+<<<-]>>>[<<<+>>>-]+<[<<->>>-<[-]]>[<<[-]>>-]<<]+<[>-<[-]]>[<<[>+>>+<<<-]>>>[<<<+>>>-]+++<<[>>->+<[>>+>+<<<-]>>>[<<<+>>>-]+<[>-<[-]]>[<<[<+>-]>>-]<<<<<-]>>[-]>[<<<->>>-]+<<<[>>>-<<<[-]]<[>+>>+<<<-]>>>[<<<+>>>-]+++++<<[>>->>+<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]+<[>-<[-]]>[<<[<<+>>-]>>-]<<<<<<-]>>[-]>>[<<<<->>>>-]+<<<<[>>>>-<<<<[-]]>>>[<<<+>>>[-]]>[<<<<+>>>>[-]]++<<<<[>>>>-<<<<-]+>>>>[<<<<->>>>[-]]<+<<<[>>>>>++++++++++[<<<++++++++++>>>-]<<<++.[-]>>>+++++++[<<<+++++++++++++++>>>-]<<<.[-]>>>+++++++++++[<<<+++++++++++>>>-]<<<+.[-]>>>+++++++++++[<<<+++++++++++>>>-]<<<+.[-]>>>+++++++[<<<++++++++++++++>>>-]<<<.[-]>>>+++++++++[<<<+++++++++++++>>>-]<<<.[-]>>>+++++++++++[<<<+++++++++++>>>-]<<<+.[-]>>>+++++++++++[<<<+++++++++++>>>-]<<<+.[-]>-<<<[-]]>>>[<<<<[>+>>+<<<-]>>>[<<<+>>>-]+++<<[>>->>>+<<<[>>>>+>+<<<<<-]>>>>>[<<<<<+>>>>>-]+<[>-<[-]]>[<<[<<<+>>>-]>>-]<<<<<<<-]>>[-]>>>[<<<<<->>>>>-]+<<<<<[>>>>>-<<<<<[-]]+>>>>>[>>++++++++++[<++++++++++>-]<++.[-]>+++++++[<+++++++++++++++>-]<.[-]>+++++++++++[<+++++++++++>-]<+.[-]>+++++++++++[<+++++++++++>-]<+.[-]<<<<<<->>>>>[-]]<<<<<[<[>>>>>>+>+<<<<<<<-]>>>>>>>[<<<<<<<+>>>>>>>-]+++++<[>->+<[>>+>+<<<-]>>>[<<<+>>>-]+<[>-<[-]]>[<<[<+>-]>>-]<<<<-]>[-]>[<<->>-]+<<[>>-<<[-]]+>>[>>+++++++[<++++++++++++++>-]<.[-]>+++++++++[<+++++++++++++>-]<.[-]>+++++++++++[<+++++++++++>-]<+.[-]>+++++++++++[<+++++++++++>-]<+.[-]<<<->>[-]]<<[<<<<<<[>>>>>>>>+>+<<<<<<<<<-]>>>>>>>>>[<<<<<<<<<+>>>>>>>>>-]++++++++++<[->->+<[>>+>+<<<-]>>>[<<<+>>>-]+<[>-<[-]]>[<<[<+>-]>>>+<-]<<<<]>>[>>>>>+<<<<<-]>>>[<<<<<+>>>>>-]<<<<[-]++++++++++<[->->+<[>>+>+<<<-]>>>[<<<+>>>-]+<[>-<[-]]>[<<[<+>-]>>>+<-]<<<<]>>[>>>>+<<<<-]>>>[++++++++++++++++++++++++++++++++++++++++++++++++.<+>>+<[-]]>[<<[>>-<<-]>>++++++++++++++++++++++++++++++++++++++++++++++++.[-]]>++++++++++++++++++++++++++++++++++++++++++++++++.[-]<<<<<<[-]<<<-]>[<<<<+>>>>-]<<<<<<-]>>[>>+<<-]>-]>[-]++++++++++.[-]<<<<<+[>>>>>+<+<<<<-]>>>>[<<<<+>>>>-]>[-]<<<[-]<<[>>>>>+<+<<<<-]>>>>[<<<<+>>>>-]<<<<<[>>>>>+<+<<<<-]>>>>[<<<<+>>>>-]>[->[<<+<<+>>>>-]<<<<[>>>>+<<<<-]+>>[>>-<<<<->>[-]]<<[>>>[-]<<<-]>>>]+>[<->[-]]<[<<+>>-]<<]
```## Syntax
### Variable
```
foo = 10;
bar = 20;
```### `input`
As in brainfuck: `,`.
```
x = input();
```### `putchar`
As in brainfuck: `.`.
```
putchar(65); // => A
```### `print`
Print value as decimal.
```
print(65); // => 65
```### Block
Block is an expression.
```
y = {
print(10);
putchar(65);
20 + 15 + 7;
};print(y); // => 42
```### `if`
`if` is an expression.
```
x = 20;if (x > 10) {
print(65);
}if (x > 10) {
print(65);
} else {
print(66);
}if (x > 10) {
print(65);
} else if (x < 10) {
print(66);
} else {
print(67);
}y = if (x > 10) {
1;
} else {
2;
};print(y); // => 1
```### `for`
```
for (i = 0; i < 10; i++) {
print(i % 3);
}
```### Operators
```
print(1 + 2); // => 3
print(4 - 1); // => 3
print(1 + +1); // => 2
print(1 + -1); // => 0
print(2 * 4); // => 8
print(13 / 3); // => 4
print(13 % 3); // => 1
print(2 ** 3); // => 8
print(2 * (3 + 4)); // => 14
print(!0); // => 1
print(1 == 2); // => 0
print(1 != 2); // => 1
print(1 < 2); // => 1
print(1 > 2); // => 0
print(1 <= 1); // => 1
print(1 >= 1); // => 1
print(1 && 0); // => 0
print(1 || 0); // => 1x = 5;
print(++x); // => 6
print(x++); // => 6
print(x--); // => 7
print(--x); // => 5
```## License
MIT