Skip to content

JourneyCodesAyush/JavaBhaiLang

πŸ–₯️ JavaBhaiLang Interpreter

Java Python License Version Status PRs Welcome


πŸ“‘ Table of Contents


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.


πŸ†• What's New

v0.5.0

  • Conditionals: Added full agar bhai (if), nahi to bhai (else if), and warna bhai (else) support.
  • Interpreter (Interpreter.java): Fixed printing of boolean values. sahi and galat are now printed instead of Java’s true/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.


πŸƒ 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 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
β”‚
β”œβ”€β”€ 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

🧾 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

About

An interpreter for Bhai lang written in Java

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published