# mica56/mini-compiler architecture

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

- Interactive diagram: https://gitdiagram.com/mica56/mini-compiler
- Repository: https://github.com/mica56/mini-compiler

## Overview

MUL is a mini-compiler: a user supplies a MUL source file to the C lexical analyzer, which writes the token/symbol-table file; the Java parser reads that file and emits a flattened syntax tree. The parser builds its tree using the shared token and tree-node models. The repository also includes two alternate lexer examples under base_templates; their relationship to the documented runtime is not established. Connections for the main workflow are supported by the README and excerpts; template internals are represented without inferred links.

Main entry points: [`MulParser.java`](https://github.com/mica56/mini-compiler/blob/main/MulParser.java) (MUL parser), [`lexical.c`](https://github.com/mica56/mini-compiler/blob/main/lexical.c) (MUL lexer), [`TreeNode.java`](https://github.com/mica56/mini-compiler/blob/main/TreeNode.java) (Tree nodes), [`file.mul`](https://github.com/mica56/mini-compiler/blob/main/file.mul) (MUL source)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_lexing["Lexical analysis"]
  node_lexer["MUL lexer<br/>[lexical.c]"]
  node_symbols["Token file"]
end

subgraph group_parsing["Syntax analysis"]
  node_parser["MUL parser<br/>[MulParser.java]"]
  node_syntax_tree["Flattened syntax tree"]
end

subgraph group_models["Parser models"]
  node_token_model["Token types<br/>[Token.java]"]
  node_tree_model["Tree nodes<br/>[TreeNode.java]"]
end

subgraph group_templates["Lexer templates"]
  node_lexanal_template["Lexer example<br/>[lexanal.c]"]
  node_lexic_template["Generic lexer<br/>[lexic.c]"]
end

node_user(("Developer"))
node_source["MUL source<br/>[file.mul]"]

node_user -->|"provides"| node_source
node_source -->|"lexes"| node_lexer
node_lexer -->|"writes tokens"| node_symbols
node_symbols -->|"supplies tokens"| node_parser
node_parser -->|"writes tree"| node_syntax_tree
node_parser -->|"uses types"| node_token_model
node_parser -->|"builds nodes"| node_tree_model
node_tree_model -->|"maps operators"| node_token_model

click node_source "https://github.com/mica56/mini-compiler/blob/main/file.mul"
click node_lexer "https://github.com/mica56/mini-compiler/blob/main/lexical.c"
click node_parser "https://github.com/mica56/mini-compiler/blob/main/MulParser.java"
click node_token_model "https://github.com/mica56/mini-compiler/blob/main/Token.java"
click node_tree_model "https://github.com/mica56/mini-compiler/blob/main/TreeNode.java"
click node_lexanal_template "https://github.com/mica56/mini-compiler/blob/main/base_templates/lexanal.c"
click node_lexic_template "https://github.com/mica56/mini-compiler/blob/main/base_templates/lexic.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_lexer,node_symbols toneBlue
class node_parser,node_syntax_tree toneAmber
class node_token_model,node_tree_model toneMint
class node_lexanal_template,node_lexic_template toneRose
class node_user toneIndigo
class node_source toneTeal
```

## Components

### Lexical analysis

- [MUL lexer](https://github.com/mica56/mini-compiler/blob/main/lexical.c): `lexical.c`
- **Token file**

### Syntax analysis

- [MUL parser](https://github.com/mica56/mini-compiler/blob/main/MulParser.java): `MulParser.java`
- **Flattened syntax tree**

### Parser models

- [Token types](https://github.com/mica56/mini-compiler/blob/main/Token.java): `Token.java`
- [Tree nodes](https://github.com/mica56/mini-compiler/blob/main/TreeNode.java): `TreeNode.java`

### Lexer templates

- [Lexer example](https://github.com/mica56/mini-compiler/blob/main/base_templates/lexanal.c): `base_templates/lexanal.c`
- [Generic lexer](https://github.com/mica56/mini-compiler/blob/main/base_templates/lexic.c): `base_templates/lexic.c`

### Other components

- **Developer**
- [MUL source](https://github.com/mica56/mini-compiler/blob/main/file.mul): `file.mul`

## Connections

- Developer → MUL source: provides (evidence: `README.md`)
- MUL source → MUL lexer: lexes (evidence: `README.md`)
- MUL lexer → Token file: writes tokens (evidence: `README.md`)
- Token file → MUL parser: supplies tokens (evidence: `README.md`)
- MUL parser → Flattened syntax tree: writes tree (evidence: `README.md`)
- MUL parser → Token types: uses types (evidence: `MulParser.java`)
- MUL parser → Tree nodes: builds nodes (evidence: `MulParser.java`)
- Tree nodes → Token types: maps operators (evidence: `TreeNode.java`)
