# nihirash/bsimple-ez80-compiler architecture

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

- Interactive diagram: https://gitdiagram.com/nihirash/bsimple-ez80-compiler
- Repository: https://github.com/nihirash/bsimple-ez80-compiler

## Overview

B Simple is a typeless, B-inspired compiled language targeting eZ80 assembly. Its main workflow reads a .bs program, scans and processes it, and writes an assembly listing for the external ez80asm assembler to turn into a runnable binary. The documented `bs` tool can concatenate sources and run the compiler and assembler as a single build workflow. Libraries extend programs with standard routines, file access, printing, and arcade features. The compiler excerpts support the front-end and output relationships shown; unsampled library wiring is not inferred.

Main entry points: [`compiler/src/main.c`](https://github.com/nihirash/bsimple-ez80-compiler/blob/main/compiler/src/main.c) (Compiler entry), [`compiler/src/scanner.c`](https://github.com/nihirash/bsimple-ez80-compiler/blob/main/compiler/src/scanner.c) (Statement processing), [`compiler/src/writer.c`](https://github.com/nihirash/bsimple-ez80-compiler/blob/main/compiler/src/writer.c) (Assembly writer), [`compiler/src/reader.c`](https://github.com/nihirash/bsimple-ez80-compiler/blob/main/compiler/src/reader.c) (Source reader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_compiler["Compiler"]
  node_compiler_main["Compiler entry<br/>[main.c]"]
  node_reader["Source reader<br/>[reader.c]"]
  node_tokenizer["Tokenization<br/>[token.c]"]
  node_scanner["Statement processing<br/>[scanner.c]"]
  node_symbols["Symbol table<br/>[symbols.c]"]
  node_generator["Assembly generation<br/>[generator.c]"]
  node_writer["Assembly writer<br/>[writer.c]"]
  node_errors["Error reporting<br/>[errors.c]"]
end

subgraph group_libraries["Libraries"]
  node_stdlib["Standard library"]
  node_startup["Runtime startup"]
  node_moslet["MOS runtime"]
  node_files["File routines"]
  node_printer["Printer routines"]
  node_arcade["Arcade features"]
end

subgraph group_tools["Build tools"]
  node_bs_tool["Source build tool<br/>[bs.bs]"]
end

subgraph group_outputs["Program outputs"]
  node_assembly["Assembly listing"]
  node_binary["Runnable binary"]
end

node_user(("Programmer"))
node_assembler["ez80asm"]

node_user -->|"builds with"| node_bs_tool
node_user -->|"compiles with"| node_compiler_main
node_bs_tool -.->|"invokes"| node_compiler_main
node_bs_tool -.->|"invokes"| node_assembler
node_compiler_main -->|"initializes input"| node_reader
node_compiler_main -->|"initializes output"| node_writer
node_compiler_main -->|"processes program"| node_scanner
node_tokenizer -->|"reads characters"| node_reader
node_scanner -->|"requests tokens"| node_tokenizer
node_scanner -->|"looks up names"| node_symbols
node_scanner -->|"emits operations"| node_generator
node_scanner -->|"includes sources"| node_reader
node_generator -->|"writes assembly"| node_writer
node_compiler_main -->|"closes output"| node_writer
node_errors -->|"reports location"| node_reader
node_errors -->|"closes output"| node_writer
node_writer -->|"produces"| node_assembly
node_assembly -->|"assembled by"| node_assembler
node_assembler -->|"produces"| node_binary

click node_bs_tool "https://github.com/nihirash/bsimple-ez80-compiler/blob/main/native-tools/bs.bs"
click node_compiler_main "https://github.com/nihirash/bsimple-ez80-compiler/blob/main/compiler/src/main.c"
click node_reader "https://github.com/nihirash/bsimple-ez80-compiler/blob/main/compiler/src/reader.c"
click node_tokenizer "https://github.com/nihirash/bsimple-ez80-compiler/blob/main/compiler/src/token.c"
click node_scanner "https://github.com/nihirash/bsimple-ez80-compiler/blob/main/compiler/src/scanner.c"
click node_symbols "https://github.com/nihirash/bsimple-ez80-compiler/blob/main/compiler/src/symbols.c"
click node_generator "https://github.com/nihirash/bsimple-ez80-compiler/blob/main/compiler/src/generator.c"
click node_writer "https://github.com/nihirash/bsimple-ez80-compiler/blob/main/compiler/src/writer.c"
click node_errors "https://github.com/nihirash/bsimple-ez80-compiler/blob/main/compiler/src/errors.c"
click node_stdlib "https://github.com/nihirash/bsimple-ez80-compiler/tree/main/lib/stdlib"
click node_startup "https://github.com/nihirash/bsimple-ez80-compiler/tree/main/lib/startup"
click node_moslet "https://github.com/nihirash/bsimple-ez80-compiler/tree/main/lib/moslet"
click node_files "https://github.com/nihirash/bsimple-ez80-compiler/tree/main/lib/files"
click node_printer "https://github.com/nihirash/bsimple-ez80-compiler/tree/main/lib/printer"
click node_arcade "https://github.com/nihirash/bsimple-ez80-compiler/tree/main/lib/arcade"

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_compiler_main,node_reader,node_tokenizer,node_scanner,node_symbols,node_generator,node_writer,node_errors toneBlue
class node_stdlib,node_startup,node_moslet,node_files,node_printer,node_arcade toneAmber
class node_bs_tool toneMint
class node_assembly,node_binary toneRose
class node_user,node_assembler toneIndigo
```

## Components

### Compiler

- [Compiler entry](https://github.com/nihirash/bsimple-ez80-compiler/blob/main/compiler/src/main.c): `compiler/src/main.c`
- [Source reader](https://github.com/nihirash/bsimple-ez80-compiler/blob/main/compiler/src/reader.c): `compiler/src/reader.c`
- [Tokenization](https://github.com/nihirash/bsimple-ez80-compiler/blob/main/compiler/src/token.c): `compiler/src/token.c`
- [Statement processing](https://github.com/nihirash/bsimple-ez80-compiler/blob/main/compiler/src/scanner.c): `compiler/src/scanner.c`
- [Symbol table](https://github.com/nihirash/bsimple-ez80-compiler/blob/main/compiler/src/symbols.c): `compiler/src/symbols.c`
- [Assembly generation](https://github.com/nihirash/bsimple-ez80-compiler/blob/main/compiler/src/generator.c): `compiler/src/generator.c`
- [Assembly writer](https://github.com/nihirash/bsimple-ez80-compiler/blob/main/compiler/src/writer.c): `compiler/src/writer.c`
- [Error reporting](https://github.com/nihirash/bsimple-ez80-compiler/blob/main/compiler/src/errors.c): `compiler/src/errors.c`

### Libraries

- [Standard library](https://github.com/nihirash/bsimple-ez80-compiler/tree/main/lib/stdlib): `lib/stdlib`
- [Runtime startup](https://github.com/nihirash/bsimple-ez80-compiler/tree/main/lib/startup): `lib/startup`
- [MOS runtime](https://github.com/nihirash/bsimple-ez80-compiler/tree/main/lib/moslet): `lib/moslet`
- [File routines](https://github.com/nihirash/bsimple-ez80-compiler/tree/main/lib/files): `lib/files`
- [Printer routines](https://github.com/nihirash/bsimple-ez80-compiler/tree/main/lib/printer): `lib/printer`
- [Arcade features](https://github.com/nihirash/bsimple-ez80-compiler/tree/main/lib/arcade): `lib/arcade`

### Build tools

- [Source build tool](https://github.com/nihirash/bsimple-ez80-compiler/blob/main/native-tools/bs.bs): `native-tools/bs.bs`

### Program outputs

- **Assembly listing**
- **Runnable binary**

### Other components

- **Programmer**
- **ez80asm**

## Connections

- Programmer → Source build tool: builds with
- Programmer → Compiler entry: compiles with
- Source build tool → Compiler entry: invokes
- Source build tool → ez80asm: invokes
- Compiler entry → Source reader: initializes input
- Compiler entry → Assembly writer: initializes output
- Compiler entry → Statement processing: processes program
- Tokenization → Source reader: reads characters
- Statement processing → Tokenization: requests tokens
- Statement processing → Symbol table: looks up names
- Statement processing → Assembly generation: emits operations
- Statement processing → Source reader: includes sources
- Assembly generation → Assembly writer: writes assembly
- Compiler entry → Assembly writer: closes output
- Error reporting → Source reader: reports location
- Error reporting → Assembly writer: closes output
- Assembly writer → Assembly listing: produces
- Assembly listing → ez80asm: assembled by
- ez80asm → Runnable binary: produces
