BF-it

所属分类:C/C++基础
开发工具:Python
文件大小:1313KB
下载次数:0
上传日期:2022-12-28 09:43:30
上 传 者sh-1993
说明:  Brainfuck编译器的类C语言,用Python编写
(A C-like language to Brainfuck compiler, written in Python)

文件列表:
BF-it.py (1852, 2022-09-12)
Compiler (0, 2022-09-12)
Compiler\Compiler.py (8492, 2022-09-12)
Compiler\Exceptions.py (86, 2022-09-12)
Compiler\FunctionCompiler.py (51557, 2022-09-12)
Compiler\Functions.py (1223, 2022-09-12)
Compiler\General.py (45010, 2022-09-12)
Compiler\Globals.py (2586, 2022-09-12)
Compiler\Lexical_analyzer.py (7041, 2022-09-12)
Compiler\LibraryFunctionCompiler.py (3987, 2022-09-12)
Compiler\Minify.py (301, 2022-09-12)
Compiler\Node.py (18213, 2022-09-12)
Compiler\Optimizer.py (3816, 2022-09-12)
Compiler\Parser.py (4966, 2022-09-12)
Compiler\Token.py (1648, 2022-09-12)
Compiler\__init__.py (0, 2022-09-12)
Interpreter.py (2474, 2022-09-12)
LICENSE.md (1065, 2022-09-12)
examples (0, 2022-09-12)
examples\arrays.bf (18175, 2022-09-12)
examples\arrays.code (3266, 2022-09-12)
examples\bitwise.bf (17618, 2022-09-12)
examples\bitwise.code (1676, 2022-09-12)
examples\block_comments.bf (550, 2022-09-12)
examples\block_comments.code (324, 2022-09-12)
examples\boolean_operations.bf (5012, 2022-09-12)
examples\boolean_operations.code (726, 2022-09-12)
examples\calc.bf (6310, 2022-09-12)
examples\calc.code (1134, 2022-09-12)
examples\chars.bf (3235, 2022-09-12)
examples\chars.code (903, 2022-09-12)
examples\do_while_loops.bf (2144, 2022-09-12)
examples\do_while_loops.code (880, 2022-09-12)
examples\expressions_evaluation.bf (65327, 2022-09-12)
examples\expressions_evaluation.code (6016, 2022-09-12)
examples\expressions_evaluation_advanced.bf (6442, 2022-09-12)
... ...

BF-it logo # **BF-it** A compiler from a C-like language to Brain*** Always heard that Brain*** is Turing complete but still had doubts about its computational power? Those days are over ## What is this? BF-it is a Compiler of a C-like language to Brain***, written in Python You give it C-like code, and it gives you Brain*** code with the same functionality :) ## Why did you create it? There are several reasons why I chose to create this 1. I always heard that Brain*** is Turing complete, and therefore as strong as any other language * I wanted to put that to the test, and find a concrete proof that it is true 2. I find it beautiful how a seemingly bunch of nonsense characters can have a logical meaning / functionality * I wanted to take it to the extreme 3. I wanted to practice my developing skills 4. It seemed to be like a real challenge (and it was!) 5. But mostly, and most importantly, I did it for teh lulz ## What can I use it for? Create a Brain*** code of your choice, send it to your friends, and tell them to run it (on some online interpreter, for example) When they receive a bunch of nonsense which does something meaningful, they will (maybe) be amazed ## How do I use it? 1. Write a C-like code (example programs included) into a file 2. Open your favorite command line interface 3. Run `BF-it.py ` * This will compile your file and create a .bf file with Brain*** code * (optional parameters: `-o` for output file, and `-r` for running the compiled file) 4. Run `Interpreter.py `, this will execute the Brain*** code Example: ``` $ cat helloworld.code int main() { print("Hello World!\n"); } $ ./BF-it.py helloworld.code Compiling file 'helloworld.code'... Compiled successfully to 'helloworld.bf' $ cat helloworld.bf >[-]>[-]<>++++++++[-<+++++++++>]<.>++++[-<+++++++>] <+.+++++++..+++.>++++++[-<------------->]<-.>+++++[ -<+++++++++++>]<.>++++[-<++++++>]<.+++.------.----- ---.>++++++[-<----------->]<-.>+++[-<------->]<--.< $ ./Interpreter.py helloworld.bf Hello World! ``` For a more interesting example, check out Tic-Tac-Toe! Tic-Tac-Toe
1. Take a look at tic_tac_toe.code in the 'examples/games' directory 2. Run ```./BF-it.py examples/games/tic_tac_toe.code -r``` 3. Play around 4. If you're brave, take a look at the generated Brain*** code 5. If you're very brave, try to understand it (I can't) ## How do I write code? Please refer to the 'examples' directory. It contains examples and explanations for syntax, operations, flow, and more ## I would like to add a feature / fix a bug If you would like to add a feature yourself, perform a pull request and add your changes. I will review them If you found a bug, or have an idea for a feature, open an issue ## References I used: * https://esolangs.org/wiki/brain***_algorithms for basic Brain*** algorithms * https://www.iamcal.com/misc/bf_debug/ for debugging Brain*** code * https://fatiherikli.github.io/brain***-visualizer/ for debugging Brain*** code * https://godbolt.org/ for comparing my C-like compiler to other C compilers' implementations * https://www.lysator.liu.se/c/ANSI-C-grammar-y.html for creating a grammar * https://introcs.cs.princeton.edu/java/11precedence/ for operator precedence * https://logomakr.com/ for creating a logo * https://www.youtube.com/ for setting the mood

近期下载者

相关文件


收藏者