Webdevelopment icons created by Alfredo Creates - Flaticon
- π₯οΈ JavaBhaiLang Interpreter
JavaBhaiLang is a minimal, fun programming language interpreter built in Java, inspired by Robert Nystromβs βCrafting Interpretersβ.
β‘ JavaBhaiLang is now feature-complete (v0.9.0-final) - no new features planned.
This project, as of now, fully supports BhaiLang, designed for experimentation without diving into full grammar, functions, or advanced features.
- Parser now executes statements between
hi bhaiandbye bhaionly for file execution. - REPL executes all statements without restriction.
- REPL startup shows version number and GitHub repository link.
- Print statements now insert implicit spaces between multiple expressions, aligning with original BhaiLang behavior.
- Added support for single-quoted strings, e.g.,
'hello' - Added support for multi-line comments using
/* */
| Feature / Behavior | Original BhaiLang | JavaBhaiLang (v0.9.0-final) |
|---|---|---|
| Error reporting | Basic, line number may not show | Shows line number for easier debugging |
Statements outside hi bhai ... bye bhai |
Allowed and ignored | Throws an error - Java version scans character by character, so extra statements beyond hi bhai ... bye bhai are detected |
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.
β οΈ Clarification About the βHierarchy of Powerβ DiagramThe diagram above is meant purely for fun.
In reality:
- Python does not control or influence the interpreter.
- It only acts as a lightweight wrapper script to compile and run the Java code.
- All actual language processing (lexing, parsing, resolving, interpreting) happens entirely in Java.
The hierarchy graphic was included for humor, not as an architectural representation. π
| Platform | Quick Install Command |
|---|---|
| Linux/macOS | bash curl -fsSL https://raw.githubusercontent.com/journeycodesayush/javabhailang/main/install.sh -o install.sh && chmod +x install.sh && ./install.sh --install |
| Windows PowerShell | powershell Invoke-WebRequest "https://raw.githubusercontent.com/JourneyCodesAyush/javabhailang/main/install.ps1" -OutFile "D:\path\to\script.ps1"; Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass; .\script.ps1 --install |
| Windows CMD | cmd curl -L https://raw.githubusercontent.com/JourneyCodesAyush/javabhailang/main/install.bat -o D:\path\to\script.bat && install.bat --install |
JavaBhaiLang can be executed without cloning the repository using JBang. This approach is intended for quickly trying the language or running scripts.
β οΈ Important
- JBang is required for all modes
- The
bhailangcommand is a JBang alias, not a standalone executable- Always invoke the REPL or scripts via
jbang bhailang--onetimeruns BhaiLang once without creating an alias--installcreates a global JBang alias for repeated use- An active internet connection is required (JBang fetches the latest version from GitHub)
- Java 17+ (required to run the JavaBhaiLang interpreter)
- Java 21+ (required only when using JBang)
- JBang installed and available in your PATH
Platform-specific installer scripts are provided at the repository root. All scripts support the same options:
--installβ Create a global JBang alias namedbhailang--onetimeβ Run BhaiLang once without installing--uninstallβ Remove the JBang alias--helpβ Show usage information
curl -fsSL https://raw.githubusercontent.com/journeycodesayush/javabhailang/main/install.sh -o install.sh
# Give executable permission
chmod +x install.sh
# Run once
./install.sh --onetime
# Install alias
./install.sh --install
# Uninstall alias
./install.sh --uninstall
β οΈ Windows Users: Avoid downloading the installer directly to the rootC:\drive. If you choose to do so, proceed at your own risk, as some permissions may prevent script execution. Itβs recommended to use a folder likeC:\Users\<YourName>\DownloadsorC:\Scripts.
Invoke-WebRequest "https://raw.githubusercontent.com/JourneyCodesAyush/javabhailang/main/install.ps1" -OutFile "D:\path\to\script.ps1"
β οΈ PowerShell may block script execution by default. Run this once per terminal session:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass# Run once
.\install.ps1 --onetime
# Install alias
.\install.ps1 --install
# Uninstall alias
.\install.ps1 --uninstall
β οΈ Note: Avoid saving install.bat directly inC:\to prevent permission issues.
curl -L https://raw.githubusercontent.com/JourneyCodesAyush/javabhailang/main/install.bat -o D:\path\to\script.bat:: Run once
install.bat --onetime
:: Install alias
install.bat --install
:: Uninstall alias
install.bat --uninstallAfter installing the alias, always run BhaiLang using JBang:
jbang bhailang
jbang bhailang example.bhaiβΉοΈ Running
bhailangdirectly will result incommand not found. The alias must always be invoked through jbang.
- To work offline
- To modify or extend the interpreter
- To pin a specific version
In those cases, follow the π Run Locally section below.
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 doosra_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
β βββ test/
β βββ java/
β βββ io/github/journeycodesayush/JavaBhaiLang/
β βββ TestHelper.java
β βββ InterpreterTest.java
β
β
βββ 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
β οΈ Java Version RequirementRunning tests and building the project with Maven requires Java 21 or newer.
- A
src/testdirectory has been added in v0.6.1 to hold unit tests for the interpreter. - Tests are written using JUnit 5 only.
- Run tests using Maven:
β οΈ Note: Only JUnit 5 is supported for tests. Running with older JUnit versions may cause failures.
mvn testβοΈ 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
Your closure is already strong and personal β just a few minimal tweaks to improve flow, readability, and grammar, while keeping your tone intact:
JavaBhaiLang is feature-complete as of the v0.9.0-final tag and will not receive new features in the near future. This project taught me about Lexer, Parser, Interpreter, Abstract Syntax Tree (AST), Resolver, Environments, and most importantly, that doing something consistently is where the fun lies.
While building this, I aimed to make it as compatible with the original implementation as possible, but some stones are surely left unturned. I am not abandoning this project - it remains a symbol that I studied Crafting Interpreters and actually learned from it.
This repo stands as proof that I have the resilience to read a book and create something meaningful.
Iska arth ye nahi ki Bhai ki kahani yahi tak thi.
Yaha se Bhai ke jeevan ka naya adhyay shuru hone ja raha hai!
