{"id":18388389,"url":"https://github.com/gabyfle/brainfuck","last_synced_at":"2025-09-11T14:03:49.824Z","repository":{"id":198034189,"uuid":"193946883","full_name":"gabyfle/Brainfuck","owner":"gabyfle","description":"A Brainfuck compiler to Assembly x86, fully written in OCaml","archived":false,"fork":false,"pushed_at":"2020-05-16T17:59:32.000Z","size":197,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-06T21:17:36.164Z","etag":null,"topics":["brainfuck","compiler","gabyfle","ocaml","parser","tokenizer"],"latest_commit_sha":null,"homepage":"","language":"OCaml","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gabyfle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-06-26T17:08:51.000Z","updated_at":"2024-10-20T20:39:10.000Z","dependencies_parsed_at":"2023-10-04T05:35:47.058Z","dependency_job_id":null,"html_url":"https://github.com/gabyfle/Brainfuck","commit_stats":null,"previous_names":["gabyfle/brainfuck"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabyfle%2FBrainfuck","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabyfle%2FBrainfuck/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabyfle%2FBrainfuck/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabyfle%2FBrainfuck/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gabyfle","download_url":"https://codeload.github.com/gabyfle/Brainfuck/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248515143,"owners_count":21117117,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["brainfuck","compiler","gabyfle","ocaml","parser","tokenizer"],"created_at":"2024-11-06T01:34:05.432Z","updated_at":"2025-04-12T04:24:44.968Z","avatar_url":"https://github.com/gabyfle.png","language":"OCaml","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Brainfuck\nA Brainfuck compiler, written in **OCaml**\n\n## Table of contents\n- [Brainfuck](#brainfuck)\n  * [What is \"Brainfuck\" ?](#what-is-brainfuck-)\n  * [What is this ?](#what-is-this-)\n  * [How to use it ?](#how-to-use-it-)\n  * [Performances](#performances)\n    + [Using `benchmarking.py`](#using-benchmarkingpy)\n  * [Compiling your Brainfuck code](#compiling-your-brainfuck-code)\n  * [Compiling your assembly code](#compiling-your-assembly-code)\n  * [Parser feature](#parser-feature)\n  * [Optimization](#optimization)\n  * [Credits](#credits)\n  * [License](#license)\n\n## What is \"Brainfuck\" ?\n\u003cp style=\"text-align: justify;\"\u003eBrainfuck is an esoteric programming language developed by Urban Müller in 1993. The first particularity of this language is that it contains only 8 instructions that allow, in theory, to create any program (it is said to be Turing-complete). For more information, visit the Wikipedia page of the Brainfuck language: \u003ca href=\"https://en.wikipedia.org/wiki/Brainfuck\"\u003eBrainfuck - Wikipedia\u003c/a\u003e\u003c/p\u003e\n\n## What is this ?\n\u003cp style=\"text-align: justify;\"\u003eThis repository contains a compiler written entirely in OCaml. The ultimate goal would be to be able to integrate the compiler into other projects so that he can use Brainfuck as he sees fit.\u003c/p\u003e\n\n## How to use it ?\n\n(this hasn't been implemented yet)\n\nBrainfuck is meant to be used in command line.\n\n## Performances\n\nAll these records have been made on the same machine.\n\n* CPU: Intel® Core™ i5-3340M CPU @ 2.70GHz × 4 \n* Memory: 11,6 GiB\n\n### Using `benchmarking.py`\n\nThis script isn't supposed to be used outside of this repository but if you want to use it, you can still, by launching this command:\n\n```\npython3 benchmarking.py -program \u003crelative_path\u003e -amount \u003camount_of_time\u003e\n```\n\nWhere `\u003crelative_path\u003e` is the relative path to the program you want to take the bench from and `\u003camount_of_time\u003e` is the amount of time the script should reproduce the benchmarks (the bigger it is, the more accurate your result will be).\n\n### Hello World!\n* Code: [Hello World!](https://en.wikipedia.org/wiki/Brainfuck#Hello_World!)\n* Compile time: 0.001737 seconds\n* **Execution:**\n  * Time (seconds): 0.00086\n\n### Mandelbrot set\n* Code: [Mandelbrot](https://github.com/erikdubbelboer/brainfuck-jit/blob/master/mandelbrot.bf)\n* Compile time: 0.003110 seconds\n* **Execution:**\n  * Time (seconds): 1.44159\n\n### Pi\n* Code: [Pi](http://esoteric.sange.fi/brainfuck/bf-source/prog/yapi.b)\n\n  **Notice:** Instead of computing only *15* decimals, we're computing *140*.\n\n* Compile time: 0.001349 seconds\n* **Execution:**\n  * Time (seconds): 0.007801\n\n## Compiling your Brainfuck code\n\n### Brainfuck parameters\n* **Input:** the first parameter that you have to pass to Brainfuck is the path to the file that contains the Brainfuck code to be compiled.\n* **Optional**:\n  * **-o `\u003cfilename\u003e`:** this parameter is optional. If not set, the default output name of Brainfuck will be `\u003cinput\u003e.asm` where `\u003cinput\u003e` is the filename you gived in the first parameter.\n  * **-opt:** If set, activate optimizations\n\n### Command line\n\nTo compile a brainfuck code, simply launch this command in your Terminal:\n\n```\nbrainfuck \u003cbf_to_compile\u003e\n```\n\nWhere `\u003cbf_to_compile\u003e` is the path to the Brainfuck code you want to compile.\nTo activate optimizations, add the `-opt` optional parameter:\n\n```\nbrainfuck \u003cbf_to_compile\u003e -opt\n```\n\nFinally, if you want to set a specific name to your compiled code file's name, use the `-o` optional parameter:\n\n```\nbrainfuck \u003cbf_to_compile\u003e -o \u003cfile_name\u003e -opt\n```\n\n## Compiling your assembly code\n\n### Requirements\n* [Netwide Assembler](https://www.nasm.us/)\n* A device running a x86-32 or x86-64 architecture\n* A POSIX operating system\n\n### Command line\nTo compile the assembly code that Brainfuck produces, type the following in your Terminal :\n\n```\nnasm -felf32 \u003cyour_file\u003e.asm\nld -melf_i386 \u003cyour_file\u003e.o -o \u003cprogram_name\u003e\n```\n\nThen, to execute it, simply run:\n\n```\n./\u003cprogram_name\u003e\n```\n\n## Parser feature\nThis compiler includes a very simple parser that will detect broken *Brainfuck* code. Here is some examples of how does it tell you that you made a mistake :\n\n* **Example 1 :** you forgot to close a loop\n\n*Input :*\n```brainfuck\n++++++++++[\u003e+++++++\n```\n*Output :*\n```\nParser.Syntax_Error(\"No matching ']' found for '[' at char 11 in loop 1\")\n```\n\n* **Example 2 :** you added a `]` that does not match any loop\n\n*Input :*\n```brainfuck\n++++++++++\u003e+++++++]\n```\n*Output :*\n```\nParser.Syntax_Error(\"No matching '[' found for ']' at char 19\")\n```\n\n## Optimization\n\nThis compiler tries to optimise the Brainfuck code that he compile.\n\n### Optimize redundant instruction (done)\n\nVery often in Brainfuck, we see sets of instructions that looks like :\n```brainfuck\n+++++++++\n\nor\n\n---------\n```\nInstead of translating it naively into 9 `add reg, 1` (respectively `sub`) assembly instructions, we can translate it into a single instruction that directly adds 9 to the cell. This type of optimization works exactly the same for `\u003c` and `\u003e`.\n\n### Optimize loops (todo)\n### Optimize dead code (todo)\n\n## Credits\n* Table of contents: \u003csmall\u003e\u003ci\u003e\u003ca href='http://ecotrust-canada.github.io/markdown-toc/'\u003eTable of contents generated with markdown-toc\u003c/a\u003e\u003c/i\u003e\u003c/small\u003e\n\n## License\nAll code in this repository is under the Apache 2.0 license, available at the following address: https://www.apache.org/licenses/LICENSE-2.0\n\n_**\u0026copy; Gabriel Santamaria, 2019**_\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgabyfle%2Fbrainfuck","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgabyfle%2Fbrainfuck","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgabyfle%2Fbrainfuck/lists"}