How Bnlang Works Internally
Bnlang is a native programming language. The whole runtime is modern C++ — lexer, parser, tree-walking interpreter, value model, and every built-in module.
There is no virtual machine, no transpilation step, and no dependency on a JavaScript engine.
This page walks through what happens when you run bnl your_script.bnl.
Execution Pipeline
- Lexer — reads source bytes and produces a token stream. Bangla and English keywords (e.g.
if/যদি,function/ফাংশন) map to the sameTokenType, so the parser sees one unified language. - Parser — turns tokens into an AST (Abstract Syntax Tree). Pure recursive descent; no parser generator.
- Interpreter — walks the AST directly to produce values. No bytecode emission, no JIT.
- Event loop — libuv drives async I/O (file ops, sockets, timers, child processes) without blocking the main thread.
- Standard library — built-in modules (
io,web,request,template,sqlite,pg,mongo,crypto, ...) live in C++ and register their functions with the interpreter at startup.
Example: One Program, Two Languages
The two snippets below parse to the same AST and run identically. The lexer's keyword table is the only thing that knows the difference.
var x = 10;
if (x > 5) {
print("Large");
} else {
print("Small");
}
Runtime Stack
Under the hood Bnlang stands on a small set of well-known C/C++ libraries:
- C++20 — the interpreter, value model, and built-in modules.
- libuv — cross-platform event loop and async I/O primitives.
- OpenSSL — TLS for HTTPS / WebSocket-over-TLS, plus hashing, HMAC, and base64/hex codecs.
- llhttp — fast HTTP/1.1 parser used by the built-in web server and client.
- SQLite / libpq / mongo-c-driver — embedded SQLite plus first-class clients for PostgreSQL and MongoDB.
- zlib — gzip/deflate for HTTP compression and general data processing.