# hen-mi/sunflower architecture

> Architecture diagram of the GitHub repository hen-mi/sunflower, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hen-mi/sunflower
- Repository: https://github.com/hen-mi/sunflower

## Overview

Sunflower is a small dynamically typed scripting language. Its demonstrated workflow reads the example program, tokenizes it, parses tokens into statement and expression ASTs, then evaluates that AST using runtime environments and callable functions; print statements write results to the console. The README documents declarations, expressions, control flow, functions, and returns, which are handled across parsing and evaluation. The resolver exists as a separate scope-analysis component, but the sampled entry point does not invoke it. Runtime wiring is based on sampled source; broader feature coverage follows the README.

Main entry points: [`src/Evaluator.cpp`](https://github.com/hen-mi/sunflower/blob/main/src/Evaluator.cpp) (Evaluator), [`src/main.cpp`](https://github.com/hen-mi/sunflower/blob/main/src/main.cpp) (Program Entry), [`src/Parser.cpp`](https://github.com/hen-mi/sunflower/blob/main/src/Parser.cpp) (Parser), [`src/Lexer.cpp`](https://github.com/hen-mi/sunflower/blob/main/src/Lexer.cpp) (Tokenizer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_front["Language Front End"]
  node_main["Program Entry<br/>[main.cpp]"]
  node_source["Source Text"]
  node_lexer["Tokenizer<br/>[Lexer.cpp]"]
  node_parser["Parser<br/>[Parser.cpp]"]
end

subgraph group_syntax["Syntax Model"]
  node_stmtast["Statement AST<br/>[Statements.h]"]
  node_exprast["Expression AST<br/>[Expressions.h]"]
end

subgraph group_runtime["Runtime"]
  node_evaluator["Evaluator<br/>[Evaluator.cpp]"]
  node_environment["Environments<br/>[Environment.cpp]"]
  node_callable["Function Calls<br/>[Callable.cpp]"]
  node_resolver["Scope Resolver<br/>[Resolver.cpp]"]
end

subgraph group_support["Runtime Support"]
  node_reader["File Utilities<br/>[Sunflower.cpp]"]
end

node_user(("Program Runner"))
node_console(("Console Output"))

node_user -->|"runs"| node_main
node_main -->|"reads source"| node_reader
node_reader -->|"returns text"| node_source
node_main -->|"tokenizes text"| node_lexer
node_lexer -->|"passes tokens"| node_parser
node_parser -->|"builds statements"| node_stmtast
node_parser -->|"builds expressions"| node_exprast
node_main -->|"runs AST"| node_evaluator
node_evaluator -->|"visits statements"| node_stmtast
node_evaluator -->|"evaluates expressions"| node_exprast
node_evaluator -->|"reads and updates"| node_environment
node_evaluator -->|"invokes functions"| node_callable
node_evaluator -->|"prints values"| node_console

click node_main "https://github.com/hen-mi/sunflower/blob/main/src/main.cpp"
click node_reader "https://github.com/hen-mi/sunflower/blob/main/src/Sunflower.cpp"
click node_lexer "https://github.com/hen-mi/sunflower/blob/main/src/Lexer.cpp"
click node_parser "https://github.com/hen-mi/sunflower/blob/main/src/Parser.cpp"
click node_stmtast "https://github.com/hen-mi/sunflower/blob/main/src/AST/Statements.h"
click node_exprast "https://github.com/hen-mi/sunflower/blob/main/src/AST/Expressions.h"
click node_evaluator "https://github.com/hen-mi/sunflower/blob/main/src/Evaluator.cpp"
click node_environment "https://github.com/hen-mi/sunflower/blob/main/src/Environment.cpp"
click node_callable "https://github.com/hen-mi/sunflower/blob/main/src/Callable.cpp"
click node_resolver "https://github.com/hen-mi/sunflower/blob/main/src/Resolver.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_source,node_lexer,node_parser toneBlue
class node_stmtast,node_exprast toneAmber
class node_evaluator,node_environment,node_callable,node_resolver toneMint
class node_reader toneRose
class node_user,node_console toneIndigo
```

## Components

### Language Front End

- [Program Entry](https://github.com/hen-mi/sunflower/blob/main/src/main.cpp): `src/main.cpp`
- **Source Text**
- [Tokenizer](https://github.com/hen-mi/sunflower/blob/main/src/Lexer.cpp): `src/Lexer.cpp`
- [Parser](https://github.com/hen-mi/sunflower/blob/main/src/Parser.cpp): `src/Parser.cpp`

### Syntax Model

- [Statement AST](https://github.com/hen-mi/sunflower/blob/main/src/AST/Statements.h): `src/AST/Statements.h`
- [Expression AST](https://github.com/hen-mi/sunflower/blob/main/src/AST/Expressions.h): `src/AST/Expressions.h`

### Runtime

- [Evaluator](https://github.com/hen-mi/sunflower/blob/main/src/Evaluator.cpp): `src/Evaluator.cpp`
- [Environments](https://github.com/hen-mi/sunflower/blob/main/src/Environment.cpp): `src/Environment.cpp`
- [Function Calls](https://github.com/hen-mi/sunflower/blob/main/src/Callable.cpp): `src/Callable.cpp`
- [Scope Resolver](https://github.com/hen-mi/sunflower/blob/main/src/Resolver.cpp): `src/Resolver.cpp`

### Runtime Support

- [File Utilities](https://github.com/hen-mi/sunflower/blob/main/src/Sunflower.cpp): `src/Sunflower.cpp`

### Other components

- **Program Runner**
- **Console Output**

## Connections

- Program Runner → Program Entry: runs
- Program Entry → File Utilities: reads source
- File Utilities → Source Text: returns text
- Program Entry → Tokenizer: tokenizes text
- Tokenizer → Parser: passes tokens
- Parser → Statement AST: builds statements
- Parser → Expression AST: builds expressions
- Program Entry → Evaluator: runs AST
- Evaluator → Statement AST: visits statements
- Evaluator → Expression AST: evaluates expressions
- Evaluator → Environments: reads and updates
- Evaluator → Function Calls: invokes functions
- Evaluator → Console Output: prints values
