|
bfx
An interpreter, compiler, and REPL for brainfuck-like languages
|
#include <stdbool.h>#include <stddef.h>#include <stdint.h>#include <stdio.h>#include <stdlib.h>Go to the source code of this file.
Data Structures | |
| struct | BFX_FileIndex |
| Structure to represent an index in a file (or user input). More... | |
| struct | BFX_Block |
| Structure to represent a loop in the brainfuck program. This structure holds the start and end indices of a loop, allowing the interpreter to efficiently jump between matching brackets during execution. More... | |
| struct | BFX |
| Structure to store generic data for a brainfuck-like esolang interpreter. More... | |
Macros | |
| #define | BFX_DEFAULT_INPUT_MAX 1024 |
| Default maximum input size for the interpreter. | |
| #define | BFX_DEFAULT_TAPE_SIZE 30000 |
| Default tape size for the interpreter. | |
| #define | BFX_INITIAL_LOOP_SIZE 2048 |
| Default maximum loop count for the interpreter (scaled anyways if higher) | |
| #define | BFX_PROCEDURE_SIZE 128 |
| Default maximum procedure count for interpreter. | |
| #define | BFX_VERSION "unknown" |
| Version of the libbfx library. | |
| #define | BFX_DEFAULT_LANG BFX_LANG_BRAINFUCK |
| Default language for the interpreter/compiler. | |
| #define | BFX_DEFAULT_EOF_BEHAVIOR BFX_EOF_BEHAVIOR_ZERO |
| Default EOF behavior for the interpreter. | |
| #define | BFX_FLAG_DEBUG 1 |
| Interpreter: Debug mode. | |
| #define | BFX_FLAG_REPL 2 |
| Interpreter: REPL mode. | |
| #define | BFX_FLAG_DISABLE_SPECIAL_INSTRUCTIONS 4 |
| Interpreter: Disable special instructions. | |
| #define | BFX_FLAG_LANG_DATA_FLAGS 8 |
| lang_data contains flags for the given language | |
| #define | BFX_FLAG_GRAPHICS 16 |
| Interpreter: Enable graphics mode. | |
| #define | BFX_FLAG_SEPARATE_INPUT_AND_SOURCE 32 |
| Interpreter: Use input in source file separated by '!'. | |
| #define | BFX_FLAG_DEGREES 64 |
| Interpreter (Grin): Use degrees instead of radians. | |
| #define | BFX_ERROR(s) fprintf(stderr, "libbfx: Error: %s\n", s); |
| Error handling macro for the interpreter. | |
| #define | BFX_IN_DEBUG_MODE(b) ((b).flags & BFX_FLAG_DEBUG) |
| Check if the interpreter is in debug mode (arg is of type BFX) | |
| #define | BFX_IN_REPL_MODE(b) ((b).flags & BFX_FLAG_REPL) |
| Check if the interpreter is in REPL mode (arg is of type BFX) | |
| #define | BFX_SPECIAL_INSTRUCTIONS_ENABLED(b) (!((b).flags & BFX_FLAG_DISABLE_SPECIAL_INSTRUCTIONS)) |
| Check if the interpreter has special instructions enabled (arg is of type BFX) | |
Enumerations | |
| enum | BFX_EOFBehavior { BFX_EOF_BEHAVIOR_ZERO , BFX_EOF_BEHAVIOR_DECREMENT , BFX_EOF_BEHAVIOR_UNCHANGED } |
| Behaviors for the interpreter when an EOF is encountered in input. More... | |
| enum | BFX_Language { BFX_LANG_UNKNOWN , BFX_LANG_brainfuck , BFX_LANG_brainfork , BFX_LANG_pbrain , BFX_LANG_grin , BFX_LANG_weave } |
| Language options for the interpreter/compiler. More... | |
| enum | BFX_Error { BFX_SUCCESS = 0 , BFX_STACK_OVERFLOW_ERROR , BFX_STACK_UNDERFLOW_ERROR , BFX_SYNTAX_ERROR , BFX_OUT_OF_MEMORY_ERROR , BFX_RUNTIME_ERROR } |
Functions | |
| void | bfx_free (BFX *) |
| Frees the memory allocated for the BFX instance. | |
| BFX_Error | bfx_run_file (const char *, BFX *) |
| Runs the program loaded from a file. | |
| BFX_Error | bfx_run_repl (BFX *) |
| Runs the BFX interpreter in REPL (Read-Eval-Print Loop) mode. | |
| #define BFX_DEFAULT_EOF_BEHAVIOR BFX_EOF_BEHAVIOR_ZERO |
Default EOF behavior for the interpreter.
| #define BFX_DEFAULT_INPUT_MAX 1024 |
Default maximum input size for the interpreter.
| #define BFX_DEFAULT_LANG BFX_LANG_BRAINFUCK |
Default language for the interpreter/compiler.
| #define BFX_DEFAULT_TAPE_SIZE 30000 |
Default tape size for the interpreter.
| #define BFX_ERROR | ( | s | ) | fprintf(stderr, "libbfx: Error: %s\n", s); |
Error handling macro for the interpreter.
| #define BFX_FLAG_DEBUG 1 |
Interpreter: Debug mode.
| #define BFX_FLAG_DEGREES 64 |
Interpreter (Grin): Use degrees instead of radians.
| #define BFX_FLAG_DISABLE_SPECIAL_INSTRUCTIONS 4 |
Interpreter: Disable special instructions.
| #define BFX_FLAG_GRAPHICS 16 |
Interpreter: Enable graphics mode.
| #define BFX_FLAG_LANG_DATA_FLAGS 8 |
lang_data contains flags for the given language
| #define BFX_FLAG_REPL 2 |
Interpreter: REPL mode.
| #define BFX_FLAG_SEPARATE_INPUT_AND_SOURCE 32 |
Interpreter: Use input in source file separated by '!'.
| #define BFX_IN_DEBUG_MODE | ( | b | ) | ((b).flags & BFX_FLAG_DEBUG) |
Check if the interpreter is in debug mode (arg is of type BFX)
| #define BFX_IN_REPL_MODE | ( | b | ) | ((b).flags & BFX_FLAG_REPL) |
Check if the interpreter is in REPL mode (arg is of type BFX)
| #define BFX_INITIAL_LOOP_SIZE 2048 |
Default maximum loop count for the interpreter (scaled anyways if higher)
| #define BFX_PROCEDURE_SIZE 128 |
Default maximum procedure count for interpreter.
| #define BFX_SPECIAL_INSTRUCTIONS_ENABLED | ( | b | ) | (!((b).flags & BFX_FLAG_DISABLE_SPECIAL_INSTRUCTIONS)) |
Check if the interpreter has special instructions enabled (arg is of type BFX)
| #define BFX_VERSION "unknown" |
Version of the libbfx library.
| enum BFX_EOFBehavior |
| enum BFX_Error |
| enum BFX_Language |
| void bfx_free | ( | BFX * | bfx | ) |
Runs the program loaded from a file.
This function builds the loop structure for the BFX instance, then iterates through the program instructions, interpreting each one until the end of the program is reached.