How tenri69/tnsrlang works
TnsrLang is a C++17 DSL interpreter for tensor computation and neural-network workflows. A script runs from source text through tokenization, parsing into an AST, and tree-walk evaluation; native tensor operations provide AutoGrad and model-training primitives. The CLI also supports AST visualization and neural-network diagnostics, while server mode serves browser tools and executes submitted scripts. README capabilities include model persistence and the web MNIST canvas. Some implementation details, especially persistence and HTTP UI wiring, are documented but were not sampled directly.
Main entry points: Evaluator.cpp Tree-walk evaluator · main.cpp CLI entrypoint · httplib.h HTTP server · public Browser terminal and canvas
Components 19
Language Front End
- Lexer
src/Lexer.cpp - Parser
src/Parser.cpp - Syntax tree
src/AST.cpp - AST visualizer
src/ASTPrinter.cpp
Execution Runtime
- Tree-walk evaluator
src/Evaluator.cpp - Scopes and functions
src/Evaluator.h - Native functions
src/Evaluator.cpp - Model persistence
src/Evaluator.cpp
Tensor and Learning
- Tensor operations
src/MathEngine.cpp - AutoGrad graph
src/MathEngine.cpp - NN training primitives
src/MathEngine.cpp - NN diagnostics
src/Evaluator.cpp
User Interfaces
- CLI entrypoint
src/main.cpp - HTTP server
src/httplib.h - Browser terminal and canvas
public
Other components
- Script author
- TnsrLang source
- Browser user
- Saved model files
Connections 23
- Script author → TnsrLang source: writes
README.md - TnsrLang source → CLI entrypoint: runs
README.md - CLI entrypoint → Lexer: tokenizes with
src/main.cpp - Lexer → Parser: tokens to
- Parser → Syntax tree: builds
src/Parser.cpp - CLI entrypoint → Parser: parses with
src/main.cpp - CLI entrypoint → Tree-walk evaluator: evaluates with
src/main.cpp - Tree-walk evaluator → Scopes and functions: uses scopes
src/Evaluator.h - Tree-walk evaluator → Native functions: registers natives
src/Evaluator.cpp - Native functions → Tensor operations: invokes operations
src/Evaluator.cpp - Tree-walk evaluator → AutoGrad graph: backpropagates
README.md - Tensor operations → AutoGrad graph: records gradients
src/MathEngine.cpp - Native functions → NN training primitives: exposes
src/Evaluator.cpp - Tree-walk evaluator → NN diagnostics: checks tensors
src/Evaluator.cpp - CLI entrypoint → AST visualizer: optionally dumps
src/main.cpp - Tree-walk evaluator → Model persistence: saves and loads
README.md - Model persistence → Saved model files: reads and writes
README.md - Browser user → Browser terminal and canvas: uses
README.md - CLI entrypoint → HTTP server: starts server
src/main.cpp - HTTP server → Browser terminal and canvas: serves assets
- Browser terminal and canvas → HTTP server: submits scripts
README.md - HTTP server → Tree-walk evaluator: executes scripts
- Browser terminal and canvas → NN training primitives: requests inference
README.md