# macdee661/mzharima-compiler architecture

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

- Interactive diagram: https://gitdiagram.com/macdee661/mzharima-compiler
- Repository: https://github.com/macdee661/mzharima-compiler

## Overview

BMinor is a compiler for the BMinor language. Its principal workflow takes source through scanning and parsing into an AST, then resolves names, checks types, and generates assembly; the README also documents token encoding, AST printing, and a standard library for print and exponentiation. The graph preserves those product capabilities and the symbol/scope layer. Relationships follow the README and the central driver’s indexed references; some implementation details were not excerpted, so uncertain internal links are omitted.

Main entry points: [`decl.c`](https://github.com/macdee661/mzharima-compiler/blob/master/decl.c) (AST model), [`scope.c`](https://github.com/macdee661/mzharima-compiler/blob/master/scope.c) (Scope manager), [`scan/scanner.c`](https://github.com/macdee661/mzharima-compiler/blob/master/scan/scanner.c) (Scanner), [`codegen/codegen.c`](https://github.com/macdee661/mzharima-compiler/blob/master/codegen/codegen.c) (Assembly generator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_front["Front end"]
  node_scanner["Scanner<br/>[scanner.c]"]
  node_token_encoder["Token encoder<br/>[encoder.c]"]
  node_parser["Parser<br/>[parser.c]"]
  node_ast["AST model<br/>[decl.c]"]
  node_ast_printer["AST printer<br/>[printer_driver.c]"]
end

subgraph group_semantics["Semantic analysis"]
  node_resolver["Name resolver<br/>[decl.c]"]
  node_typechecker["Type checker<br/>[decl.c]"]
  node_scope["Scope manager<br/>[scope.c]"]
  node_symbols["Symbols<br/>[symbol.c]"]
  node_hash_table["Name table<br/>[hash_table.c]"]
  node_type_model["Type model<br/>[type.c]"]
end

subgraph group_runtime["Code generation"]
  node_codegen["Assembly generator<br/>[codegen.c]"]
  node_output["Assembly output"]
  node_standard_library["Standard library<br/>[library.c]"]
end

subgraph group_support["Language support"]
  node_token_model["Token definitions<br/>[tokens.h]"]
  node_statement_model["Statement model<br/>[stmt.c]"]
  node_parameter_model["Parameter model<br/>[param_list.c]"]
end

node_developer(("Compiler user"))

node_developer -->|"supplies source"| node_scanner
node_scanner -->|"emits tokens"| node_token_model
node_scanner -->|"encodes tokens"| node_token_encoder
node_parser -->|"builds AST"| node_ast
node_ast -->|"prints AST"| node_ast_printer
node_ast -->|"resolves names"| node_resolver
node_resolver -->|"looks up names"| node_scope
node_scope -->|"stores bindings"| node_hash_table
node_scope -->|"binds symbols"| node_symbols
node_ast -->|"checks types"| node_typechecker
node_typechecker -->|"compares types"| node_type_model
node_typechecker -->|"binds parameters"| node_scope
node_ast -->|"generates assembly"| node_codegen
node_codegen -->|"writes assembly"| node_output
node_codegen -->|"calls runtime functions"| node_standard_library
node_ast -->|"contains statements"| node_statement_model
node_ast -->|"uses parameters"| node_parameter_model

click node_scanner "https://github.com/macdee661/mzharima-compiler/blob/master/scan/scanner.c"
click node_token_encoder "https://github.com/macdee661/mzharima-compiler/blob/master/encode/encoder.c"
click node_parser "https://github.com/macdee661/mzharima-compiler/blob/master/parse/parser.c"
click node_ast "https://github.com/macdee661/mzharima-compiler/blob/master/decl.c"
click node_ast_printer "https://github.com/macdee661/mzharima-compiler/blob/master/print/printer_driver.c"
click node_resolver "https://github.com/macdee661/mzharima-compiler/blob/master/decl.c"
click node_typechecker "https://github.com/macdee661/mzharima-compiler/blob/master/decl.c"
click node_scope "https://github.com/macdee661/mzharima-compiler/blob/master/scope.c"
click node_symbols "https://github.com/macdee661/mzharima-compiler/blob/master/symbol.c"
click node_hash_table "https://github.com/macdee661/mzharima-compiler/blob/master/hash_table.c"
click node_type_model "https://github.com/macdee661/mzharima-compiler/blob/master/type.c"
click node_codegen "https://github.com/macdee661/mzharima-compiler/blob/master/codegen/codegen.c"
click node_standard_library "https://github.com/macdee661/mzharima-compiler/blob/master/library.c"
click node_token_model "https://github.com/macdee661/mzharima-compiler/blob/master/scan/tokens.h"
click node_statement_model "https://github.com/macdee661/mzharima-compiler/blob/master/stmt.c"
click node_parameter_model "https://github.com/macdee661/mzharima-compiler/blob/master/param_list.c"

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_scanner,node_token_encoder,node_parser,node_ast,node_ast_printer,node_developer toneBlue
class node_resolver,node_typechecker,node_scope,node_symbols,node_hash_table,node_type_model toneAmber
class node_codegen,node_output,node_standard_library toneMint
class node_token_model,node_statement_model,node_parameter_model toneRose
```

## Components

### Front end

- [Scanner](https://github.com/macdee661/mzharima-compiler/blob/master/scan/scanner.c): `scan/scanner.c`
- [Token encoder](https://github.com/macdee661/mzharima-compiler/blob/master/encode/encoder.c): `encode/encoder.c`
- [Parser](https://github.com/macdee661/mzharima-compiler/blob/master/parse/parser.c): `parse/parser.c`
- [AST model](https://github.com/macdee661/mzharima-compiler/blob/master/decl.c): `decl.c`
- [AST printer](https://github.com/macdee661/mzharima-compiler/blob/master/print/printer_driver.c): `print/printer_driver.c`

### Semantic analysis

- [Name resolver](https://github.com/macdee661/mzharima-compiler/blob/master/decl.c): `decl.c`
- [Type checker](https://github.com/macdee661/mzharima-compiler/blob/master/decl.c): `decl.c`
- [Scope manager](https://github.com/macdee661/mzharima-compiler/blob/master/scope.c): `scope.c`
- [Symbols](https://github.com/macdee661/mzharima-compiler/blob/master/symbol.c): `symbol.c`
- [Name table](https://github.com/macdee661/mzharima-compiler/blob/master/hash_table.c): `hash_table.c`
- [Type model](https://github.com/macdee661/mzharima-compiler/blob/master/type.c): `type.c`

### Code generation

- [Assembly generator](https://github.com/macdee661/mzharima-compiler/blob/master/codegen/codegen.c): `codegen/codegen.c`
- **Assembly output**
- [Standard library](https://github.com/macdee661/mzharima-compiler/blob/master/library.c): `library.c`

### Language support

- [Token definitions](https://github.com/macdee661/mzharima-compiler/blob/master/scan/tokens.h): `scan/tokens.h`
- [Statement model](https://github.com/macdee661/mzharima-compiler/blob/master/stmt.c): `stmt.c`
- [Parameter model](https://github.com/macdee661/mzharima-compiler/blob/master/param_list.c): `param_list.c`

### Other components

- **Compiler user**

## Connections

- Compiler user → Scanner: supplies source
- Scanner → Token definitions: emits tokens (evidence: `scan/scanner.c`)
- Scanner → Token encoder: encodes tokens
- Parser → AST model: builds AST
- AST model → AST printer: prints AST (evidence: `print/printer_driver.c`)
- AST model → Name resolver: resolves names (evidence: `decl.c`)
- Name resolver → Scope manager: looks up names (evidence: `decl.c`)
- Scope manager → Name table: stores bindings (evidence: `scope.c`)
- Scope manager → Symbols: binds symbols (evidence: `scope.c`)
- AST model → Type checker: checks types (evidence: `decl.c`)
- Type checker → Type model: compares types (evidence: `decl.c`)
- Type checker → Scope manager: binds parameters (evidence: `decl.c`)
- AST model → Assembly generator: generates assembly
- Assembly generator → Assembly output: writes assembly (evidence: `codegen/codegen.c`)
- Assembly generator → Standard library: calls runtime functions (evidence: `codegen/codegen.c`)
- AST model → Statement model: contains statements
- AST model → Parameter model: uses parameters
