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

  1. Lexer — reads source bytes and produces a token stream. Bangla and English keywords (e.g. if / যদি, function / ফাংশন) map to the same TokenType, so the parser sees one unified language.
  2. Parser — turns tokens into an AST (Abstract Syntax Tree). Pure recursive descent; no parser generator.
  3. Interpreter — walks the AST directly to produce values. No bytecode emission, no JIT.
  4. Event loop — libuv drives async I/O (file ops, sockets, timers, child processes) without blocking the main thread.
  5. 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.