# ludosniper/digited architecture

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

- Interactive diagram: https://gitdiagram.com/ludosniper/digited
- Repository: https://github.com/ludosniper/digited

## Overview

##### Project type and purpose
- This is a domain‐specific programming language (“Digited”), Brainfuck-like but digit-only.
- It provides both a compiler (two versions) and an interpreter, plus a CLI entry point (`digited.py`) and test cases.

##### File structure
Top-level
– README.md (project description)
– digited.py (CLI orchestration: compile or interpret)
– /compilator
- compilator.py (pure-Python compiler v1)
- compilatorv2.py (lexer/parser-based compiler v2)
- tests/
– digited_lex.l, digited_yacc.y (lexer & parser specs)
– generated C: lex.yy.c, y.tab.c/h
– /interpreter
- interpreter.py (runtime engine)
– /tests
- helloworld.dg (sample Digited programs)

##### README for insights
- Defines language semantics (commands 0–9, parentheses for comments).
- Notes unimplemented features (nested loops/comments, input command).

##### Important notes
– Be thorough but avoid over-segmenting: group related files under shared components.
– Capture all essential elements: CLI entry, both compiler versions, interpreter engine, and test harness.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Dependencies
    subgraph "External Dependencies"
        PY3["Python 3"]:::external
        PLY["PLY / flex+bison"]:::external
    end

    %% CLI Layer
    subgraph "CLI Layer"
        CLI["CLI (digited.py)"]:::compile
    end

    %% Compiler Modules
    subgraph "Compiler Modules"
        subgraph "Compiler v1" 
            CV1["Compiler v1\n(compilator.py)"]:::compile
        end
        subgraph "Compiler v2"
            CV2["Compiler v2\n(compilatorv2.py)"]:::compile
            subgraph "Pipeline"
                LA["Lexical Analyzer"]:::compile
                PR["Parser"]:::compile
                CG["Code Generator"]:::compile
            end
        end
    end

    %% Interpreter Module
    subgraph "Interpreter Module"
        IM["Interpreter Engine\n(interpreter.py)"]:::runtime
        subgraph "Runtime Components"
            BM["Buffer Manager"]:::runtime
            CC["Cursor Controller"]:::runtime
            LE["Loop Executor"]:::runtime
            IOH["I/O Handler"]:::runtime
        end
    end

    %% Test Harness
    subgraph "Test Harness"
        subgraph "Compiler Tests"
            CTests["Compiler Tests\n(compilator/tests/)"]:::test
            subgraph "Generated C Code"
                LYY["lex.yy.c"]:::test
                YTC["y.tab.c"]:::test
                YTH["y.tab.h"]:::test
            end
        end
        Samples["Sample Programs\n(helloworld.dg)"]:::test
    end

    %% Data Flows
    Samples -->|"provides .dg file"| CLI
    CLI -->|"uses"| CV1
    CLI -->|"uses"| CV2
    CV2 -->|"feeds"| LA
    LA -->|"tokens"| PR
    PR -->|"AST/IR"| CG
    CLI -->|"bypasses compile"| IM
    CG -->|"IR/C code"| IM

    CTests --> CV1
    CTests --> CV2
    CG --> LYY
    CG --> YTC
    CG --> YTH
    PY3 --> CLI
    PLY --> CV2

    IM --> BM
    IM --> CC
    IM --> LE
    IM --> IOH

    %% Click Events
    click CLI "https://github.com/ludosniper/digited/blob/main/digited.py"
    click CV1 "https://github.com/ludosniper/digited/blob/main/compilator/compilator.py"
    click CV2 "https://github.com/ludosniper/digited/blob/main/compilator/compilatorv2.py"
    click LA "https://github.com/ludosniper/digited/blob/main/compilator/tests/digited_lex.l"
    click PR "https://github.com/ludosniper/digited/blob/main/compilator/tests/digited_yacc.y"
    click LYY "https://github.com/ludosniper/digited/blob/main/compilator/tests/lex.yy.c"
    click YTC "https://github.com/ludosniper/digited/blob/main/compilator/tests/y.tab.c"
    click YTH "https://github.com/ludosniper/digited/blob/main/compilator/tests/y.tab.h"
    click CTests "https://github.com/ludosniper/digited/tree/main/compilator/tests/"
    click Samples "https://github.com/ludosniper/digited/blob/main/tests/helloworld.dg"

    %% Styles
    classDef compile fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef runtime fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef test fill:#FFD580,stroke:#000,stroke-width:1px;
    classDef external fill:#E0E0E0,stroke:#000,stroke-width:1px;
```
