I Built a Programming Language in Bhojpuri from Scratch Using Go
Nobody asked for a Bhojpuri programming language, so I built one.
Meet BiharLang, a dynamically typed, interpreted toy programming language written entirely in Go, with keywords derived from Bhojpuri.
Why I built it
I've always been curious about how programming languages work beneath the syntax we use every day.
I wanted to see how a language parses expressions, applies operator precedence, stores variables and lets functions remember their surrounding scope. Reading about those ideas only got me so far. So I implemented them myself.
Why Bhojpuri? It made the project more fun.
A huge shoutout to the developers behind BhaiLang for the inspiration and to my friends from Bihar who helped me figure out the keywords.
Project structure:
biharlang/
├── cmd/
│ └── bihari/
│ └── main.go # CLI entry point (REPL and file runner)
├── lexer/
│ ├── lexer.go # Tokenizer implementation
│ └── lexer_test.go # Lexer unit tests
├── parser/
│ ├── parser.go # Pratt parser implementation
│ └── parser_test.go # Parser unit tests
├── evaluator/
│ ├── evaluator.go # Tree-walking evaluator
│ ├── evaluator_test.go # Evaluator unit tests
│ └── environment.go # Scoped variable environment (closures)
├── ast/
│ └── ast.go # Abstract Syntax Tree node definitions
├── object/
│ └── object.go # Runtime value types
├── token/
│ └── token.go # Token type definitions and keyword lookup
├── repl/
│ └── repl.go # Interactive REPL implementation
├── go.mod # Go module definition
├── main.bh # Example BiharLang script
├── README.md
└── LICENSE
What BiharLang looks like
Here's a simple program:
rakha naam = "Babu"
rakha umar = 25
bol "Ka ho " + naam + "!"
bol umar
Output:
Ka ho Babu!
25
Some of the keywords currently supported are:
| BiharLang | English equivalent |
|---|---|
| rakha | let / var |
| bol | |
| agar | if |
| nata | else |
| jabtak | while |
| kaam | function |
| lauta | return |
| sach | true |
| jhoot | false |
| kuchnahi | null |
BiharLang also supports functions, recursion and loops. Here's a factorial implementation:
kaam factorial(n) {
agar (n <= 1) {
lauta 1
}
lauta n * factorial(n - 1)
}
bol factorial(5)
Output:
120
How BiharLang works internally
BiharLang uses a fairly simple interpreter architecture with three major components: a lexer, a parser and an evaluator.
Source Code (.bh)
|
v
Lexer
|
v
Tokens
|
v
Parser
|
v
Abstract Syntax Tree
|
v
Evaluator
|
v
Runtime Values
1. The lexer
The lexer converts raw source code into tokens the parser can understand. Given this BiharLang statement:
rakha x = 10 + 5
It produces tokens that conceptually look like this:
RAKHA
IDENTIFIER(x)
ASSIGN
INTEGER(10)
PLUS
INTEGER(5)
EOF
- Nothing runs yet. At this stage, the interpreter doesn't evaluate anything
- The lexer only identifies what each part of the source represents.
- I implemented it manually in Go, with support for identifiers, keywords, integers, strings and both single-character and multi-character operators.
- This is also where the Bhojpuri keywords are recognized.
2. The parser
- Once I had a stream of tokens, I needed to determine how they relate to one another.
- Why a Pratt parser?
- It parses expressions according to operator precedence.
Consider this expression:
5 + 3 * 2
Multiplication must happen before addition, so the parser represents the expression as an Abstract Syntax Tree (AST):
+
/ \
5 *
/ \
3 2
The evaluator traverses this tree. The result is 11.
BiharLang currently implements the following precedence levels, from lowest to highest:
- LOWEST
- EQUALS
- LESSGREATER
- SUM
- PRODUCT
- CALL
The Pratt parser also makes it easier to add more operators later.
3. The evaluator
After the parser constructs the AST, the evaluator walks through it recursively. This is where the interpreter runs the program.
For this code:
rakha x = 10 + 5
bol x
The evaluator computes the expression, stores the result in the environment and retrieves it when evaluating the print statement.
Every runtime value in BiharLang implements a common Go interface:
type Object interface {
Type() ObjectType
Inspect() string
}
The runtime currently includes integers, strings, booleans, null values, functions, return values and errors.
The language is dynamically typed, so variable types are determined at runtime rather than explicitly declared.
4. Environments and closures
An environment stores variable names and their corresponding runtime values.
Functions create enclosed environments that reference their parent environment, allowing them to access variables from the surrounding lexical scope.
For example:
rakha x = 10
kaam getX() {
lauta x
}
bol getX()
Output:
10
The function can access x even though it wasn't declared inside the function itself.
Implementing environments gave me a much clearer understanding of lexical scoping and closures than simply using them in other programming languages.
5. The interactive REPL
I also built a REPL (Read-Eval-Print Loop) so users can run BiharLang interactively without creating a script file:
bh repl
To run a .bh file directly:
bh main.bh
The project includes unit tests for the lexer, parser and evaluator. Run them with:
go test ./... -v
What's next?
BiharLang is still a toy language, and plenty is missing. I'd like to add:
- Arrays
- Hash maps
- Logical operators
- Break and continue statements
- Built-in functions
- User input
- File I/O
For now, it can execute functions, recursion, loops, expressions and conditionals—which is exactly what I set out to build.
Final thoughts
It isn't meant to replace an existing language. It's a learning project I built for fun, and it's open-source under the MIT license.
GitHub: https://github.com/CoderZ90/BiharLang
Try it live: https://helloadi.vercel.app/projects/biharlang
Linkedin: https://lnkd.in/p/gg6JMejZ
Try it, break it or contribute. Suggestions, feedback and bug reports are always welcome! :D
Made with ❤️ for fun & learning.
Resources that helped me
- BhaiLang — the inspiration behind the fun part of BiharLang.
- The Super Tiny Compiler — helped me understand some of the concepts behind language implementation.


Top comments (0)