- π₯οΈ JavaBhaiLang Interpreter
JavaBhaiLang is a minimal, fun programming language interpreter built in Java, inspired by Robert Nystromβs βCrafting Interpretersβ.
This project, as of now, is a subset of JavaBhaiLang, designed for experimentation without diving into full grammar, functions, or advanced features (yet). Future updates may include full JavaBhaiLang support and user-defined functions.
- Conditionals: Added full
agar bhai(if),nahi to bhai(else if), andwarna bhai(else) support. - Interpreter (
Interpreter.java): Fixed printing of boolean values.sahiandgalatare now printed instead of Javaβstrue/false.
In the grand scheme of things, Python quietly whispers, Java obeys loyally, and Bhai Lang just unleashes chaos. The true hierarchy of power is subtle.
+-------------------------------------+
| Python VM (PVM) |
| "The Unseen Puppeteer" |
| Launches JVM, whispers to Java |
+----------------+--------------------+
|
v
+-------------------------------------+
| Java Virtual Machine (JVM) |
| "The Loyal Servant" |
| Executes Bhai Lang Interpreter |
+----------------+--------------------+
|
v
+-------------------------------------+
| Bhai Lang Interpreter |
| "The Mouthpiece of Chaos" |
| Reads and runs your Bhai Lang |
| code like a true Bhai π |
+----------------+--------------------+
|
v
+-------------------------------------+
| Bhai Lang Code |
| "The Soul of Madness" |
+-------------------------------------+
TL;DR: Python whispers, Java obeys, Bhai Lang just does whatever it wants.
β οΈ Note: This is currently experimental and meant for fun and learning purposes.
You need:
- Java (any recent version, 2-3 years old also works)
- Python (for the helper script that compiles and runs JavaBhaiLang)
-
Clone the repo:
git clone https://github.com/JourneyCodesAyush/javabhailang.git cd javabhailang -
Open the REPL using the Python helper script:
python run_bhai_lang.py
-
Execute a bhai lang script:
python run_bhai_lang.py example.bhai
The Python script will:
- Compile all Java files in src/ to out/ directory
- Run the main JavaBhaiLang interpreter
- Clean up .class files on exit
NOTE: Semicolon
;is mandatory
Variables can be declared using bhai ye hai.
BhaiLang now also supports complex assignment operators (+=, -=, *=, /=).
bhai ye hai a = 10;
bhai ye hai b = 5;
a += 3; // Equivalent to: a = a + 3
b -= 2; // Equivalent to: b = b - 2
a *= b; // Equivalent to: a = a * b
b /= 3; // Equivalent to: b = b / 3
bol bhai a, b; # Prints the updated values
Numbers and Strings like other well known languages. Null values denoted by nalla, boolean values by sahi and galat
bhai ye hai string = "hello bhai";
bhai ye hai number = 14.0;
bhai ye hai boolean_value_true = sahi;
bhai ye hai boolean_value_false = galat;
bhai ye hai null_value = nalla;
Use bol bhai to print anything to console. Now supports multiple variables:
bhai ye hai a = 10;
bhai ye hai b = 20;
# Single variable
bol bhai a;
# Multiple variables
bol bhai "Values are:", a, b;
This interpreter now supports full ifβelse-ifβelse ladders using:
agar bhaiβ ifnahi to bhaiβ else ifwarna bhaiβ else
bhai ye hai score = 75;
agar bhai (score >= 90) {
bol bhai "Topper bhai!";
} nahi to bhai (score >= 60) {
bol bhai "Pass hogaya bhai!";
} warna bhai {
bol bhai "Thoda padh le bhai.";
}
The statements inside jab tak bhai are executed until the condition is evaluated to sahi.
The moment condition turns galat, loop terminates.
bhai ye hai a = 0;
jab tak bhai (a < 10) {
a = a + 1;
agar bhai (a == 5) {
bol bhai "andar se bol bhai 5";
}
agar bhai (a == 6) {
bol bhai "andar se bol bhai 6";
}
bol bhai a;
}
bol bhai "done";
You can control loop flow using:
agla dekh bhai;β continuebas kar bhai;β break
bhai ye hai counter = 0;
jab tak bhai (counter < 10) {
counter = counter + 1;
agar bhai (counter == 3) {
bol bhai "Skipping 3, counter:", counter;
agla dekh bhai;
}
agar bhai (counter == 7) {
bol bhai "Stop at 7, counter:", counter;
bas kar bhai;
}
bol bhai counter;
}
bol bhai "Loop finished!";
- π₯οΈ Minimal JavaBhaiLang interpreter in Java
- π― Focus on learning interpreter design rather than full language features
- π Easy-to-extend for future grammar and functions
- π Python helper script for compiling and running code effortlessly
- π§ No external dependencies besides Java & Python
- β Added support for loop control statements:
bas kar bhaiβ breakagla dekh bhaiβ continue
- No standard library except built-in print (
bol bhai) - Only single-file execution via
run_bhai_lang.py
These features were missing earlier but are now fully implemented:
- Full
ifβelse-ifβelseladder - Multi-variable
bol bhai - Complex assignment operators (
+=,-=,*=,/=) - Loop control:
bas kar bhai(break) &agla dekh bhai(continue)
JavaBhaiLang/
βββ run_bhai_lang.py # Python helper script to compile & run
βββ src/
β βββ main/
β βββ java/
β βββ io/github/journeycodesayush/JavaBhaiLang/
β βββ BhaiLang.java # Driver code
β βββ interpreter/ # Interpreter and Exception files
β βββ lexer/ # Lexer, Token and TokenType
β βββ parser/ # Parser, Expression and Statement
β βββ tool/ # Generate AST
β
βββ LICENSE # MIT License
βββ README.md # You're reading it!
- Interpreter written in Java, modular design
- Extend by adding new grammar rules, statements, or features
- Use
run_bhai_lang.pyfor fast testing during development - Follow the Java conventions already in the repo
- When adding new grammar rules, statements, or built-in functions, ensure your code is modular and follows the existing patterns in:
src/main/java/io/github/journeycodesayush/JavaBhaiLang/ - Use the Python helper script (
run_bhai_lang.py) to quickly test your changes
βοΈ Follow Conventional Commits
feat(<scope>): add new feature
fix(<scope>): bug fix
docs(<scope>): documentation changeWant to contribute to JavaBhaiLang? Awesome! Here's a quick guide:
- Fork the repo and work on a separate branch (
feat/feature-name,fix/bug-name) - Keep changes modular: one feature, bug fix, or improvement per commit
- Commit messages: use Angular format:
<type>(<scope>): short description- Types:
feat,fix,docs,style,refactor,test,chore - Scopes:
interpreter | lexer | parser | tool | examples | docs | tests
- Types:
- Test your changes using
run_bhai_lang.py - If adding new language features, statements, or built-in commands, follow the existing code structure in
src/main/java/io/github/journeycodesayush/JavaBhaiLang/and test thoroughly withrun_bhai_lang.py. - Open a Pull Request with a clear description
- Respect the Code of Conduct: CODE_OF_CONDUCT.md
MIT License
Copyright (c) 2025 JourneyCodesAyush
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the βSoftwareβ), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies
or substantial portions of the Software.
THE SOFTWARE IS PROVIDED βAS ISβ, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Made with β₯ by JourneyCodesAyush