braincrap

From Esolang
Jump to navigation Jump to search
Braincrap
Paradigm(s) imperative
Designed by Huywallz
Appeared in 2025
Memory system Cell-based
Dimensions one-dimensional
Computational class Turing complete
Major implementations C
Influenced by Brainfuck
Influenced None
File extension(s) .bc

Braincrap is an extended version of the esoteric programming language Brainfuck, designed to provide additional functionality while maintaining the simplicity and minimalism of the original language. This extension introduces file inclusion and macro functionality, making it more versatile for larger projects and reusable code.

Additionally, Braincrap comes with a compiler (braincrap.c) that translates Braincrap code into C, allowing for efficient execution after compilation with a standard C compiler.

Features

  • File Inclusion: Allows importing external Braincrap files using the "$" syntax.
  • Macros: Define custom macros for easier and more efficient coding using the "#" syntax.
  • Braincrap Compiler (braincrap.c): Translates Braincrap code into C, which can then be compiled with a C compiler.
  • Efficiency: By compiling to C instead of interpreting directly, Braincrap programs can run faster than traditional Brainfuck interpreters.
  • Modular Programming: Using file inclusion and macros, Braincrap allows for better code organization and reuse.

Getting Started

Prerequisites

To compile and run Braincrap programs, you need:

  • A C compiler (such as gcc or clang)
  • A terminal (Linux/macOS) or Command Prompt (Windows)

Installing the Braincrap Compiler

First, compile the braincrap.c compiler:

gcc braincrap.c -o braincrap

This will create an executable named braincrap.

Writing Your First Braincrap Program

Create a file named hello.bc and add the following Braincrap code:

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

This is the traditional "Hello, World!" program in Brainfuck, which also works in Braincrap.

Now, compile it into C:

./braincrap hello.bc hello.c

Then, compile the generated C code:

gcc hello.c -o hello

Finally, run the compiled program:

./hello

You should see:

Hello, World!

Braincrap Syntax

Braincrap extends Brainfuck's standard 8 commands (`+`, `-`, `<`, `>`, `[`, `]`, `.` and `,`) with the following new features:

Macros

Macros allow defining custom single-character shortcuts for Brainfuck code.

Syntax

#<character> <Brainfuck code>

Example

#X +++[->++<]
X

Expands to:

+++[->++<]

File Inclusion

Files can be included using the "$" symbol followed by the filepath.

Syntax

$<filepath>

Example

$utilities.bc

This will insert the contents of utilities.bc into the program.

Examples

Example 1: Using Macros

#A +++[->++<]  
#B ---[->--<]  

AABBA

This expands into:

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

Example 2: File Inclusion

Create a file called math.bc:

#M +++[->+++<]

Now use it in another file:

$math.bc
M

This expands into:

+++[->+++<]

Compilation & Execution

Braincrap code is compiled to C using braincrap.c, which can then be compiled with any standard C compiler.

Compile Braincrap to C

./braincrap myfile.bc output.c

Compile the Generated C Code

gcc output.c -o myprogram

Run the Compiled Program

./myprogram

License

Braincrap is an open-source project released under the MIT License. Feel free to use, modify, and distribute it as you see fit.