# wisenheim/yarmin architecture

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

- Interactive diagram: https://gitdiagram.com/wisenheim/yarmin
- Repository: https://github.com/wisenheim/yarmin

## Overview

##### Project type and purpose
- **Type**: A compiler‐style project—specifically an interpreter for an imperative (and functional) toy language written in OCaml.
- **Purpose**: To parse source strings or files into an AST, then evaluate that AST in a denotational (functional) style using dynamic local and static non‐local environments. It also supports reflection by re‐parsing strings at runtime.

##### File structure
Top level:
- README.md – project overview and build/run instructions
- YarminDocs/ – LaTeX documentation source (design choices, parsing & lexing, testing, glossary)
- src/ – all OCaml source and build scripts

src/ contains:
- Lexing (YarminLexer.{mll,ml,cm*})
- Parsing (YarminParser.{mly,ml,cm*,mli})
- AST definition (Ast.{mli,cmi})
- Environments & store (Funenv.{ml,mli,cm*}; Funstore.{ml,mli,cm*})
- Core interpreter (yarmin.ml, yarminBasic.ml, loadAll.ml)
- Test harness (YarminTest.ml)
- Scripts (compileAll.sh)

##### README for additional insights
- Uses Menhir for parsing, ocamllex for lexing
- Denotational interpreter with distinct environment layers
- REPL interaction via rlwrap + OCaml toplevel, loading loadAll.ml
- Automated tests via `#use "YarminTest.ml"`

##### Components
a. Main components
1. User / REPL Frontend (rlwrap + OCaml toplevel)
2. Build Layer (compileAll.sh)
3. Lexer (YarminLexer)
4. Parser (YarminParser / Menhir)
5. AST Module (Ast)
6. Semantic Modules
- Environment Manager (Funenv)
- Store Manager (Funstore)
7. Interpreter Core (yarmin.ml, yarminBasic.ml)
8. Reflection Mechanism (invokes Lexer+Parser at runtime)
9. Test Harness (YarminTest.ml)
10. Documentation (YarminDocs) – secondary

b. Relationships & data flows
- The user types code or tests in the REPL, `#use "loadAll.ml"`.
- loadAll.ml loads all compiled modules into memory.
- Interpreter Core calls the Lexer to tokenize input, then Parser to build an AST.
- AST is handed off to the denotational evaluator in Interpreter Core.
- The evaluator uses Funenv for local/static environment lookups and Funstore for mutable state.
- Reflection calls back into the Lexer+Parser pipeline at runtime.
- Test Harness invokes Interpreter Core on predefined test scripts.

c. Architectural patterns / design principles
- **Pipelined architecture**: clear stages (lexing → parsing → AST → evaluation).
- **Modular design**: each concern in separate module (lexer, parser, AST, env, store, core).
- **Denotational semantics**: interpreter functions map AST nodes to semantic values.
- **Reflection**: self‐hosted parsing at runtime.
- **Scripted build**: compileAll.sh ensures all modules are built before REPL usage.

d. Key technologies / frameworks
- OCaml (core language)
- Menhir (parser generator)
- ocamllex (lexer generator)
- rlwrap + OCaml toplevel for REPL
- Bash (compileAll.sh)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend Layer"
        REPL["User / REPL (rlwrap + OCaml toplevel)"]:::frontend
        LoadAll["loadAll.ml"]:::frontend
    end

    %% Build Layer
    subgraph "Build Layer"
        Build["compileAll.sh"]:::build
    end

    %% Pipeline Stages
    subgraph "Pipeline Stages"
        Lexer["YarminLexer"]:::pipeline
        Parser["YarminParser"]:::pipeline
        AST["Ast Module"]:::pipeline
        Evaluator["Interpreter Core"]:::pipeline
    end

    %% Semantic Modules
    subgraph "Semantic Modules"
        Funenv["Funenv (Environment Manager)"]:::semantic
        Funstore["Funstore (Store Manager)"]:::semantic
    end

    %% Test and Documentation
    subgraph "Auxiliary Components"
        Test["Test Harness (YarminTest)"]:::test
        Docs["Documentation (YarminDocs)"]:::docs
        Readme["Project Overview (README.md)"]:::docs
    end

    %% Data Flows
    REPL -->|"#use loadAll.ml"| LoadAll
    LoadAll -->|"builds modules"| Build
    Build -->|"compiles"| Lexer
    Lexer -->|"tokens"| Parser
    Parser -->|"AST"| AST
    AST -->|"AST nodes"| Evaluator
    Evaluator -->|"semantic value"| REPL
    Evaluator -->|"uses"| Funenv
    Evaluator -->|"uses"| Funstore
    Evaluator -->|"reflection: source string"| Lexer
    Test -->|"invokes"| Evaluator

    %% Click Events
    click LoadAll "https://github.com/wisenheim/yarmin/blob/master/src/loadAll.ml"
    click Build "https://github.com/wisenheim/yarmin/blob/master/src/compileAll.sh"
    click Lexer "https://github.com/wisenheim/yarmin/blob/master/src/YarminLexer.mll"
    click Parser "https://github.com/wisenheim/yarmin/blob/master/src/YarminParser.mly"
    click AST "https://github.com/wisenheim/yarmin/blob/master/src/Ast.mli"
    click Evaluator "https://github.com/wisenheim/yarmin/blob/master/src/yarmin.ml"
    click Funenv "https://github.com/wisenheim/yarmin/blob/master/src/Funenv.ml"
    click Funstore "https://github.com/wisenheim/yarmin/blob/master/src/Funstore.ml"
    click Test "https://github.com/wisenheim/yarmin/blob/master/src/YarminTest.ml"
    click Docs "https://github.com/wisenheim/yarmin/tree/master/YarminDocs/"
    click Readme "https://github.com/wisenheim/yarmin/blob/master/README.md"

    %% Styles
    classDef frontend fill:#f9f,stroke:#333,stroke-width:1px;
    classDef build fill:#ff9,stroke:#333,stroke-width:1px;
    classDef pipeline fill:#9ff,stroke:#333,stroke-width:1px;
    classDef semantic fill:#9f9,stroke:#333,stroke-width:1px;
    classDef test fill:#f99,stroke:#333,stroke-width:1px;
    classDef docs fill:#ccc,stroke:#333,stroke-width:1px;
```
