# maharabhi01/compiler architecture

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

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

## Overview

#### Purpose and entry points
This repository is a native compiler project. Its primary executable is likely `compiler/program`, built from the C++ sources through `compiler/Makefile`. The compiler’s source-language input appears to use `.nlp` files, with `compiler/program.nlp` serving as an example or current compilation target.

#### Build and runtime boundary
`compiler/Makefile` defines the native build pipeline, producing object code (`compiler/program.o`), assembly (`compiler/program.s`), and the executable (`compiler/program`). The implementation runs as a C++ command-line program rather than a web or service runtime.

#### Compiler driver
`compiler/main.cpp` is the orchestration entry point. It likely accepts or selects source input, invokes lexical scanning and parsing, then passes the resulting program representation into assembly generation. This is the main control-flow boundary between user input and generated machine-oriented output.

#### Lexical analysis
`compiler/scanner.cpp` tokenizes source text into a stream consumed by the parser. `compiler/token.hpp` defines the token representation and/or token categories shared across scanning and parsing. This isolates source-text handling from syntax and code-generation stages.

#### Parsing and program representation
`compiler/parser.cpp` consumes tokens and constructs or validates the language’s syntactic structure. Its output is the central internal boundary: scanner details should not reach later stages, while assembly generation should operate on parsed program constructs rather than raw text.

#### Assembly generation and artifacts
`compiler/asm_gen.cpp` translates parsed constructs into assembly, represented by the generated artifact `compiler/program.s`. The assembly is then assembled/linked into `compiler/program` via the build process. `compiler/program.o` is the intermediate object-level boundary between generated assembly and the final native executable.

#### Primary flow
The expected end-to-end flow is:

source program such as `compiler/program.nlp` → `compiler/scanner.cpp` → `compiler/parser.cpp` → `compiler/asm_gen.cpp` → `compiler/program.s` → object/link steps from `compiler/Makefile` → `compiler/program`.

The principal architectural interfaces are tokens (`compiler/token.hpp`), the parser-to-generator program structure, and generated assembly as the handoff to the system assembler/linker.

