# shamsparvezarka/bmo architecture

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

- Interactive diagram: https://gitdiagram.com/shamsparvezarka/bmo
- Repository: https://github.com/shamsparvezarka/bmo

## Overview

##### Main Components
- BMO Front-End Components:
- Lexer (source/Lexer.java): Responsible for reading raw input text and outputting tokens.
- Parser (source/Parser.java): Transforms tokens into an Abstract Syntax Tree (AST) consisting of expression nodes (source/Expr.java) and statement nodes (source/Stmt.java).
- Resolver (source/Resolver.java): Performs variable and scope resolution to validate semantics before interpretation.
- Interpreter & Environment:
- Interpreter (source/Interpreter.java): Executes the AST by evaluating expressions and executing statements.
- Environment (source/Environment.java): Manages variable scopes and runtime context.
- Error Handling:
- RuntimeError (source/RuntimeError.java) and Return (source/Return.java): Handle exceptions and control flow during execution.
- Supporting Functionality:
- BMO.java, BMOCallable.java, BmoFunction.java: Likely represent the main entry point and provide support for functions/callable objects.
- AST Generation:
- Tool component (tool/GenerateAst.java): A utility for generating or transforming the AST classes for the language.
- Build and Documentation:
- build.ps1 and related build scripts indicate a script-driven build process generating class files, while DOCUMENTATION.md documents the language.

- Input Source Code (BMO code from test/main.bmo or user input) →
- Lexer: A component that tokenizes the input.
- Parser: Consumes tokens to produce the AST (represented by Expr and Stmt nodes).
- Resolver: Analyzes the AST to resolve variable scopes, linking identifiers to definitions.
- Interpreter: Executes the AST based on the current Environment, performing runtime logic.
- Supporting function modules such as BMOCallable and BmoFunction which are used when the AST includes function calls.
- Error handling via RuntimeError and the control flow flag Return.

##### Architectural Patterns
- The project uses the Interpreter design pattern, employing separate classes for each language processing stage.
- There is a clear separation between the lexing/parsing (front-end) and execution (back-end) phases.
- The AST generation tool exemplifies a meta-programming approach that eases AST class expansion/modification.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "BMO Interpreter Flow"
        M["Main Entry (Bmo)"]:::main
        A["Input Source Code"]:::main
        B["Lexer"]:::lex
        C["Parser"]:::lex
        subgraph "AST Nodes"
            D1["Expr"]:::ast
            D2["Stmt"]:::ast
        end
        E["Resolver"]:::runtime
        F["Interpreter"]:::runtime
        G["Environment"]:::env
        subgraph "Error Handling"
            H1["RuntimeError"]:::error
            H2["Return"]:::error
        end
        subgraph "Function Support"
            I1["BmoCallable"]:::func
            I2["BmoFunction"]:::func
        end
    end

    subgraph "Build/Documentation Tools"
        J["AST Generation Tool (GenerateAst)"]:::tool
        K["Build Script (build.ps1)"]:::tool
        L["Documentation (DOCUMENTATION.md)"]:::tool
    end

    M -->|"starts"| B
    A -->|"raw_code"| B
    B -->|"tokens"| C
    C -->|"creates_AST"| D1
    C -->|"creates_AST"| D2
    D1 -->|"AST_nodes"| E
    D2 -->|"AST_nodes"| E
    E -->|"resolved_AST"| F
    F -->|"executes_in"| G
    F -->|"handles"| H1
    F -->|"controls"| H2
    F -->|"invokes"| I1
    F -->|"invokes"| I2

    J -.-> C
    K -.-> A
    L -.-> A

    click B "https://github.com/shamsparvezarka/bmo/blob/main/source/Lexer.java"
    click C "https://github.com/shamsparvezarka/bmo/blob/main/source/Parser.java"
    click D1 "https://github.com/shamsparvezarka/bmo/blob/main/source/Expr.java"
    click D2 "https://github.com/shamsparvezarka/bmo/blob/main/source/Stmt.java"
    click E "https://github.com/shamsparvezarka/bmo/blob/main/source/Resolver.java"
    click F "https://github.com/shamsparvezarka/bmo/blob/main/source/Interpreter.java"
    click G "https://github.com/shamsparvezarka/bmo/blob/main/source/Environment.java"
    click H1 "https://github.com/shamsparvezarka/bmo/blob/main/source/RuntimeError.java"
    click H2 "https://github.com/shamsparvezarka/bmo/blob/main/source/Return.java"
    click I1 "https://github.com/shamsparvezarka/bmo/blob/main/source/BmoCallable.java"
    click I2 "https://github.com/shamsparvezarka/bmo/blob/main/source/BmoFunction.java"
    click M "https://github.com/shamsparvezarka/bmo/blob/main/source/Bmo.java"
    click J "https://github.com/shamsparvezarka/bmo/blob/main/tool/GenerateAst.java"
    click K "https://github.com/shamsparvezarka/bmo/blob/main/build.ps1"
    click L "https://github.com/shamsparvezarka/bmo/blob/main/DOCUMENTATION.md"

    classDef lex fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef ast fill:#d4edda,stroke:#333,stroke-width:2px;
    classDef runtime fill:#fff3cd,stroke:#333,stroke-width:2px;
    classDef env fill:#d1ecf1,stroke:#333,stroke-width:2px;
    classDef error fill:#f8d7da,stroke:#333,stroke-width:2px;
    classDef tool fill:#e2e3e5,stroke:#333,stroke-width:2px;
    classDef main fill:#d6d8d9,stroke:#333,stroke-width:2px;
    classDef func fill:#ffeeba,stroke:#333,stroke-width:2px;
```
