# migikun474/compiler-design architecture

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

## Overview

This is a phased C-like compiler project. The present user workflow is to provide source text to either the standalone lexer or the parser, which scans and parses directly, resolves identifier categories with scoped symbols, then reports tokens, an AST and symbols—or diagnostics on failure. Shared token vocabulary keeps lexical classifications aligned. The README describes three-address-code and MIPS stages, but marks both as not started, so they are shown as planned rather than wired into the implemented workflow. Parser relationships reflect the excerpts; unsampled phase internals are represented only where documented.

Main entry points: [`phase2-parser/src/main.cpp`](https://github.com/migikun474/compiler-design/blob/main/phase2-parser/src/main.cpp) (Parser entry), [`phase1-lexer/src/lexer.l`](https://github.com/migikun474/compiler-design/blob/main/phase1-lexer/src/lexer.l) (Flex lexer), [`phase2-parser/src/scanner.l`](https://github.com/migikun474/compiler-design/blob/main/phase2-parser/src/scanner.l) (Parser scanner), [`phase2-parser/src/parser.y`](https://github.com/migikun474/compiler-design/blob/main/phase2-parser/src/parser.y) (Grammar and actions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_lex["Lexical analysis"]
  node_lexer["Flex lexer<br/>[lexer.l]"]
  node_lex_tokens["Token table<br/>[token.h]"]
  node_lex_errors["Lexical diagnostics<br/>[diagnostics.h]"]
end

subgraph group_parse["Syntax analysis"]
  node_parser_main["Parser entry<br/>[main.cpp]"]
  node_scanner["Parser scanner<br/>[scanner.l]"]
  node_token_adapter["Bison token adapter"]
  node_grammar["Grammar and actions<br/>[parser.y]"]
  node_parser_state[("Scopes and symbols<br/>[common.cpp]")]
  node_ast["AST construction<br/>[ast.cpp]"]
  node_parse_results["Tokens AST symbols<br/>[main.cpp]"]
  node_parse_diagnostics["Syntax diagnostics<br/>[common.cpp]"]
end

subgraph group_shared["Shared vocabulary"]
  node_vocabulary["Token vocabulary<br/>[token_type.cpp]"]
end

subgraph group_future["Planned stages"]
  node_ir["Three-address code"]
  node_mips["MIPS generation"]
end

node_developer(("Source author"))

node_developer -->|"provides source"| node_lexer
node_lexer -->|"classifies with"| node_vocabulary
node_lexer -->|"emits tokens"| node_lex_tokens
node_lexer -->|"records errors"| node_lex_errors
node_developer -->|"provides source"| node_parser_main
node_parser_main -->|"starts scanning"| node_scanner
node_scanner -->|"classifies with"| node_vocabulary
node_scanner -->|"maps token types"| node_token_adapter
node_scanner -->|"supplies tokens"| node_grammar
node_grammar -->|"resolves identifiers"| node_parser_state
node_grammar -->|"builds syntax tree"| node_ast
node_grammar -->|"records errors"| node_parse_diagnostics
node_parser_main -->|"prints reports"| node_parse_results
node_parser_main -->|"prints tree"| node_ast
node_parser_main -->|"prints symbols"| node_parser_state

click node_lexer "https://github.com/migikun474/compiler-design/blob/main/phase1-lexer/src/lexer.l"
click node_lex_tokens "https://github.com/migikun474/compiler-design/blob/main/phase1-lexer/include/token.h"
click node_lex_errors "https://github.com/migikun474/compiler-design/blob/main/phase1-lexer/include/diagnostics.h"
click node_parser_main "https://github.com/migikun474/compiler-design/blob/main/phase2-parser/src/main.cpp"
click node_scanner "https://github.com/migikun474/compiler-design/blob/main/phase2-parser/src/scanner.l"
click node_token_adapter "https://github.com/migikun474/compiler-design/blob/main/phase2-parser/src/token_converter.cpp"
click node_grammar "https://github.com/migikun474/compiler-design/blob/main/phase2-parser/src/parser.y"
click node_parser_state "https://github.com/migikun474/compiler-design/blob/main/phase2-parser/src/common.cpp"
click node_ast "https://github.com/migikun474/compiler-design/blob/main/phase2-parser/src/ast.cpp"
click node_parse_results "https://github.com/migikun474/compiler-design/blob/main/phase2-parser/src/main.cpp"
click node_parse_diagnostics "https://github.com/migikun474/compiler-design/blob/main/phase2-parser/src/common.cpp"
click node_vocabulary "https://github.com/migikun474/compiler-design/blob/main/shared/src/token_type.cpp"
click node_ir "https://github.com/migikun474/compiler-design/tree/main/phase3-ir"
click node_mips "https://github.com/migikun474/compiler-design/tree/main/phase4-codegen"

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_lex_tokens,node_lex_errors toneBlue
class node_parser_main,node_scanner,node_token_adapter,node_grammar,node_parser_state,node_ast,node_parse_results,node_parse_diagnostics toneAmber
class node_vocabulary toneMint
class node_ir,node_mips toneRose
class node_developer toneIndigo
```

## Components

### Lexical analysis

- [Flex lexer](https://github.com/migikun474/compiler-design/blob/main/phase1-lexer/src/lexer.l): `phase1-lexer/src/lexer.l`
- [Token table](https://github.com/migikun474/compiler-design/blob/main/phase1-lexer/include/token.h): `phase1-lexer/include/token.h`
- [Lexical diagnostics](https://github.com/migikun474/compiler-design/blob/main/phase1-lexer/include/diagnostics.h): `phase1-lexer/include/diagnostics.h`

### Syntax analysis

- [Parser entry](https://github.com/migikun474/compiler-design/blob/main/phase2-parser/src/main.cpp): `phase2-parser/src/main.cpp`
- [Parser scanner](https://github.com/migikun474/compiler-design/blob/main/phase2-parser/src/scanner.l): `phase2-parser/src/scanner.l`
- [Bison token adapter](https://github.com/migikun474/compiler-design/blob/main/phase2-parser/src/token_converter.cpp): `phase2-parser/src/token_converter.cpp`
- [Grammar and actions](https://github.com/migikun474/compiler-design/blob/main/phase2-parser/src/parser.y): `phase2-parser/src/parser.y`
- [Scopes and symbols](https://github.com/migikun474/compiler-design/blob/main/phase2-parser/src/common.cpp): `phase2-parser/src/common.cpp`
- [AST construction](https://github.com/migikun474/compiler-design/blob/main/phase2-parser/src/ast.cpp): `phase2-parser/src/ast.cpp`
- [Tokens AST symbols](https://github.com/migikun474/compiler-design/blob/main/phase2-parser/src/main.cpp): `phase2-parser/src/main.cpp`
- [Syntax diagnostics](https://github.com/migikun474/compiler-design/blob/main/phase2-parser/src/common.cpp): `phase2-parser/src/common.cpp`

### Shared vocabulary

- [Token vocabulary](https://github.com/migikun474/compiler-design/blob/main/shared/src/token_type.cpp): `shared/src/token_type.cpp`

### Planned stages

- [Three-address code](https://github.com/migikun474/compiler-design/tree/main/phase3-ir): `phase3-ir`
- [MIPS generation](https://github.com/migikun474/compiler-design/tree/main/phase4-codegen): `phase4-codegen`

### Other components

- **Source author**

## Connections

- Source author → Flex lexer: provides source
- Flex lexer → Token vocabulary: classifies with
- Flex lexer → Token table: emits tokens
- Flex lexer → Lexical diagnostics: records errors
- Source author → Parser entry: provides source
- Parser entry → Parser scanner: starts scanning
- Parser scanner → Token vocabulary: classifies with
- Parser scanner → Bison token adapter: maps token types
- Parser scanner → Grammar and actions: supplies tokens
- Grammar and actions → Scopes and symbols: resolves identifiers
- Grammar and actions → AST construction: builds syntax tree
- Grammar and actions → Syntax diagnostics: records errors
- Parser entry → Tokens AST symbols: prints reports
- Parser entry → AST construction: prints tree
- Parser entry → Scopes and symbols: prints symbols
