How maharabhi01/compiler works
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: main.cpp Compiler driver · Makefile Makefile · program.o Object artifact · scanner.cpp Scanner
Components 12
Native Build
- Makefile · Builds compiler and generated native artifacts.
compiler/Makefile - Compiler executable · Runs the compilation pipeline.
compiler/program - Object artifact · Intermediate native build artifact.
compiler/program.o - Generated native program · Assembly is assembled and linked into this output.
compiler/program
Compiler Front End
- Compiler driver · Orchestrates scanning, parsing, and assembly generation.
compiler/main.cpp - Scanner · Converts source text into tokens.
compiler/scanner.cpp - Token interface · Token categories and representation shared by scanner and parser.
compiler/token.hpp - Parser · Builds or validates parsed program constructs.
compiler/parser.cpp - Parsed program · Boundary between front end and code generation.
Code Generation
- Assembly generator · Translates parsed constructs into assembly.
compiler/asm_gen.cpp - Generated assembly
compiler/program.s
Other components
- NLP source program · Example or current compilation target.
compiler/program.nlp
Connections 15
- 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