# cyiuhim/goose architecture

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

- Interactive diagram: https://gitdiagram.com/cyiuhim/goose
- Repository: https://github.com/cyiuhim/goose

## Overview

Goose is a C++20 compiler for a small language. Its documented workflow takes a source file through DFA lexing, LL(1) parsing, parse-tree-to-AST transformation, semantic analysis, and LLVM IR generation. The graph retains the documented type-checking and visitor-based backend capabilities, plus the lexer’s DFA and keyword trie and the parser’s grammar. Some implementation details were not sampled; uncertain internal links are omitted or marked unverified.

Main entry points: [`src/main.cpp`](https://github.com/cyiuhim/goose/blob/main/src/main.cpp) (Compiler entry), [`src/semantic_analyzer/semantic_analyzer.cpp`](https://github.com/cyiuhim/goose/blob/main/src/semantic_analyzer/semantic_analyzer.cpp) (Semantic analysis), [`src/lexer/dfa.cpp`](https://github.com/cyiuhim/goose/blob/main/src/lexer/dfa.cpp) (DFA lexer), [`src/parser/parser.cpp`](https://github.com/cyiuhim/goose/blob/main/src/parser/parser.cpp) (LL(1) parser)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_driver["Compiler entry<br/>[main.cpp]"]
  node_lexer["DFA lexer<br/>[dfa.cpp]"]
  node_transitions["DFA transitions<br/>[state_list.h]"]
  node_state["Lexer state<br/>[state.cpp]"]
  node_keywords["Keyword trie<br/>[trie_node.cpp]"]
  node_tokens["Token stream<br/>[symbol.h]"]
  node_grammar["Language grammar<br/>[grammar.h]"]
  node_parser["LL&#40;1&#41; parser<br/>[parser.cpp]"]
  node_parse_tree["Concrete parse tree<br/>[parser_node.h]"]
end

subgraph group_ast["AST"]
  node_transformer["AST transformer"]
  node_ast_nodes["AST nodes"]
  node_ast_printer["AST printer<br/>[ast_printer.cpp]"]
end

subgraph group_analysis["Analysis"]
  node_semantic["Semantic analysis"]
  node_type_checker["Type checker"]
  node_types["Type model<br/>[type.h]"]
  node_symbols["Symbol model<br/>[symbol.h]"]
  node_visitor["AST visitor<br/>[visitor.h]"]
end

subgraph group_backend["Backend"]
  node_codegen["LLVM lowering"]
  node_llvm["LLVM IR"]
end

node_user(("Compiler user"))
node_source["Goose source"]
node_native["Native binary"]

node_user -->|"runs"| node_driver
node_source -->|"provides input"| node_driver
node_driver -->|"starts lexing"| node_lexer
node_lexer -->|"uses transitions"| node_transitions
node_transitions -->|"configures states"| node_state
node_lexer -->|"checks keywords"| node_keywords
node_lexer -->|"produces tokens"| node_tokens
node_driver -->|"starts parsing"| node_parser
node_tokens -->|"feeds tokens"| node_parser
node_grammar -->|"defines grammar"| node_parser
node_parser -->|"builds tree"| node_parse_tree
node_driver -->|"starts transformation"| node_transformer
node_parse_tree -->|"feeds tree"| node_transformer
node_transformer -->|"constructs AST"| node_ast_nodes
node_ast_nodes -.->|"prints AST"| node_ast_printer
node_driver -->|"starts analysis"| node_semantic
node_ast_nodes -->|"provides AST"| node_semantic
node_semantic -.->|"checks types"| node_type_checker
node_semantic -.->|"uses types"| node_types
node_semantic -.->|"uses symbols"| node_symbols
node_type_checker -.->|"visits AST"| node_visitor
node_semantic -->|"lowers program"| node_codegen
node_codegen -->|"generates IR"| node_llvm
node_llvm -->|"generates binary"| node_native

click node_driver "https://github.com/cyiuhim/goose/blob/main/src/main.cpp"
click node_lexer "https://github.com/cyiuhim/goose/blob/main/src/lexer/dfa.cpp"
click node_transitions "https://github.com/cyiuhim/goose/blob/main/include/lexer/state_list.h"
click node_state "https://github.com/cyiuhim/goose/blob/main/src/lexer/state.cpp"
click node_keywords "https://github.com/cyiuhim/goose/blob/main/src/lexer/trie_node.cpp"
click node_tokens "https://github.com/cyiuhim/goose/blob/main/include/symbol.h"
click node_grammar "https://github.com/cyiuhim/goose/blob/main/include/parser/grammar.h"
click node_parser "https://github.com/cyiuhim/goose/blob/main/src/parser/parser.cpp"
click node_parse_tree "https://github.com/cyiuhim/goose/blob/main/include/parser/parser_node.h"
click node_transformer "https://github.com/cyiuhim/goose/blob/main/src/tree_transformer/tree_transformer.cpp"
click node_ast_nodes "https://github.com/cyiuhim/goose/tree/main/src/ast_nodes"
click node_ast_printer "https://github.com/cyiuhim/goose/blob/main/src/tree_transformer/ast_printer.cpp"
click node_semantic "https://github.com/cyiuhim/goose/blob/main/src/semantic_analyzer/semantic_analyzer.cpp"
click node_type_checker "https://github.com/cyiuhim/goose/blob/main/src/semantic_analyzer/type_check_visitor.cpp"
click node_types "https://github.com/cyiuhim/goose/blob/main/include/type.h"
click node_symbols "https://github.com/cyiuhim/goose/blob/main/include/symbol.h"
click node_visitor "https://github.com/cyiuhim/goose/blob/main/include/visitor.h"
click node_codegen "https://github.com/cyiuhim/goose/blob/main/src/semantic_analyzer/semantic_analyzer.cpp"

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_driver,node_lexer,node_transitions,node_state,node_keywords,node_tokens,node_grammar,node_parser,node_parse_tree,node_user toneBlue
class node_transformer,node_ast_nodes,node_ast_printer toneAmber
class node_semantic,node_type_checker,node_types,node_symbols,node_visitor toneMint
class node_codegen,node_llvm toneRose
class node_source,node_native toneIndigo
```

## Components

### Frontend

- [Compiler entry](https://github.com/cyiuhim/goose/blob/main/src/main.cpp): `src/main.cpp`
- [DFA lexer](https://github.com/cyiuhim/goose/blob/main/src/lexer/dfa.cpp): `src/lexer/dfa.cpp`
- [DFA transitions](https://github.com/cyiuhim/goose/blob/main/include/lexer/state_list.h): `include/lexer/state_list.h`
- [Lexer state](https://github.com/cyiuhim/goose/blob/main/src/lexer/state.cpp): `src/lexer/state.cpp`
- [Keyword trie](https://github.com/cyiuhim/goose/blob/main/src/lexer/trie_node.cpp): `src/lexer/trie_node.cpp`
- [Token stream](https://github.com/cyiuhim/goose/blob/main/include/symbol.h): `include/symbol.h`
- [Language grammar](https://github.com/cyiuhim/goose/blob/main/include/parser/grammar.h): `include/parser/grammar.h`
- [LL(1) parser](https://github.com/cyiuhim/goose/blob/main/src/parser/parser.cpp): `src/parser/parser.cpp`
- [Concrete parse tree](https://github.com/cyiuhim/goose/blob/main/include/parser/parser_node.h): `include/parser/parser_node.h`

### AST

- [AST transformer](https://github.com/cyiuhim/goose/blob/main/src/tree_transformer/tree_transformer.cpp): `src/tree_transformer/tree_transformer.cpp`
- [AST nodes](https://github.com/cyiuhim/goose/tree/main/src/ast_nodes): `src/ast_nodes`
- [AST printer](https://github.com/cyiuhim/goose/blob/main/src/tree_transformer/ast_printer.cpp): `src/tree_transformer/ast_printer.cpp`

### Analysis

- [Semantic analysis](https://github.com/cyiuhim/goose/blob/main/src/semantic_analyzer/semantic_analyzer.cpp): `src/semantic_analyzer/semantic_analyzer.cpp`
- [Type checker](https://github.com/cyiuhim/goose/blob/main/src/semantic_analyzer/type_check_visitor.cpp): `src/semantic_analyzer/type_check_visitor.cpp`
- [Type model](https://github.com/cyiuhim/goose/blob/main/include/type.h): `include/type.h`
- [Symbol model](https://github.com/cyiuhim/goose/blob/main/include/symbol.h): `include/symbol.h`
- [AST visitor](https://github.com/cyiuhim/goose/blob/main/include/visitor.h): `include/visitor.h`

### Backend

- [LLVM lowering](https://github.com/cyiuhim/goose/blob/main/src/semantic_analyzer/semantic_analyzer.cpp): `src/semantic_analyzer/semantic_analyzer.cpp`
- **LLVM IR**

### Other components

- **Compiler user**
- **Goose source**
- **Native binary**

## Connections

- Compiler user → Compiler entry: runs (evidence: `README.md`)
- Goose source → Compiler entry: provides input (evidence: `README.md`)
- Compiler entry → DFA lexer: starts lexing (evidence: `README.md`)
- DFA lexer → DFA transitions: uses transitions (evidence: `src/lexer/dfa.cpp`)
- DFA transitions → Lexer state: configures states (evidence: `include/lexer/state_list.h`)
- DFA lexer → Keyword trie: checks keywords (evidence: `src/lexer/dfa.cpp`)
- DFA lexer → Token stream: produces tokens (evidence: `src/lexer/dfa.cpp`)
- Compiler entry → LL(1) parser: starts parsing (evidence: `README.md`)
- Token stream → LL(1) parser: feeds tokens (evidence: `README.md`)
- Language grammar → LL(1) parser: defines grammar (evidence: `README.md`)
- LL(1) parser → Concrete parse tree: builds tree (evidence: `README.md`)
- Compiler entry → AST transformer: starts transformation (evidence: `README.md`)
- Concrete parse tree → AST transformer: feeds tree (evidence: `README.md`)
- AST transformer → AST nodes: constructs AST (evidence: `src/tree_transformer/tree_transformer.cpp`)
- AST nodes → AST printer: prints AST
- Compiler entry → Semantic analysis: starts analysis (evidence: `README.md`)
- AST nodes → Semantic analysis: provides AST (evidence: `README.md`)
- Semantic analysis → Type checker: checks types
- Semantic analysis → Type model: uses types
- Semantic analysis → Symbol model: uses symbols
- Type checker → AST visitor: visits AST
- Semantic analysis → LLVM lowering: lowers program (evidence: `README.md`)
- LLVM lowering → LLVM IR: generates IR (evidence: `README.md`)
- LLVM IR → Native binary: generates binary (evidence: `README.md`)
