Skip to content

JourneyCodesAyush/JavaBhaiLang

πŸ–₯️ JavaBhaiLang Interpreter

Java JBang Python License Version Status PRs Welcome


Webdevelopment icons created by Alfredo Creates - Flaticon


πŸ“‘ Table of Contents


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.


πŸ†• What's New

v0.9.0-final Highlights

  • Parser now executes statements between hi bhai and bye bhai only 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.

v0.8.0 Highlights

  • Added support for single-quoted strings, e.g., 'hello'
  • Added support for multi-line comments using /* */

⚠️ Differences from Original BhaiLang

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” Diagram

The 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. πŸ˜„


⚑ Quick Install TL;DR

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

πŸš€ Run via JBang (No Repo Clone)

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 bhailang command is a JBang alias, not a standalone executable
  • Always invoke the REPL or scripts via jbang bhailang
  • --onetime runs BhaiLang once without creating an alias
  • --install creates a global JBang alias for repeated use
  • An active internet connection is required (JBang fetches the latest version from GitHub)

Prerequisites

  • Java 17+ (required to run the JavaBhaiLang interpreter)
  • Java 21+ (required only when using JBang)
  • JBang installed and available in your PATH

Installer Scripts

Platform-specific installer scripts are provided at the repository root. All scripts support the same options:

  • --install β†’ Create a global JBang alias named bhailang
  • --onetime β†’ Run BhaiLang once without installing
  • --uninstall β†’ Remove the JBang alias
  • --help β†’ Show usage information

Linux / macOS (Unix shells)

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 – PowerShell (install.ps1)

⚠️ Windows Users: Avoid downloading the installer directly to the root C:\ 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 like C:\Users\<YourName>\Downloads or C:\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

Windows – Command Prompt (install.bat)

⚠️ Note: Avoid saving install.bat directly in C:\ 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 --uninstall

Using JavaBhaiLang

After installing the alias, always run BhaiLang using JBang:

jbang bhailang
jbang bhailang example.bhai

ℹ️ Running bhailang directly will result in command not found. The alias must always be invoked through jbang.

When should you clone the repository?

  • To work offline
  • To modify or extend the interpreter
  • To pin a specific version

In those cases, follow the πŸƒ Run Locally section below.


πŸƒ Run Locally

You need:

  • Java (any recent version, 2-3 years old also works)
  • Python (for the helper script that compiles and runs JavaBhaiLang)

Steps:

  1. Clone the repo:

    git clone https://github.com/JourneyCodesAyush/javabhailang.git
    cd javabhailang
  2. Open the REPL using the Python helper script:

    python run_bhai_lang.py
  3. 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

πŸ“ Examples

NOTE: Semicolon ; is mandatory

Variables

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

Types

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;

Built-ins

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;

Conditionals

This interpreter now supports full if–else-if–else ladders using:

  • agar bhai β†’ if
  • nahi to bhai β†’ else if
  • warna 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.";
}

Loops

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";

Break & Continue

You can control loop flow using:

  • agla dekh bhai; β†’ continue
  • bas 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!";

βš™οΈ Features

  • πŸ–₯️ 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 β†’ break
    • agla dekh bhai β†’ continue

⚠️ Known Limitations

  • No standard library except built-in print (bol bhai)
  • Only single-file execution via run_bhai_lang.py

βœ”οΈ Previously Resolved Limitations

These features were missing earlier but are now fully implemented:

  • Full if–else-if–else ladder
  • Multi-variable bol bhai
  • Complex assignment operators (+=, -=, *=, /=)
  • Loop control: bas kar bhai (break) & agla dekh bhai (continue)

πŸ“ Project Structure

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!

πŸ§‘β€πŸ’» Development Guide

  • Interpreter written in Java, modular design
  • Extend by adding new grammar rules, statements, or features
  • Use run_bhai_lang.py for 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

πŸ§ͺ Running Tests (v0.6.1)

⚠️ Java Version Requirement

Running tests and building the project with Maven requires Java 21 or newer.

  • A src/test directory 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

🧾 Commit Message Convention

✍️ Follow Conventional Commits

feat(<scope>): add new feature
fix(<scope>): bug fix
docs(<scope>): documentation change

🀝 Contributing

Want 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
  • 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 with run_bhai_lang.py.
  • Open a Pull Request with a clear description
  • Respect the Code of Conduct: CODE_OF_CONDUCT.md

LICENSE

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.


πŸ“¬ Author

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:


❀️ Closure

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!