Documentation

Language specification and reference for the Bad Language Compiler.

About

Blan is a custom tree-walking interpreter built around Hindi slang. It was written as an applied exercise in compiler design — specifically the Lexical Analysis, Syntax Analysis, and Semantic Analysis phases from the CS312 curriculum at RGIPT.

The compiler is implemented in C++17. The backend execution layer is written in Go and handles asynchronous job execution, result caching via a custom LSM-tree engine (StrataKV), and JWT-based authentication.

This playground sends your source code to the Go backend, which hashes it, checks the cache, and either returns a cached result immediately or runs it through the C++ binary via a bounded worker pool.

Program Structure

Every Blan program must begin with the entry marker and end with the exit marker. Tokens found after the exit marker produce a syntax error.

Haan Meri Jaan
// your program goes here
Bhag Bsdk

Haan Meri Jaan

Entry point. Must be the first non-comment token.

Bhag Bsdk

Exit point. Terminates the program cleanly.

Single-line comments are supported with // and are ignored by the lexer.

Variables

Variables are declared and assigned in a single statement using bhadwa and matlb. There is no separate declaration without assignment.

bhadwa x matlb 10
bhadwa name matlb "Aditya"
bhadwa flag matlb sach

Reassignment uses the same syntax. There is no mutation keyword — bhadwa is always used.

bhadwa count matlb 5
bhadwa count matlb count - 1

Data Types

The evaluator uses a std::variant-based Value type that holds one of four kinds at runtime.

Number

All numeric values are stored as double-precision floating point internally. Trailing zeros are stripped from output.

bhadwa x matlb 42
bhadwa y matlb x + 8

String

String literals are enclosed in double quotes. The + operator concatenates two strings.

bhadwa greeting matlb "Haan "
bolna greeting + "Meri Jaan"

Boolean

Boolean literals are sach (true) and jhooth (false). They print as their Blan names, not as 0/1. In numeric contexts, sach behaves as 1 and jhooth as 0.

bolna sach        // prints: sach
bolna sach == 1   // prints: sach
bolna !jhooth     // prints: sach

Null

Represented by std::monostate internally. Uninitialized state. Prints as null.

Operators

Operators are evaluated left to right within each precedence level. The full precedence chain from lowest to highest:

||  →  &&  →  == !=  →  < <= > >=  →  + -  →  * / %  →  - ! (unary)

Arithmetic

  • +   add / concatenate
  • -   subtract
  • *   multiply
  • /   divide
  • %   modulo

Comparison

  • ==   equal
  • !=   not equal
  • <   less than
  • <=   less or equal
  • >   greater than
  • >=   greater or equal

Logical

  • &&   and (short-circuit)
  • ||   or (short-circuit)
  • !   not

Type mismatches produce a runtime error. You cannot subtract strings or apply ! to a number.

Conditionals

Conditionals use agar for if, warna for else-if, nahi_toh for else, and khtm to close the block. The tab keyword closes the condition header.

agar x > 15 tab
    bolna "greater"
warna x == 10 tab
    bolna "exactly ten"
nahi_toh
    bolna "less"
khtm

The warna chain is handled recursively by the parser — you can nest as many else-if branches as needed. The khtm keyword always appears exactly once, closing the entire chain.

Legacy aliases warna_agar and nhi_toh are still accepted for backward compatibility.

Loops

The while loop uses JabTak to open, TabTak to close the condition header, and hogya to end the body.

bhadwa count matlb 3

JabTak count > 0 TabTak
    bolna count
    bhadwa count matlb count - 1
hogya

The evaluator enforces a hard iteration cap of 100,000 loops. Programs that exceed this are terminated with a runtime error to prevent infinite loops from hanging the execution worker.

Error Messages

Blan uses themed error messages. They are not meant to be polite.

BehenChod! [Line N, Col N] Syntax Error

Emitted by the parser for malformed structure — missing tab, unclosed blocks, unexpected tokens.

CHUDDI! ...

Emitted by the evaluator for runtime errors — type mismatches, division by zero, undefined variables, unknown operators.

CHHUDDI! Maximum loops exceeded

Emitted when the 100,000 iteration cap is hit. Indicates an infinite loop.

Keyword Reference

KeywordRoleAlias
Haan Meri JaanProgram entry
Bhag BsdkProgram exit
bhadwaVariable declaration
matlbAssignment operator
bolnaPrint to stdout
agarIf condition
tabCondition header close
warnaElse-if branchwarna_agar
nahi_tohElse branchnhi_toh
khtmEnd if blockbas_itna_hi
JabTakWhile loop open
TabTakWhile condition close
hogyaEnd while block
sachBoolean true
jhoothBoolean false