Status: Authoritative Specification Version: 2.0.0 Last Updated: 2026-07-15 Related Documents: 00 Master Architecture · 06 Lexer · 07 Parser · 10 Semantic Analysis · 11 Interpreter
flowchart TD
SRC["Source Code (.txs)"]
LEX["Stage 1: Lexer"]
TOK["Token Stream"]
PAR["Stage 2: Parser"]
RAST["Raw AST"]
SEM["Stage 3: Semantic Analyzer"]
CAST["Checked AST + Symbol Table"]
INT["Stage 4a: Interpreter (v2.0)"]
OUT["Program Output"]
BC["Stage 4b: Bytecode Compiler (v2.1)"]
BYTEC["Bytecode"]
VM["Stage 5b: Virtual Machine (v2.1)"]
LLVM["Stage 4c: LLVM Backend (v3.0)"]
IR["LLVM IR"]
OPT["LLVM Optimizer"]
BIN["Native Binary"]
SRC --> LEX
LEX --> TOK
TOK --> PAR
PAR --> RAST
RAST --> SEM
SEM --> CAST
CAST --> INT
INT --> OUT
CAST -.-> BC
BC -.-> BYTEC
BYTEC -.-> VM
VM -.-> OUT
CAST -.-> LLVM
LLVM -.-> IR
IR -.-> OPT
OPT -.-> BIN
style SRC fill:#e8e8e8,color:#333
style LEX fill:#ff6b6b,color:#fff
style PAR fill:#ff6b6b,color:#fff
style SEM fill:#ff6b6b,color:#fff
style INT fill:#ffd93d,color:#333
style OUT fill:#6bcb77,color:#fff
style BC fill:#aaa,color:#fff
style VM fill:#aaa,color:#fff
style LLVM fill:#aaa,color:#fff
style BIN fill:#aaa,color:#fff
Solid lines = v2.0 pipeline (interpreter). Dashed lines = future versions.
Crate: techscript_lexer
Input: &str (UTF-8 source code)
Output: Vec<Token>
- Scan source text character-by-character.
- Produce tokens containing
TokenKind, lexeme string slice, and sourceSpan. - Handle string escapes and f-string interpolation boundaries.
- Handle nested block comments.
- Identify newline tokens significant for statement termination.
- Emit
Funtokens and record deprecation triggers.
Crate: techscript_parser
Input: Vec<Token>
Output: Program (AST root node)
- Consume tokens and construct AST nodes.
- Validate syntactic structure against the EBNF Grammar.
- Handle operator precedence and associativity via Pratt parsing.
- Recover from parser errors using panic-mode synchronization.
- Parse methods declared with either
buildorfunkeywords.
Crate: techscript_sema
Input: Program (raw AST)
Output: CheckedProgram (annotated AST + SymbolTable)
- Name resolution: Resolve identifiers to declarations.
- Scope analysis: Enforce lexical scoping, detect duplicates, and flag shadowing.
- Keyword warning: Inspect the AST and emit deprecation warnings (
W0015) for any method defined with thefunkeyword. - Validation: Check function call arity, loop bounds, model declarations, and FFI imports.
Crate: techscript_interpreter
Input: CheckedProgram
Output: Program output side effects and process exit code
- Walk the checked AST and execute nodes sequentially.
- Maintain runtime Environment scopes.
- Dispatch methods defined with both
buildandfunkeywords uniformly. - Catch runtime exceptions via
attempt/catch.
- Source Files: The compiler toolchain refuses to parse files that do not carry the
.txsextension. - Unified Methods: The Parser and Semantic Analyzer allow both
doandfunmethods. During Semantic Analysis,funusages are recorded in the diagnostics database as warnings, but do not prevent the interpreter stage from running.
- When running compilation in check mode:
The compiler prints all diagnostic warnings, including legacy
tech check src/main.txs
funuses:Warning [TSW1002]: Use of deprecated keyword 'fun' --> src/main.txs:12:5 | 12 | fun bark() | ^^^ help: replace 'fun' with 'do'
- Rust Implementation: Implementing in Rust ensures memory safety, sub-millisecond startup times, and deterministic performance profile.
- Frontend/Backend decoupling: Decoupling the frontend (lexer, parser, sema) from the backend (interpreter, VM, LLVM) guarantees that future VM/LLVM updates require zero parser modifications.
- v2.1: The Semantic Analyzer will output an intermediate representation (IR) or flat bytecode instructions for the VM backend.
- v3.0: The code generator block will swap the VM backend for the LLVM Backend, compiling
.txssource directly into native machine code.