# imgajeed76/bfscript architecture

> Architecture diagram of the GitHub repository imgajeed76/bfscript, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/imgajeed76/bfscript
- Repository: https://github.com/imgajeed76/bfscript

## Overview

##### Project Type & Purpose
- This is a compiler/interpreter project. Its purpose is to allow developers to write code in an easier, C-inspired syntax and then compile that code into Brainfuck, which is then executed by a custom interpreter.
- The README outlines that the compiler provides familiar constructs – such as variable declarations, loops and conditionals – and that the interpreter can execute the produced Brainfuck code. It also explicitly emphasizes a 32-bit cell architecture.

##### File Structure
- Top-Level Files & Directories:
- The root directory includes key files like compiler.py and interpreter.py. These act as the entry points for command-line usage.
- The lib directory further divides the implementation into submodules:
◦ lib/compiler: Contains modules such as assembler.py, compiler.py, memory_manager.py, preprocessing.py, scope_manager.py, transformer.py, and a grammar file (brainfuckscript.lark). Test files for the compiler are included here.
◦ lib/interpreter.py and lib/test_interpreter.py provide the core logic and tests for the Brainfuck interpreter.
- Examples Directory:
- Contains sample source code (e.g., pyramid.bfs) used for demonstration.
- Configuration Files:
- pyproject.toml configures dependencies and builds with Poetry.
- .gitignore and LICENSE.md handle version control and licensing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Compiler Pipeline
    subgraph "Compiler Pipeline"
        s_source["BrainfuckScript Source (.bfs)"]:::external
        compilerFE["Compiler Frontend (CLI)"]:::cli
        parserLark["Parser (Lark)"]:::module
        preProc["Preprocessing Module"]:::module
        scopeManager["Scope Management Module"]:::module
        transformer["Transformer"]:::module
        assembler["Assembler"]:::module
        memoryMgr["Memory Manager (32-bit)"]:::module
        compilerOutput["Generated Brainfuck (.bf)"]:::external
    end

    %% Interpreter Workflow
    subgraph "Interpreter Workflow"
        interpreterInput["Brainfuck Code (.bf)"]:::external
        interpreterFE["Interpreter Frontend (CLI)"]:::cli
        executionEngine["Execution Engine"]:::module
    end

    %% Supporting Components
    subgraph "Supporting Components"
        compilerTesting["Compiler Testing"]:::module
        interpreterTesting["Interpreter Testing"]:::module
        examples["Examples"]:::external
    end

    %% Data Flows for Compiler Pipeline
    s_source -->|"reads"| compilerFE
    compilerFE -->|"calls"| parserLark
    parserLark -->|"parses"| preProc
    preProc -->|"processes"| scopeManager
    scopeManager -->|"prepares AST for"| transformer
    transformer -->|"transforms code to"| assembler
    assembler -->|"assembles into"| memoryMgr
    memoryMgr -->|"outputs"| compilerOutput

    %% Link Compiler to Interpreter Workflow
    compilerOutput -->|"input to"| interpreterInput
    interpreterInput -->|"loads"| interpreterFE
    interpreterFE -->|"executes with"| executionEngine

    %% Supporting Testing Relationships
    memoryMgr -- "verified_by" --> compilerTesting
    executionEngine -- "verified_by" --> interpreterTesting

    %% Click Events
    click compilerFE "https://github.com/imgajeed76/bfscript/blob/master/compiler.py"
    click interpreterFE "https://github.com/imgajeed76/bfscript/blob/master/interpreter.py"
    click parserLark "https://github.com/imgajeed76/bfscript/blob/master/lib/compiler/brainfuckscript.lark"
    click preProc "https://github.com/imgajeed76/bfscript/blob/master/lib/compiler/preprocessing.py"
    click scopeManager "https://github.com/imgajeed76/bfscript/blob/master/lib/compiler/scope_manager.py"
    click transformer "https://github.com/imgajeed76/bfscript/blob/master/lib/compiler/transformer.py"
    click assembler "https://github.com/imgajeed76/bfscript/blob/master/lib/compiler/assembler.py"
    click memoryMgr "https://github.com/imgajeed76/bfscript/blob/master/lib/compiler/memory_manager.py"
    click executionEngine "https://github.com/imgajeed76/bfscript/blob/master/lib/interpreter.py"
    click compilerTesting "https://github.com/imgajeed76/bfscript/blob/master/lib/compiler/test_assembler.py"
    click interpreterTesting "https://github.com/imgajeed76/bfscript/blob/master/lib/test_interpreter.py"
    click examples "https://github.com/imgajeed76/bfscript/tree/master/examples"

    %% Styles
    classDef cli fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef module fill:#ccffcc,stroke:#006600,stroke-width:2px;
    classDef external fill:#ccccff,stroke:#0000cc,stroke-width:2px;
```
