This repository contains the code for client side of YaarScript.
YaarScript is an educational passion project I built as a solo developer. It is a full-fledged, multi-phase compiler written in Rust, designed to demonstrate advanced compiler construction techniques, such as semantic analysis, intermediate representation optimization, and bytecode execution, while utilizing a uniquely fun, Urdu-infused slang syntax to make learning systems programming more relatable and engaging.
Important
Explore the Core: Check out the compiler source code at the YaarScript Repository.
Quick Links:
- Official Website: yaarscript.netlify.app
- Online Playground: Try YaarScript in the Browser
- Documentation: Read the Docs
- Urdu-Inspired Syntax – Natural keywords like
agar,warna,dohrao,bolomake coding intuitive for Urdu speakers - Lightning Fast – Entire compiler runs in the browser via WebAssembly (wasm32-unknown-unknown)
- Industrial-Grade – Multi-pass compiler with fixed-point optimization, constant folding, and dead code elimination
- Modern IDE – Professional web-based editor with syntax highlighting and real-time execution
- Strong Type System – Strict typing with no implicit coercion for safer code
- Zero Installation – Run directly in your browser with our online playground
YaarScript features a sophisticated multi-pass compilation pipeline:
- Lexical Analysis – Tokenization with full Unicode support
- Syntax Analysis – Top-Down Operator Precedence (Pratt) Parser
- Semantic Analysis – Comprehensive scope management and type checking
- IR Generation – Three-Address Code (TAC) intermediate representation
- Optimization – Fixed-point optimization passes
- Execution – High-performance WASM virtual machine
- ✅ Strong Type System –
number,float,double,char,lafz(string),faisla(boolean) - ✅ Control Flow –
agar/warna(if/else),dohrao(for),jabtak(while),karo-jabtak(do-while) - ✅ Switch Statements –
intekhabwithagar_hocases - ✅ Functions – First-class functions with return types
- ✅ Enumerations –
qismfor defining custom enums - ✅ Constants –
pakkafor immutable values,sab_ke_liyefor globals - ✅ Operators – Full arithmetic, logical, and comparison operations
- ✅ Loop Control –
bas_kar(break),aagay_baro(continue)
YaarScript Maps localized terminology directly to robust systems logic.
| YaarScript Keyword | C-Equivalent | Purpose |
|---|---|---|
number |
int64_t |
64-bit signed integer |
float |
double |
64-bit floating point |
faisla |
bool |
Boolean value |
lafz |
char* |
String primitive |
khaali |
void |
No return value |
pakka |
const |
Immutable constant |
yaar |
main |
Entry point block |
agar |
if |
Conditional branch |
warna |
else |
Alternative branch |
jabtak |
while |
Loop continuation |
dohrao |
for |
Iterative loop |
intekhab |
switch |
Multi-way branching |
bas_kar |
break |
Scope exit |
wapsi |
return |
Function return |
qism |
enum |
Enumeration type |
bolo |
printf |
Console Output |
suno |
scanf |
Console Input |
sahi |
true |
Boolean true |
galat |
false |
Boolean false |
The parser natively incorporates the Power Operator with high precedence.
| Level | Operators | Associativity | Example |
|---|---|---|---|
| 1 | = |
Right-to-left | a = b = c |
| 2 | || |
Left-to-right | a || b |
| 3 | && |
Left-to-right | a && b |
| 4 | ==, != |
Left-to-right | a == b |
| 5 | <, >, <=, >= |
Left-to-right | a < b |
| 6 | &, |, ^, <<, >> |
Left-to-right | a & b |
| 7 | +, - |
Left-to-right | a + b |
| 8 | *, /, % |
Left-to-right | a * b |
| 9 | ** (Power) |
Left-to-right | a ** b |
| 10 | -, !, ++, -- (prefix) |
Right-to-left | !-x |
| 11 | ++, -- (postfix) |
Left-to-right | x++ |
| 12 | () |
Highest | f(x) |
yaar {
number w = 10;
number h = 20;
dohrao (number i = 0; i < 5; i++) {
agar (i == 3) {
bas_kar;
}
}
faisla flag = (w > 5) && (h < 50);
faisla check = !flag;
number result = w ** 2; // Power operator test
bolo("Computed successfully! ", result);
}Expected Output:
0
1
2
Computed successfully! 100
Shows strict type safety catching errors before execution.
khaali invalidVar; // ERROR: 1. ErroneousVarDecl
khaali voidFunc() {
bolo("hello");
}
yaar {
number i = 10;
float f = 3.14;
// 3. FnCallParamType
voidFunc(f);
// 5. ExpressionTypeMismatch
i = 3.14;
// 7. NonBooleanCondStmt
agar (i) {
bolo("wont work");
}
}Compiler Output (Caught at Semantic Stage):
[Type Error] Variable invalidVar cannot be of type void
[Type Error] Function 'voidFunc' expects 0 arguments, but got 1
[Type Error] Invalid assignment: Cannot assign type 'float' to variable 'i' of type 'int'
[Type Error] Condition must be a boolean expression
Before you begin, ensure you have the following installed:
- Node.js (v18 or higher) – Download
- Rust (for building compiler) – Install via rustup
- wasm-pack (for WebAssembly compilation) –
cargo install wasm-pack
# Clone the compiler repository (wasm-compiler branch)
git clone -b wasm-compiler https://github.com/BazilSuhail/YaarScript-Client.git
cd YaarScript-Client
# For building the WASM package go to wasm-compiler branch
git checkout wasm-compiler
# Build the WASM package
wasm-pack build --target web
# This generates a 'pkg' folder with the compiled WASM files# Clone the web client repository
git clone https://github.com/BazilSuhail/YaarScript-Client.git
cd YaarScript-Client
# Copy the compiled WASM package
# Copy the 'pkg' folder from the compiler to the client root directory
# Install dependencies
npm install
# Run the development server
npm run devOpen http://localhost:3000 in your browser to see the application.
YaarScript-Client/
├── pkg/ # WASM compiled files (from compiler)
│ ├── compiler.js
│ ├── compiler_bg.wasm
│ └── ...
├── app/
│ ├── page.jsx # Home page
│ ├── editor/ # Online code editor
│ └── docs/ # Documentation pages
├── components/
│ ├── home-page/ # Landing page components
│ ├── editor/ # Editor components
│ └── docs/ # Documentation components
├── public/ # Static assets
└── package.json
yaar {
bolo("Assalam-o-Alaikum, World!\n");
}
yaar {
number age = 25;
float price = 99.99;
lafz name = "Ahmed";
faisla is_valid = sahi;
bolo("Name: ", name, "\n");
bolo("Age: ", age, "\n");
}
yaar {
number score = 85;
agar (score >= 90) {
bolo("Grade: A\n");
} warna agar (score >= 80) {
bolo("Grade: B\n");
} warna agar (score >= 70) {
bolo("Grade: C\n");
} warna {
bolo("Grade: F\n");
}
}
yaar {
dohrao (number i = 0; i < 5; i++) {
bolo("Iteration: ", i, "\n");
}
}
number add(number a, number b) {
wapsi a + b;
}
khaali greet(lafz name) {
bolo("Hello, ", name, "!\n");
}
yaar {
number sum = add(10, 20);
bolo("Sum: ", sum, "\n");
greet("YaarScript");
}
yaar {
number day = 3;
intekhab (day) {
agar_ho 1:
bolo("Monday\n");
bas_kar;
agar_ho 2:
bolo("Tuesday\n");
bas_kar;
agar_ho 3:
bolo("Wednesday\n");
bas_kar;
aakhir:
bolo("Other day\n");
}
}
We welcome contributions from the community! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- 🐛 Bug fixes and improvements
- 📝 Documentation enhancements
- 🎨 UI/UX improvements
- 🌐 Translations and localization
- ✨ New language features
- 🧪 Test coverage
This project is open source and available under the MIT License.
