Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
# .gitignore for brainfuck.

# ignore the .cproject and .project file generated by Eclipse.
Expand Down
6 changes: 2 additions & 4 deletions CMakeLists.txt
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})

## Compile-time options ##
option(ENABLE_CLI "Enable the command line interface" ON)
option(ENABLE_EDITLINE "Enable GNU readline functionality provided by the editline library" ON)
option(ENABLE_EXTENSION_DEBUG "Enable the debug extension for brainfuck")
option(INSTALL_EXAMPLES "Install the examples")

## Target ##
set(BRAINFUCK_H include/brainfuck.h)
set(BRAINFUCK_H include/brainfuck.h
src/brainfuck.c)
set(BRAINFUCK_C_FLAGS
$<$<OR:$<C_COMPILER_ID:Clang>,$<C_COMPILER_ID:AppleClang>,$<C_COMPILER_ID:GNU>>:
-Wall -Wextra>
Expand Down Expand Up @@ -49,9 +49,7 @@ if(ENABLE_CLI)
target_compile_options(brainfuck-cli PRIVATE "${BRAINFUCK_C_FLAGS}")

if(ENABLE_EDITLINE)
find_package(editline REQUIRED)
target_compile_definitions(brainfuck-cli PRIVATE BRAINFUCK_EDITLINE_LIB)
target_link_libraries(brainfuck-cli PRIVATE editline)
endif()
endif()

Expand Down
Empty file modified LICENSE.txt
100644 → 100755
Empty file.
82 changes: 59 additions & 23 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
brainfuck
[![Build Status](https://github.com/fabianishere/brainfuck/workflows/Build/badge.svg)](https://github.com/fabianishere/brainfuck/actions?query=workflow%3ABuild)
===========
Brainfuck interpreter written in C.

## Update
1. Added a double slash '//' comment function.
2. Added a shebang '#!' line function.
3. Added a function that allows letters to replace symbols
- default replacing mothed
-
| origin | optional |
|--------|-----------|
| '+' | 'o' , 'O' |
| '-' | 'i' , 'I' |
| '<' | 'a' , 'A' |
| '>' | 'e' , 'E' |
| '.' | '.' , '.' |
| ',' | ',' , ',' |
| '[' | 'u' , 'U' |
| ']' | 'y' , 'Y' |
| '#' | '?' , '!' |

- you can change them in `src/brainfuck.c:other_char_table`.\
- I love these vowels, reading them is like listening to a baby trying to speak but only babbling.
4. Added two tools transLetter.py and transLetters.sh to help users automatically convert letters to others.
5. Add a tools folder to store transLetter.py and transLetters.sh.\
You can compare the instruction parameters in transLetters.sh to customize the conversion file.
6. Removed the `editline` library dependency,\
because it was interfering with the NVIDIA 4060 GPU driver on my Ubuntu PC.
## Usage
brainfuck [-veh] file...
-e --eval run code directly
Expand Down Expand Up @@ -43,29 +66,42 @@ $ git clone https://github.com/fabianishere/brainfuck.git
or simply [grab](https://github.com/fabianishere/brainfuck/archive/master.zip) a copy of the source code as a Zip file.

## Building
Create the build directory.
```sh
$ mkdir build
$ cd build
```
Brainfuck requires CMake and a C compiler (e.g. Clang or GCC) in order to run. It also depends on [libedit](http://thrysoee.dk/editline/), which is available in the main repositories of most Linux distributions (e.g. as [libedit-dev](https://packages.debian.org/stretch/libedit-dev) on Debian/Ubuntu) and comes with the macOS XCode command line tools.
1. Create the build directory.
```sh
$ mkdir build
$ cd build
```
2. Brainfuck requires CMake and a C compiler (e.g. Clang or GCC) in order to run. It also depends on [libedit](http://thrysoee.dk/editline/), which is available in the main repositories of most Linux distributions (e.g. as [libedit-dev](https://packages.debian.org/stretch/libedit-dev) on Debian/Ubuntu) and comes with the macOS XCode command line tools.
Then, simply create the Makefiles:
```sh
$ cmake ..
```
and finally, build it using the building system you chose (e.g. Make):
```sh
$ make
```
```sh
$ cmake ..
```
3. and finally, build it using the building system you chose (e.g. Make):
```sh
$ make
```

After the build has been finished, you may install the binaries to your local system (see [CMAKE\_INSTALL\_PREFIX](https://cmake.org/cmake/help/v3.0/variable/CMAKE_INSTALL_PREFIX.html) for information about the install prefix):
```sh
$ make install
```
Alternatively, you may run the interpreter directly without installation, for instance:
```sh
$ ./brainfuck ../examples/hello.bf
```
4. After the build has been finished, you may install the binaries to your local system (see [CMAKE\_INSTALL\_PREFIX](https://cmake.org/cmake/help/v3.0/variable/CMAKE_INSTALL_PREFIX.html) for information about the install prefix):
```sh
$ make install
```
5. Alternatively, you may run the interpreter directly without installation, for instance:
```sh
$ ./brainfuck ../examples/hello.bf
```
6. Because some new features are added, you can add `#!brainfuck` and change you symbols
like the `hello.bf`:
```brainfuck
#!/usr/bin/env brainfuck
// hello <O-O>
ooooooooueooooueooeoooeoooeoaaaaiyeoeoeieeouayaiyee.eiii.ooooooo..ooo.ee.ai.a.oo
o.iiiiii.iiiiiiii.eeo.eoo.
```
Then run the file directly in the terminal\
```sh
sudo chmod 755 hello.bf
hello.bf
```

## License
The code is released under the Apache License version 2.0. See [LICENSE.txt](/LICENSE.txt).
Expand Down
39 changes: 0 additions & 39 deletions cmake/Findeditline.cmake

This file was deleted.

1 change: 1 addition & 0 deletions examples/196-commented.bf
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/home/mango/CLionProjects/brainfuck/build/brainfuck
[
The 196-algorithm implemented in brainfuck by Mats Linander.

Expand Down
Empty file modified examples/196.bf
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion examples/2d_table.bf
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

#!/home/mango/CLionProjects/brainfuck/build/brainfuck
2D Table reading routine for BrainFuck
Made By: NYYRIKKI 2001

Expand Down
1 change: 1 addition & 0 deletions examples/666.bf
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

>+++++++++[<++++++>-]<...
>++++++++++.

1 change: 1 addition & 0 deletions examples/asciiart/asciiart.bf
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/local/bin/brainfuck
>>+++[<+++++[<+++++++>-]>-]<<.>>>+++++[<+++++++++++[<++>-]>-]<<.>++++>
>++++[<++++[<+++++++>-]>-]<<.>++>+++++[<++++++>-]<.>+>>++++[<+++++++++
[<+++>-]>-]<<.>+>>++++[<++++[<++++++>-]>-]<<.<<<<<.>.>>>>>+>++++++++++
Expand Down
3 changes: 1 addition & 2 deletions examples/asciiart/chess.bf
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


#!brainfuck
+++++++++++++++[>++>+++>+++>++++++>++>+++++++>++++>+<<<<<<<<-]>>--.>....
...<.>.......<.>.......<.>.......<.>.......<.>.......<.>.......<.>......
.<.>>>>>>-----.<<+++++++++++++++++++.<++.<+.++++.>>.<<.--.>.>.>--..<<<++
Expand Down
Empty file modified examples/asciiart/text.bf
100644 → 100755
Empty file.
5 changes: 3 additions & 2 deletions examples/asciiart/triangle.bf
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/home/mango/CLionProjects/brainfuck/build/brainfuck
[ This program prints Sierpinski triangle on 80-column display. ]
>
+ +
Expand All @@ -14,7 +15,7 @@
> > + <
< < < < < < < <
< [ - [ - > + <
] > [ - < + > > > . < < ] > > >
] > [ - < + > > > . < < ] > > > // dt crraa
[ [
- > + +
+ + + +
Expand All @@ -30,4 +31,4 @@
[ - < - > ] < <
< ] < < < < ] + + + + + + + + +
+ . + + + . [ - ] < ] + + + + +
* * * * * M a d e * B y : * N Y Y R I K K I * 2 0 0 2 * * * * *
* * * * * * * * * * * * * * * * * * * * * * * 2 0 0 2 * * * * *
1 change: 1 addition & 0 deletions examples/asciiart/xmastree.bf
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/home/mango/CLionProjects/brainfuck/build/brainfuck
[xmastree.b -- print Christmas tree
(c) 2016 Daniel B. Cristofani
http://brainfuck.org/]
Expand Down
Empty file modified examples/atoi.bf
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions examples/bench/bench-1.bf
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/usr/local/bin/brainfuck
++++++++[->-[->-[->-[-]<]<]<]
>++++++++[<++++++++++>-]<[>+>+<<-]>-.>-----.>
Empty file modified examples/bench/bench-2.bf
100644 → 100755
Empty file.
Empty file modified examples/bench/easy-opt.bf
100644 → 100755
Empty file.
Empty file modified examples/bench/endtest.bf
100644 → 100755
Empty file.
Empty file modified examples/bench/long.bf
100644 → 100755
Empty file.
Empty file modified examples/bench/prttab.bf
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions examples/bench/skiploop.bf
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/home/mango/CLionProjects/brainfuck/build/brainfuck
[ This program tests how well the interpreter reacts to large
runs of '>' and '<'.
This is the source RLE-encoded.
Expand Down
Empty file modified examples/bench/tests.bf
100644 → 100755
Empty file.
Empty file modified examples/bottles-1.bf
100644 → 100755
Empty file.
Empty file modified examples/bottles-2.bf
100644 → 100755
Empty file.
Empty file modified examples/bottles-3.bf
100644 → 100755
Empty file.
Empty file modified examples/busy-beaver-overflow.bf
100644 → 100755
Empty file.
Empty file modified examples/busy-beaver.bf
100644 → 100755
Empty file.
Empty file modified examples/cat-1.bf
100644 → 100755
Empty file.
Empty file modified examples/cat-2.bf
100644 → 100755
Empty file.
Empty file modified examples/cat-3.bf
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion examples/cell-size-1.bf
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

#!/home/mango/CLionProjects/brainfuck/build/brainfuck

// Calculate (16*16*16*16)^128 AKA 2^2048
++[>++++++++<-]>[>++++++++<-]>[<<
Expand Down
Empty file modified examples/cell-size-2.bf
100644 → 100755
Empty file.
Empty file modified examples/cell-size-3.bf
100644 → 100755
Empty file.
Empty file modified examples/cell-size-4.bf
100644 → 100755
Empty file.
Empty file modified examples/cell-size-5.bf
100644 → 100755
Empty file.
Empty file modified examples/char.bf
100644 → 100755
Empty file.
Empty file modified examples/counter.bf
100644 → 100755
Empty file.
Empty file modified examples/css.bf
100644 → 100755
Empty file.
Empty file modified examples/decss.bf
100644 → 100755
Empty file.
Empty file modified examples/dvorak.bf
100644 → 100755
Empty file.
Empty file modified examples/echo.bf
100644 → 100755
Empty file.
Empty file modified examples/gameoflife.bf
100644 → 100755
Empty file.
Empty file modified examples/hanoi-opt.bf
100644 → 100755
Empty file.
Empty file modified examples/hanoi.bf
100644 → 100755
Empty file.
Empty file modified examples/head.bf
100644 → 100755
Empty file.
Empty file modified examples/hello-short.bf
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions examples/hello.bf
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/usr/bin/env brainfuck
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.++
+.------.--------.>>+.>++.
Empty file modified examples/htmlconv.bf
100644 → 100755
Empty file.
Empty file modified examples/jabh.bf
100644 → 100755
Empty file.
Empty file modified examples/ks.bf
100644 → 100755
Empty file.
Empty file modified examples/lost-kingdom.bf
100644 → 100755
Empty file.
Empty file modified examples/mac2unix.bf
100644 → 100755
Empty file.
Empty file modified examples/numwarp.bf
100644 → 100755
Empty file.
Empty file modified examples/oobrain.bf
100644 → 100755
Empty file.
Empty file modified examples/order.bf
100644 → 100755
Empty file.
Empty file modified examples/packbits.bf
100644 → 100755
Empty file.
Empty file modified examples/password-vault.bf
100644 → 100755
Empty file.
Empty file modified examples/reverse.bf
100644 → 100755
Empty file.
Empty file modified examples/rot13.bf
100644 → 100755
Empty file.
Empty file modified examples/rpn.bf
100644 → 100755
Empty file.
Empty file modified examples/short.bf
100644 → 100755
Empty file.
Empty file modified examples/si.bf
100644 → 100755
Empty file.
Empty file modified examples/sisihi.bf
100644 → 100755
Empty file.
Empty file modified examples/utm.bf
100644 → 100755
Empty file.
Empty file modified examples/wc.bf
100644 → 100755
Empty file.
6 changes: 6 additions & 0 deletions include/brainfuck.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@
#define BRAINFUCK_TOKEN_NEXT '>'
#define BRAINFUCK_TOKEN_OUTPUT '.'
#define BRAINFUCK_TOKEN_INPUT ','

#define BRAINFUCK_TOKEN_LOOP_START '['
#define BRAINFUCK_TOKEN_LOOP_END ']'

// extern const char char_table[][3];
// extern const int char_table_size;

#define BRAINFUCK_EXTENSION_DEBUG
#ifdef BRAINFUCK_EXTENSION_DEBUG
# define BRAINFUCK_TOKEN_BREAK '#'
#else
Expand Down
20 changes: 10 additions & 10 deletions man/brainfuck.1
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ A brainfuck interpreter written in C.
The brainfuck syntax is described below:
.Pp
.Bl -tag -width -indent
.It Sy >
Increment the data pointer (to point to the next cell to the right).
.It Sy <
.It Sy < , a , A
Decrement the data pointer (to point to the next cell to the left).
.It Sy +
Increment (increase by one) the byte at the data pointer.
.It Sy -
.It Sy > , e , E
Increment the data pointer (to point to the next cell to the right).
.It Sy - , i , I
Decrement (decrease by one) the byte at the data pointer.
.It Sy \&.
Output the byte at the data pointer as an ASCII encoded character.
.It Sy + , o , O
Increment (increase by one) the byte at the data pointer.
.It Sy \&,
Accept one byte of input, storing its value in the byte at the data pointer.
.It Sy \&[
.It Sy \&.
Output the byte at the data pointer as an ASCII encoded character.
.It Sy \&[ , y , Y
If the byte at the data pointer is zero, then instead of moving the instruction pointer forward to the next command, jump it forward to the command after the matching
.Sy \&]
token.
.It Sy \&]
.It Sy \&] , u , U
If the byte at the data pointer is nonzero, then instead of moving the instruction pointer forward to the next command, jump it back to the command after the matching
.Sy \&[
token.
Expand Down
Loading