This document describes the compilation pipeline of the TechScript 2.0 compiler.
graph TD
A[Source File] --> B[Lexer]
B --> C[Parser]
C --> D[Abstract Syntax Tree]
D --> E[Semantic Analysis]
E --> F[IR Generation]
F --> G[Code Generator]
Scans the source character stream and generates tokens using the logos Rust library. Whitespace is ignored except when separating keywords or within string literals.
Implements a top-down operator precedence (Pratt Parser) for parsing expressions cleanly. This avoids deeply nested recursive grammar structures and cleanly parses operator precedence.
The parsing phase outputs an AST containing nodes representing program statements, expressions, loops, and definitions. Every node holds source code locations (Span) for error attribution.
Validates program semantics prior to runtime:
- Scope Resolution: Ensures variables are defined in the current block or enclosing parents.
- Constant Verification: Fails compilation if code attempts to reassign a constant.
- OOP checks: Verifies subclasses inherit from valid models, and trait contracts are fully implemented.
Translates optimized AST structures into:
- Bytecode Instructions: 8-bit opcodes for the Virtual Machine (VM).
- LLVM IR: Compiled into platform-specific machine code.