# n230881/minic-compiler architecture

> Architecture diagram of the GitHub repository n230881/minic-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/n230881/minic-compiler
- Repository: https://github.com/n230881/minic-compiler

## Overview

MiniC is a small C-like language compiler with a Streamlit front end. A user submits source text; the interface writes it to a temporary file and launches the compiler, which lexes and parses it, checks semantics, generates and optimizes intermediate code, reports a control-flow graph, and executes the program when semantic checks pass. The UI presents each report and program output. The sampled source establishes the CLI’s stage calls and the optimizer/VM’s shared operator helpers; the tree and interface caption support the broader language capabilities.

Main entry points: [`main.c`](https://github.com/n230881/minic-compiler/blob/main/main.c) (Compiler CLI), [`parser.c`](https://github.com/n230881/minic-compiler/blob/main/parser.c) (Parser), [`codegen.c`](https://github.com/n230881/minic-compiler/blob/main/codegen.c) (IR generator), [`optimizer.c`](https://github.com/n230881/minic-compiler/blob/main/optimizer.c) (IR optimizer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Web interface"]
  node_ui["Streamlit interface<br/>[app.py]"]
end

subgraph group_frontend["Language front end"]
  node_cli["Compiler CLI<br/>[main.c]"]
  node_lexer["Lexer<br/>[lexer.c]"]
  node_tokens["Token list<br/>[token.h]"]
  node_parser["Parser<br/>[parser.c]"]
  node_ast["AST utilities<br/>[ast.c]"]
  node_tree["AST<br/>[ast.h]"]
  node_semantic["Semantic checks<br/>[semantic.c]"]
end

subgraph group_ir["IR and analysis"]
  node_codegen["IR generator<br/>[codegen.c]"]
  node_program["IR program<br/>[codegen.h]"]
  node_optimizer["IR optimizer<br/>[optimizer.c]"]
  node_cfg["CFG reporter<br/>[cfg.c]"]
end

subgraph group_runtime["Execution"]
  node_vm["Virtual machine<br/>[vm.c]"]
  node_ops["Operator helpers<br/>[ops.c]"]
end

node_user(("Program author"))

node_user -->|"submits source"| node_ui
node_ui -->|"runs compiler"| node_cli
node_cli -->|"lexes source"| node_lexer
node_lexer -->|"produces tokens"| node_tokens
node_cli -->|"prints tokens"| node_lexer
node_cli -->|"parses tokens"| node_parser
node_parser -->|"reads tokens"| node_tokens
node_parser -->|"builds nodes"| node_ast
node_ast -->|"creates AST"| node_tree
node_parser -->|"returns AST"| node_tree
node_cli -->|"prints AST"| node_ast
node_cli -->|"checks AST"| node_semantic
node_semantic -->|"reads AST"| node_tree
node_cli -->|"generates IR"| node_codegen
node_codegen -->|"reads AST"| node_tree
node_codegen -->|"emits IR"| node_program
node_cli -->|"prints IR"| node_codegen
node_cli -->|"optimizes IR"| node_optimizer
node_optimizer -->|"rewrites IR"| node_program
node_cli -->|"prints optimized IR"| node_optimizer
node_cli -->|"reports CFG"| node_cfg
node_cfg -->|"reads IR"| node_program
node_cli -->|"runs IR"| node_vm
node_vm -->|"reads IR"| node_program
node_vm -->|"evaluates operators"| node_ops
node_optimizer -->|"folds operators"| node_ops
node_ui -->|"reads reports"| node_cli

click node_ui "https://github.com/n230881/minic-compiler/blob/main/app.py"
click node_cli "https://github.com/n230881/minic-compiler/blob/main/main.c"
click node_lexer "https://github.com/n230881/minic-compiler/blob/main/lexer.c"
click node_tokens "https://github.com/n230881/minic-compiler/blob/main/token.h"
click node_parser "https://github.com/n230881/minic-compiler/blob/main/parser.c"
click node_ast "https://github.com/n230881/minic-compiler/blob/main/ast.c"
click node_tree "https://github.com/n230881/minic-compiler/blob/main/ast.h"
click node_semantic "https://github.com/n230881/minic-compiler/blob/main/semantic.c"
click node_codegen "https://github.com/n230881/minic-compiler/blob/main/codegen.c"
click node_program "https://github.com/n230881/minic-compiler/blob/main/codegen.h"
click node_optimizer "https://github.com/n230881/minic-compiler/blob/main/optimizer.c"
click node_cfg "https://github.com/n230881/minic-compiler/blob/main/cfg.c"
click node_vm "https://github.com/n230881/minic-compiler/blob/main/vm.c"
click node_ops "https://github.com/n230881/minic-compiler/blob/main/ops.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_ui toneBlue
class node_cli,node_lexer,node_tokens,node_parser,node_ast,node_tree,node_semantic toneAmber
class node_codegen,node_program,node_optimizer,node_cfg toneMint
class node_vm,node_ops toneRose
class node_user toneIndigo
```

## Components

### Web interface

- [Streamlit interface](https://github.com/n230881/minic-compiler/blob/main/app.py): `app.py`

### Language front end

- [Compiler CLI](https://github.com/n230881/minic-compiler/blob/main/main.c): `main.c`
- [Lexer](https://github.com/n230881/minic-compiler/blob/main/lexer.c): `lexer.c`
- [Token list](https://github.com/n230881/minic-compiler/blob/main/token.h): `token.h`
- [Parser](https://github.com/n230881/minic-compiler/blob/main/parser.c): `parser.c`
- [AST utilities](https://github.com/n230881/minic-compiler/blob/main/ast.c): `ast.c`
- [AST](https://github.com/n230881/minic-compiler/blob/main/ast.h): `ast.h`
- [Semantic checks](https://github.com/n230881/minic-compiler/blob/main/semantic.c): `semantic.c`

### IR and analysis

- [IR generator](https://github.com/n230881/minic-compiler/blob/main/codegen.c): `codegen.c`
- [IR program](https://github.com/n230881/minic-compiler/blob/main/codegen.h): `codegen.h`
- [IR optimizer](https://github.com/n230881/minic-compiler/blob/main/optimizer.c): `optimizer.c`
- [CFG reporter](https://github.com/n230881/minic-compiler/blob/main/cfg.c): `cfg.c`

### Execution

- [Virtual machine](https://github.com/n230881/minic-compiler/blob/main/vm.c): `vm.c`
- [Operator helpers](https://github.com/n230881/minic-compiler/blob/main/ops.c): `ops.c`

### Other components

- **Program author**

## Connections

- Program author → Streamlit interface: submits source
- Streamlit interface → Compiler CLI: runs compiler
- Compiler CLI → Lexer: lexes source
- Lexer → Token list: produces tokens
- Compiler CLI → Lexer: prints tokens
- Compiler CLI → Parser: parses tokens
- Parser → Token list: reads tokens
- Parser → AST utilities: builds nodes
- AST utilities → AST: creates AST
- Parser → AST: returns AST
- Compiler CLI → AST utilities: prints AST
- Compiler CLI → Semantic checks: checks AST
- Semantic checks → AST: reads AST
- Compiler CLI → IR generator: generates IR
- IR generator → AST: reads AST
- IR generator → IR program: emits IR
- Compiler CLI → IR generator: prints IR
- Compiler CLI → IR optimizer: optimizes IR
- IR optimizer → IR program: rewrites IR
- Compiler CLI → IR optimizer: prints optimized IR
- Compiler CLI → CFG reporter: reports CFG
- CFG reporter → IR program: reads IR
- Compiler CLI → Virtual machine: runs IR
- Virtual machine → IR program: reads IR
- Virtual machine → Operator helpers: evaluates operators
- IR optimizer → Operator helpers: folds operators
- Streamlit interface → Compiler CLI: reads reports