Main entry points: [`compiler/main.cpp`](https://github.com/maharabhi01/compiler/blob/main/compiler/main.cpp) (Compiler driver), [`compiler/Makefile`](https://github.com/maharabhi01/compiler/blob/main/compiler/Makefile) (Makefile), [`compiler/program.o`](https://github.com/maharabhi01/compiler/blob/main/compiler/program.o) (Object artifact), [`compiler/scanner.cpp`](https://github.com/maharabhi01/compiler/blob/main/compiler/scanner.cpp) (Scanner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_build["Native Build"]
  node_makefile["Makefile<br/>build definition"]
  node_compiler_executable["Compiler executable<br/>native CLI"]
  node_object["Object artifact<br/>object code<br/>[program.o]"]
  node_native_program["Generated native program<br/>native executable"]
end

subgraph group_frontend["Compiler Front End"]
  node_main["Compiler driver<br/>C++ entry point<br/>[main.cpp]"]
  node_scanner["Scanner<br/>lexer<br/>[scanner.cpp]"]
  node_token["Token interface<br/>shared representation<br/>[token.hpp]"]
  node_parser["Parser<br/>syntax analyzer<br/>[parser.cpp]"]
  node_program_ir{{"Parsed program<br/>program structure"}}
end

subgraph group_backend["Code Generation"]
  node_asm_gen["Assembly generator<br/>code generator<br/>[asm_gen.cpp]"]
  node_assembly["Generated assembly<br/>assembly artifact<br/>[program.s]"]
end

node_source["NLP source program<br/>source input<br/>[program.nlp]"]

node_makefile -->|"builds"| node_compiler_executable
node_compiler_executable -->|"starts"| node_main
node_source -->|"source text"| node_scanner
node_main -->|"invokes"| node_scanner
node_scanner -->|"produces"| node_token
node_token -->|"token stream"| node_parser
node_main -->|"invokes"| node_parser
node_parser -->|"constructs"| node_program_ir
node_main -->|"invokes"| node_asm_gen
node_program_ir -->|"parsed constructs"| node_asm_gen
node_asm_gen -->|"emits"| node_assembly
node_makefile -->|"assembles"| node_object
node_assembly -->|"assembled into"| node_object
node_makefile -->|"links"| node_native_program
node_object -->|"linked into"| node_native_program

click node_source "https://github.com/maharabhi01/compiler/blob/main/compiler/program.nlp"
click node_makefile "https://github.com/maharabhi01/compiler/blob/main/compiler/Makefile"
click node_compiler_executable "https://github.com/maharabhi01/compiler/blob/main/compiler/program"
click node_main "https://github.com/maharabhi01/compiler/blob/main/compiler/main.cpp"
click node_scanner "https://github.com/maharabhi01/compiler/blob/main/compiler/scanner.cpp"
click node_token "https://github.com/maharabhi01/compiler/blob/main/compiler/token.hpp"
click node_parser "https://github.com/maharabhi01/compiler/blob/main/compiler/parser.cpp"
click node_asm_gen "https://github.com/maharabhi01/compiler/blob/main/compiler/asm_gen.cpp"
click node_assembly "https://github.com/maharabhi01/compiler/blob/main/compiler/program.s"
click node_object "https://github.com/maharabhi01/compiler/blob/main/compiler/program.o"
click node_native_program "https://github.com/maharabhi01/compiler/blob/main/compiler/program"

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_makefile,node_compiler_executable,node_object,node_native_program toneBlue
class node_main,node_scanner,node_token,node_parser,node_program_ir toneAmber
class node_asm_gen,node_assembly toneMint
class node_source toneNeutral
```

## Components

### Native Build

- [Makefile](https://github.com/maharabhi01/compiler/blob/main/compiler/Makefile): build definition · Builds compiler and generated native artifacts. · `compiler/Makefile`
- [Compiler executable](https://github.com/maharabhi01/compiler/blob/main/compiler/program): native CLI · Runs the compilation pipeline. · `compiler/program`
- [Object artifact](https://github.com/maharabhi01/compiler/blob/main/compiler/program.o): object code · Intermediate native build artifact. · `compiler/program.o`
- [Generated native program](https://github.com/maharabhi01/compiler/blob/main/compiler/program): native executable · Assembly is assembled and linked into this output. · `compiler/program`

### Compiler Front End

- [Compiler driver](https://github.com/maharabhi01/compiler/blob/main/compiler/main.cpp): C++ entry point · Orchestrates scanning, parsing, and assembly generation. · `compiler/main.cpp`
- [Scanner](https://github.com/maharabhi01/compiler/blob/main/compiler/scanner.cpp): lexer · Converts source text into tokens. · `compiler/scanner.cpp`
- [Token interface](https://github.com/maharabhi01/compiler/blob/main/compiler/token.hpp): shared representation · Token categories and representation shared by scanner and parser. · `compiler/token.hpp`
- [Parser](https://github.com/maharabhi01/compiler/blob/main/compiler/parser.cpp): syntax analyzer · Builds or validates parsed program constructs. · `compiler/parser.cpp`
- **Parsed program**: program structure · Boundary between front end and code generation.

### Code Generation

- [Assembly generator](https://github.com/maharabhi01/compiler/blob/main/compiler/asm_gen.cpp): code generator · Translates parsed constructs into assembly. · `compiler/asm_gen.cpp`
- [Generated assembly](https://github.com/maharabhi01/compiler/blob/main/compiler/program.s): assembly artifact · `compiler/program.s`

### Other components

- [NLP source program](https://github.com/maharabhi01/compiler/blob/main/compiler/program.nlp): source input · Example or current compilation target. · `compiler/program.nlp`

## Connections

- Makefile → Compiler executable: builds
- Compiler executable → Compiler driver: starts
- NLP source program → Scanner: source text
- Compiler driver → Scanner: invokes
- Scanner → Token interface: produces
- Token interface → Parser: token stream
- Compiler driver → Parser: invokes
- Parser → Parsed program: constructs
- Compiler driver → Assembly generator: invokes
- Parsed program → Assembly generator: parsed constructs
- Assembly generator → Generated assembly: emits
- Makefile → Object artifact: assembles
- Generated assembly → Object artifact: assembled into
- Makefile → Generated native program: links
- Object artifact → Generated native program: linked into
