{"id":18304817,"url":"https://github.com/zenoamaro/braincuck","last_synced_at":"2026-04-16T00:32:45.335Z","repository":{"id":66209921,"uuid":"127543622","full_name":"zenoamaro/braincuck","owner":"zenoamaro","description":"Transpiles Brainfuck code into C code","archived":false,"fork":false,"pushed_at":"2018-03-31T15:17:44.000Z","size":6,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-25T16:37:43.299Z","etag":null,"topics":["brainfuck","c","compiler","transpiler"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zenoamaro.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-31T15:14:46.000Z","updated_at":"2023-03-08T20:48:23.000Z","dependencies_parsed_at":"2023-02-23T23:15:22.280Z","dependency_job_id":null,"html_url":"https://github.com/zenoamaro/braincuck","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zenoamaro/braincuck","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zenoamaro%2Fbraincuck","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zenoamaro%2Fbraincuck/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zenoamaro%2Fbraincuck/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zenoamaro%2Fbraincuck/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zenoamaro","download_url":"https://codeload.github.com/zenoamaro/braincuck/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zenoamaro%2Fbraincuck/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31866345,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-15T15:24:51.572Z","status":"ssl_error","status_checked_at":"2026-04-15T15:24:39.138Z","response_time":63,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","c","compiler","transpiler"],"created_at":"2024-11-05T15:30:43.721Z","updated_at":"2026-04-16T00:32:45.305Z","avatar_url":"https://github.com/zenoamaro.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Braincuck\n=========\nTranspiles Brainfuck code into C code.\n\n~~~\n$ npm install zenoamaro/braincuck --global\n$ braincuck 99-bottles.bf 99-bottles.c\n$ gcc -O3 99-bottles.c -o 99-bottles\n$ ./99-bottles\n~~~\n\n[Brainfuck]: https://en.wikipedia.org/wiki/Brainfuck\n[C]: https://en.wikipedia.org/wiki/C_(programming_language)\n[GCC]: https://gcc.gnu.org\n[Clang]: https://clang.llvm.org\n[LLVM]: http://llvm.org\n\n\nTranspilation\n-------------\n[Brainfuck] code translates pretty closely to [C] code, so much that we can transpile it using a simple mapping table:\n\n| Instruction       | Brainfuck code      | C code              |\n|-------------------|---------------------|---------------------|\n| Increment pointer | `\u003e` (one or more)   | `ptr += x;`         |\n| Decrement pointer | `\u003c` (one or more)   | `ptr -= x;`         |\n| Increment cell    | `+` (one or more)   | `*ptr += x;`        |\n| Decrement cell    | `-` (one or more)   | `*ptr -= x;`        |\n| Output cell       | `.`                 | `putchar(*ptr);`    |\n| Input cell        | `,`                 | `*ptr = getchar();` |\n| Jump if zero      | `[`                 | `while (*ptr) {`    |\n| Loop              | `]`                 | `}`                 |\n| Comment           | Any other character | No output           |\n\nHere is a simple Brainfuck program:\n\n~~~brainfuck\n# Brainfuck Hello World\n# https://gist.github.com/niklaskorz/4523505\n\n+++++ +++++             initialize counter (cell #0) to 10\n[                       use loop to initialize the next cells\n    \u003e +++++ ++              add  7 to cell #1 to be  70\n    \u003e +++++ +++++           add 10 to cell #2 to be 100\n    \u003e +++                   add  3 to cell #3 to be  30\n    \u003e +                     add  1 to cell #4 to be  10\n    \u003c\u003c\u003c\u003c -                  decrement counter (cell #0)\n]\n\u003e ++ .                  print 'H'\n\u003e + .                   print 'e'\n+++++ ++ .              print 'l'\n.                       print 'l'\n+++ .                   print 'o'\n\u003e ++ .                  print ' '\n\u003c\u003c +++++ +++++ +++++ .  print 'W'\n\u003e .                     print 'o'\n+++ .                   print 'r'\n----- - .               print 'l'\n----- --- .             print 'd'\n\u003e + .                   print '!'\n\u003e .                     print '\\n'\n~~~\n\nHere is the resulting C program, reformatted and commented to highlight how closely it resembles the original:\n\n~~~c\n#include \u003cstdio.h\u003e\n\nchar array[65536] = {0};\nchar *ptr = array;\n\nint main() {\n  *ptr+=10;                         // initialize counter (cell #0) to 10\n\n  while (*ptr) {                    // use loop to initialize the next cells\n    ptr+=1; *ptr+=7;                //     add  7 to cell #1 to be  70\n    ptr+=1; *ptr+=10;               //     add 10 to cell #2 to be 100\n    ptr+=1; *ptr+=3;                //     add  3 to cell #3 to be  30\n    ptr+=1; *ptr+=1;                //     add  1 to cell #4 to be  10\n    ptr-=4; *ptr-=1;                //     decrement counter (cell #0)\n  }\n\n  ptr+=1; *ptr+=2; putchar(*ptr);   // print 'H'\n  ptr+=1; *ptr+=1; putchar(*ptr);   // print 'e'\n  *ptr+=7; putchar(*ptr);           // print 'l'\n  putchar(*ptr);                    // print 'l'\n  *ptr+=3; putchar(*ptr);           // print 'o'\n  ptr+=1; *ptr+=2; putchar(*ptr);   // print ' '\n  ptr-=2; *ptr+=15; putchar(*ptr);  // print 'W'\n  ptr+=1; putchar(*ptr);            // print 'o'\n  *ptr+=3; putchar(*ptr);           // print 'r'\n  *ptr-=6; putchar(*ptr);           // print 'l'\n  *ptr-=8; putchar(*ptr);           // print 'd'\n  ptr+=1; *ptr+=1; putchar(*ptr);   // print '!'\n  ptr+=1; putchar(*ptr);            // print '\\n'\n\n  return 0;\n}\n~~~\n\nDue to the crazy optimizations built into [GCC] and [LLVM], even a naive C conversion like this one is bound to give you an immense performance boost over a standard Brainfuck interpreter.\n\n\nCommand-line interface\n----------------------\n\nYou can use the CLI to transpile a Brainfuck script into a C program by passing it source and destination files:\n\n~~~\n$ braincuck 99-bottles.bf 99-bottles.c\n~~~\n\nYou can compile the C code into an executable binary for your platform with [GCC] or [Clang]:\n\n~~~\n$ gcc -O3 99-bottles.c -o 99-bottles\n~~~\n\n\nProgrammatic API\n----------------\nThough I am not sure why would you want to do it, you can use the transpiler programmatically from your own code.\n\nYou can optionally enable the `bare` flag to return the inner code, without the surrounding C skeleton, in case you want to provide it yourself.\n\n~~~javascript\nconst transpile = require('braincuck');\n\nconst program = transpile(source, {\n  bare: false // If true, only inner code is returned\n});\n~~~\n\n\nCompatibility Notes\n-------------------\nThere is no single standard specification of a Brainfuck environment, so programs written with different assumptions will not work. Most Brainfuck programs, however, are compatible:\n\n- Cells are 8 bit-wide, signed, and they wrap-around.\n- The tape is 65536 cells long, starts from address zero, with no wrap-around.\n\nAlso, note that there are no boundary checks, so accessing anything outside the bounds of the tape will cause a segmentation fault.\n\n\nLicense\n-------\nCopyright (c) 2018, zenoamaro \u003czenoamaro@gmail.com\u003e\n\nThis software is released under the [MIT License](LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzenoamaro%2Fbraincuck","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzenoamaro%2Fbraincuck","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzenoamaro%2Fbraincuck/lists"}