This project is a custom-built compiler written in C++ that parses a subset of C++-like syntax and translates it into executable instructions. The system processes raw text input, validates it against defined language rules, and emits low-level instructions that are executed through a custom runtime environment.
Unlike traditional compilers that target existing architectures, this project implements its own instruction model and execution pipeline on Linux, demonstrating core compiler design concepts such as parsing, syntax validation, and instruction generation.
-
Parses structured input using C++-style syntax (e.g.,
{}blocks) -
Supports core language constructs:
if/while/forcontrol flowcout <<output operations- Arithmetic operations and assignment (
+=, comparisons, etc.)
-
Translates high-level syntax into custom machine-level instructions
-
Executes compiled instructions through a custom runtime
-
Handles nested scopes and block structures
- Language: C++
- Environment: Linux
- Core Concepts: Compiler design, parsing, code generation, instruction execution
The compiler follows a simplified compilation pipeline:
-
Parsing Phase
- Reads raw text input and constructs an internal representation based on defined grammar rules
- Validates syntax such as block structure and control flow statements
-
Code Generation
- Converts parsed structures into a custom instruction set
- Emits low-level instructions representing program behavior
-
Execution Engine
- Runs generated instructions using a custom-built machine model
- Simulates execution rather than relying on native CPU compilation
This design demonstrates how high-level constructs are lowered into executable operations.
- Linux environment
g++with C++17 support
g++ -std=c++17 -o mycompiler *.cpp- Prepare a text file containing supported C++-like syntax
- Modify or pass the file into the
CodeAndExecute()function - Execute the compiler:
./mycompiler- The program will compile the input and display the execution output
- Nested scopes and variable shadowing
- Loop execution (
for,while) - Conditional branching (
ifstatements) - Output via
cout
- Expand supported C++ syntax
- Add lexical analysis stage (tokenization improvements)
- Improve error handling and diagnostics
- Target real assembly output instead of a custom instruction set
- Add optimization passes
- Implementation of a full compilation pipeline
- Designing and executing a custom instruction set
- Managing scope and control flow in a compiler
- Bridging high-level syntax with low-level execution
