# coderz90/biharlang architecture

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

- Interactive diagram: https://gitdiagram.com/coderz90/biharlang
- Repository: https://github.com/coderz90/biharlang

## Overview

BiharLang is a Bhojpuri-keyword, dynamically typed interpreter. Users run a `.bh` file through the CLI or enter code in the REPL; both paths tokenize source, parse it into an AST, and evaluate it into runtime values. The evaluator also uses scoped environments for variables and closures, while the lexer and parser provide tokenization and Pratt parsing. The README documents these capabilities; the graph’s runtime connections are limited to relationships shown in the excerpts or README.

Main entry points: [`cmd/bihari/main.go`](https://github.com/coderz90/biharlang/blob/master/cmd/bihari/main.go) (CLI runner), [`repl/repl.go`](https://github.com/coderz90/biharlang/blob/master/repl/repl.go) (Interactive REPL), [`evaluator/evaluator.go`](https://github.com/coderz90/biharlang/blob/master/evaluator/evaluator.go) (Tree evaluator), [`parser/parser.go`](https://github.com/coderz90/biharlang/blob/master/parser/parser.go) (Pratt parser)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["User entry"]
  node_cli["CLI runner<br/>[main.go]"]
  node_repl["Interactive REPL<br/>[repl.go]"]
  node_source["Script source"]
end

subgraph group_front["Language front end"]
  node_lexer["Lexer<br/>[lexer.go]"]
  node_tokens["Tokens and keywords<br/>[token.go]"]
  node_parser["Pratt parser<br/>[parser.go]"]
  node_ast["Syntax tree<br/>[ast.go]"]
end

subgraph group_runtime["Interpreter runtime"]
  node_evaluator["Tree evaluator<br/>[evaluator.go]"]
  node_environment[("Scoped environment<br/>[environment.go]")]
end

subgraph group_values["Runtime values"]
  node_objects["Runtime objects<br/>[object.go]"]
end

node_user(("User"))
node_console(("Console output"))

node_user -->|"runs scripts"| node_cli
node_user -->|"enters code"| node_repl
node_cli -->|"reads file"| node_source
node_cli -->|"creates lexer"| node_lexer
node_cli -->|"creates parser"| node_parser
node_cli -->|"creates scope"| node_environment
node_cli -->|"evaluates program"| node_evaluator
node_repl -->|"tokenizes line"| node_lexer
node_repl -->|"parses line"| node_parser
node_repl -->|"retains scope"| node_environment
node_repl -->|"evaluates program"| node_evaluator
node_lexer -->|"emits tokens"| node_tokens
node_parser -->|"consumes tokens"| node_lexer
node_parser -->|"checks token types"| node_tokens
node_parser -->|"builds AST"| node_ast
node_evaluator -->|"walks AST"| node_ast
node_evaluator -->|"reads and writes"| node_environment
node_evaluator -->|"creates values"| node_objects
node_evaluator -->|"prints values"| node_console
node_cli -->|"reports errors"| node_console
node_repl -->|"displays results"| node_console

click node_cli "https://github.com/coderz90/biharlang/blob/master/cmd/bihari/main.go"
click node_repl "https://github.com/coderz90/biharlang/blob/master/repl/repl.go"
click node_lexer "https://github.com/coderz90/biharlang/blob/master/lexer/lexer.go"
click node_tokens "https://github.com/coderz90/biharlang/blob/master/token/token.go"
click node_parser "https://github.com/coderz90/biharlang/blob/master/parser/parser.go"
click node_ast "https://github.com/coderz90/biharlang/blob/master/ast/ast.go"
click node_evaluator "https://github.com/coderz90/biharlang/blob/master/evaluator/evaluator.go"
click node_environment "https://github.com/coderz90/biharlang/blob/master/evaluator/environment.go"
click node_objects "https://github.com/coderz90/biharlang/blob/master/object/object.go"

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_cli,node_repl,node_source,node_user toneBlue
class node_lexer,node_tokens,node_parser,node_ast toneAmber
class node_evaluator,node_environment toneMint
class node_objects toneRose
class node_console toneIndigo
```

## Components

### User entry

- [CLI runner](https://github.com/coderz90/biharlang/blob/master/cmd/bihari/main.go): `cmd/bihari/main.go`
- [Interactive REPL](https://github.com/coderz90/biharlang/blob/master/repl/repl.go): `repl/repl.go`
- **Script source**

### Language front end

- [Lexer](https://github.com/coderz90/biharlang/blob/master/lexer/lexer.go): `lexer/lexer.go`
- [Tokens and keywords](https://github.com/coderz90/biharlang/blob/master/token/token.go): `token/token.go`
- [Pratt parser](https://github.com/coderz90/biharlang/blob/master/parser/parser.go): `parser/parser.go`
- [Syntax tree](https://github.com/coderz90/biharlang/blob/master/ast/ast.go): `ast/ast.go`

### Interpreter runtime

- [Tree evaluator](https://github.com/coderz90/biharlang/blob/master/evaluator/evaluator.go): `evaluator/evaluator.go`
- [Scoped environment](https://github.com/coderz90/biharlang/blob/master/evaluator/environment.go): `evaluator/environment.go`

### Runtime values

- [Runtime objects](https://github.com/coderz90/biharlang/blob/master/object/object.go): `object/object.go`

### Other components

- **User**
- **Console output**

## Connections

- User → CLI runner: runs scripts (evidence: `README.md`)
- User → Interactive REPL: enters code (evidence: `README.md`)
- CLI runner → Script source: reads file (evidence: `cmd/bihari/main.go`)
- CLI runner → Lexer: creates lexer (evidence: `cmd/bihari/main.go`)
- CLI runner → Pratt parser: creates parser (evidence: `cmd/bihari/main.go`)
- CLI runner → Scoped environment: creates scope (evidence: `cmd/bihari/main.go`)
- CLI runner → Tree evaluator: evaluates program (evidence: `cmd/bihari/main.go`)
- Interactive REPL → Lexer: tokenizes line (evidence: `repl/repl.go`)
- Interactive REPL → Pratt parser: parses line (evidence: `repl/repl.go`)
- Interactive REPL → Scoped environment: retains scope (evidence: `repl/repl.go`)
- Interactive REPL → Tree evaluator: evaluates program (evidence: `repl/repl.go`)
- Lexer → Tokens and keywords: emits tokens (evidence: `lexer/lexer.go`)
- Pratt parser → Lexer: consumes tokens (evidence: `parser/parser.go`)
- Pratt parser → Tokens and keywords: checks token types (evidence: `parser/parser.go`)
- Pratt parser → Syntax tree: builds AST (evidence: `README.md`)
- Tree evaluator → Syntax tree: walks AST (evidence: `evaluator/evaluator.go`)
- Tree evaluator → Scoped environment: reads and writes (evidence: `evaluator/evaluator.go`)
- Tree evaluator → Runtime objects: creates values (evidence: `evaluator/evaluator.go`)
- Tree evaluator → Console output: prints values (evidence: `evaluator/evaluator.go`)
- CLI runner → Console output: reports errors (evidence: `cmd/bihari/main.go`)
- Interactive REPL → Console output: displays results (evidence: `repl/repl.go`)
