# ppazosp/interpppreter architecture

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

- Interactive diagram: https://gitdiagram.com/ppazosp/interpppreter
- Repository: https://github.com/ppazosp/interpppreter

## Overview

##### Project type and purpose
- This is an academic‐style, command‐driven **interactive mathematical expression interpreter** written in C.
- It uses Flex for lexical analysis, Bison for parsing, Readline for the REPL interface, and supports dynamic libraries for extensibility.

##### File structure
- Top‑level:
- Makefile – build orchestration
- ippp (final executable)
- / – all headers (.h)
- src/ – implementation (.c, .l, .y)
- resources/ – sample input files and dynamic libraries
- Key source files in src/:
- lex.l / lex.yy.c: lexer
- syn.y / syn.tab.c: parser
- main.c: entry point and REPL loop
- hash_table.c, symbol_table.c, stack.c: core runtime data structures
- error_handler.c, functions.c, dll.c: runtime services (errors, built‑in funcs, dynamic libs)

##### README for additional insights
- Describes commands (LOAD, IMPORT, WORKSPACE, etc.) and language conventions.
- Emphasis on dynamically loaded functions, history via Readline, and memory checking with Valgrind.

##### Elements
- Clear, descriptive labels for each module (e.g., “Lexer (Flex)”, “Parser (Bison)”)
- Yellow for compiler stages (lex, parse)
- Blue for runtime modules (symbol table, stack)
- Green for I/O and dynamic linking
- Gray for build tools
- Related files under each module (e.g., lex.l & lex.yy.c under Lexer)

##### Detail without over‑splitting
- Logical component distinctly (don’t lump lexer + parser into one block)
- How commands map onto pipeline invocations (LOAD uses file I/O + REPL, IMPORT uses DLL loader)
- Build step as a side module generating the `ippp` executable

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build Toolchain
    subgraph "Build Toolchain"
        MF["Makefile"]:::build
        EXE["ippp (Executable)"]:::build
    end
    MF -->|"build"| EXE

    %% REPL
    REPL["REPL / CLI (Readline)"]:::runtime

    %% Compiler Stages
    subgraph "Compiler Stages"
        LEX["Lexer (Flex)"]:::compiler
        PARSE["Parser (Bison)"]:::compiler
    end

    %% Execution Engine Components
    Exec["Execution Engine"]:::runtime
    subgraph "Execution Engine Modules"
        ST["Symbol Table"]:::runtime
        HT["Hash Table"]:::runtime
        STK["Stack"]:::runtime
        ERR["Error Handler"]:::runtime
        FUNC["Built-in Functions"]:::runtime
        DLL["Dynamic Library Loader"]:::io
    end

    %% File I/O & Plugins
    subgraph "File I/O & Plugins"
        IO["File I/O (LOAD)"]:::io
        EXT["External Resources"]:::io
    end

    %% Pipeline Flow
    REPL -->|"input"| LEX
    LEX -->|"tokens"| PARSE
    PARSE -->|"parse tree"| Exec
    Exec --> ST
    Exec --> HT
    Exec --> STK
    Exec --> FUNC
    Exec --> DLL
    Exec --> ERR
    DLL -->|"loads"| EXT
    Exec -->|"result"| REPL

    %% Command Triggers
    REPL -->|"LOAD"| IO
    IO --> REPL
    REPL -->|"IMPORT"| DLL

    %% Click Events
    click MF "https://github.com/ppazosp/interpppreter/tree/main/Makefile"
    click EXE "https://github.com/ppazosp/interpppreter/tree/main/ippp"
    click REPL "https://github.com/ppazosp/interpppreter/blob/main/src/main.c"
    click LEX "https://github.com/ppazosp/interpppreter/blob/main/src/lex.l"
    click PARSE "https://github.com/ppazosp/interpppreter/blob/main/src/syn.y"
    click ST "https://github.com/ppazosp/interpppreter/blob/main/src/symbol_table.c"
    click HT "https://github.com/ppazosp/interpppreter/blob/main/src/hash_table.c"
    click STK "https://github.com/ppazosp/interpppreter/blob/main/src/stack.c"
    click ERR "https://github.com/ppazosp/interpppreter/blob/main/src/error_handler.c"
    click FUNC "https://github.com/ppazosp/interpppreter/blob/main/src/functions.c"
    click DLL "https://github.com/ppazosp/interpppreter/blob/main/src/dll.c"

    %% Styles
    classDef compiler fill:#fdfd96,stroke:#333,stroke-width:1px
    classDef runtime fill:#aec6cf,stroke:#333,stroke-width:1px
    classDef io fill:#77dd77,stroke:#333,stroke-width:1px
    classDef build fill:#d3d3d3,stroke:#333,stroke-width:1px
```
