Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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); // => 1

x = 5;
print(++x); // => 6
print(x++); // => 6
print(x--); // => 7
print(--x); // => 5
```

## License

MIT