From e6d9f6dc1edc3dc0dd030722a95f6c8c1da65055 Mon Sep 17 00:00:00 2001 From: Alvin <524715@vistacollege.nl> Date: Thu, 2 Oct 2025 13:25:27 +0200 Subject: [PATCH] bingbong --- languages/custom/bingbong/README.md | 76 +++++++++++++++++++ .../custom/bingbong/bingbong_interpreter.py | 39 ++++++++++ languages/custom/bingbong/example.bb | 1 + languages/custom/bingbong/hello.bb | 1 + languages/custom/bingbong/hello.py | 1 + languages/custom/bingbong/py_to_bingbong.py | 33 ++++++++ 6 files changed, 151 insertions(+) create mode 100644 languages/custom/bingbong/README.md create mode 100644 languages/custom/bingbong/bingbong_interpreter.py create mode 100644 languages/custom/bingbong/example.bb create mode 100644 languages/custom/bingbong/hello.bb create mode 100644 languages/custom/bingbong/hello.py create mode 100644 languages/custom/bingbong/py_to_bingbong.py diff --git a/languages/custom/bingbong/README.md b/languages/custom/bingbong/README.md new file mode 100644 index 0000000..90e9780 --- /dev/null +++ b/languages/custom/bingbong/README.md @@ -0,0 +1,76 @@ +# BingBong 2.0 + +BingBong is a minimalist, esoteric programming language designed to be as simple and difficult to use as possible. This new version of BingBong is a binary representation of Python code. + +## Language Elements + +The BingBong language consists of only two commands: + +* `.` (dot): Represents a `0` in the binary representation of the code. +* `,` (comma): Represents a `1` in the binary representation of the code. + +## Execution Model + +The interpreter reads the BingBong source code, converts the `.` and `,` characters to a binary string, decodes the binary string into a UTF-8 string, and then executes the resulting string as Python code. + +**Warning:** The interpreter uses `exec()` to run the decoded Python code. This is a powerful but potentially dangerous function. Only run BingBong code from sources you trust. + +## Interpreter + +The language is interpreted by the `bingbong_interpreter.py` script. + +### Usage + +To run a BingBong program, execute the interpreter from your command line and pass the path to your source file as an argument: + +```bash +python bingbong_interpreter.py your_program.bb +``` + +## Converter + +A helper script, `py_to_bingbong.py`, is provided to convert standard Python code into the BingBong format. + +### Usage + +To convert a Python file (`.py`) to a BingBong file (`.bb`), run the following command: + +```bash +python py_to_bingbong.py your_python_script.py +``` + +This will create a new file with the same name but with the `.bb` extension. + +### Example Workflow + +1. Create a Python file named `hello.py` with the following content: + + ```python + print("Hello, BingBong 2.0!") + ``` + +2. Convert it to a BingBong file: + + ```bash + python py_to_bingbong.py hello.py + ``` + +3. This will generate a `hello.bb` file with a long sequence of `.` and `,` characters. + +4. Run the BingBong file: + + ```bash + python bingbong_interpreter.py hello.bb + ``` + +5. The output will be: + + ``` + --- Executing Decoded Python Code --- + Hello, BingBong 2.0! + --- Execution Finished --- + ``` + +## Philosophy + +The design philosophy of BingBong is to explore the limits of simplicity in programming language design, while intentionally creating a cumbersome and difficult-to-master tool. It serves as a thought experiment and a challenge for programmers who enjoy working with esoteric languages. \ No newline at end of file diff --git a/languages/custom/bingbong/bingbong_interpreter.py b/languages/custom/bingbong/bingbong_interpreter.py new file mode 100644 index 0000000..6e7d7b3 --- /dev/null +++ b/languages/custom/bingbong/bingbong_interpreter.py @@ -0,0 +1,39 @@ +import sys + +def interpret_bingbong(source_code): + """ + Interprets a string of BingBong source code by converting it from a + binary representation to a Python script and executing it. + """ + binary_string = source_code.replace('.', '0').replace(',', '1') + + # Ensure the binary string has a valid length for UTF-8 conversion + if len(binary_string) % 8 != 0: + print("Error: The length of the binary string must be a multiple of 8.") + return + + try: + byte_array = bytearray(int(binary_string[i:i+8], 2) for i in range(0, len(binary_string), 8)) + python_code = byte_array.decode('utf-8') + + print("--- Executing Decoded Python Code ---") + # WARNING: exec() is used here, which can be dangerous. Only run trusted BingBong code. + exec(python_code) + print("--- Execution Finished ---") + + except Exception as e: + print(f"An error occurred during execution: {e}") + +if __name__ == "__main__": + if len(sys.argv) != 2: + print("Usage: python bingbong_interpreter.py ") + sys.exit(1) + + source_file = sys.argv[1] + try: + with open(source_file, 'r') as f: + source_code = f.read() + interpret_bingbong(source_code) + except FileNotFoundError: + print(f"Error: File not found at '{source_file}'") + sys.exit(1) \ No newline at end of file diff --git a/languages/custom/bingbong/example.bb b/languages/custom/bingbong/example.bb new file mode 100644 index 0000000..6dab1f1 --- /dev/null +++ b/languages/custom/bingbong/example.bb @@ -0,0 +1 @@ +... ,,. \ No newline at end of file diff --git a/languages/custom/bingbong/hello.bb b/languages/custom/bingbong/hello.bb new file mode 100644 index 0000000..f819d86 --- /dev/null +++ b/languages/custom/bingbong/hello.bb @@ -0,0 +1 @@ +.,,,.....,,,..,..,,.,..,.,,.,,,..,,,.,....,.,.....,...,..,..,....,,..,.,.,,.,,...,,.,,...,,.,,,,..,.,,....,......,....,..,,.,..,.,,.,,,..,,..,,,.,....,..,,.,,,,.,,.,,,..,,..,,,..,.......,,..,...,.,,,...,,......,....,..,...,...,.,.., \ No newline at end of file diff --git a/languages/custom/bingbong/hello.py b/languages/custom/bingbong/hello.py new file mode 100644 index 0000000..8afe1fe --- /dev/null +++ b/languages/custom/bingbong/hello.py @@ -0,0 +1 @@ +print("Hello, BingBong 2.0!") \ No newline at end of file diff --git a/languages/custom/bingbong/py_to_bingbong.py b/languages/custom/bingbong/py_to_bingbong.py new file mode 100644 index 0000000..aa7f30a --- /dev/null +++ b/languages/custom/bingbong/py_to_bingbong.py @@ -0,0 +1,33 @@ + +import sys + +def python_to_bingbong(python_code): + """ + Converts a string of Python code into its BingBong binary representation. + """ + byte_array = python_code.encode('utf-8') + binary_string = ''.join(f'{byte:08b}' for byte in byte_array) + bingbong_code = binary_string.replace('0', '.').replace('1', ',') + return bingbong_code + +if __name__ == "__main__": + if len(sys.argv) != 2: + print("Usage: python py_to_bingbong.py ") + sys.exit(1) + + python_file = sys.argv[1] + try: + with open(python_file, 'r') as f: + python_code = f.read() + + bingbong_code = python_to_bingbong(python_code) + + output_file = python_file.replace('.py', '.bb') + with open(output_file, 'w') as f: + f.write(bingbong_code) + + print(f"Successfully converted {python_file} to {output_file}") + + except FileNotFoundError: + print(f"Error: File not found at '{python_file}'") + sys.exit(1)