Language Basics
Operators
BanglaCode provides a comprehensive set of operators for arithmetic, comparison, logical operations, and more. Some logical operators use Bengali keywords.
Arithmetic Operators
| Operator | Name | Example | Result |
|---|---|---|---|
+ | Addition | 5 + 3 | 8 |
- | Subtraction | 5 - 3 | 2 |
* | Multiplication | 5 * 3 | 15 |
/ | Division | 10 / 4 | 2.5 |
% | Modulo | 10 % 3 | 1 |
** | Exponent | 2 ** 3 | 8 |
| 1 | dhoro a = 10; |
| 2 | dhoro b = 3; |
| 3 | |
| 4 | dekho(a + b); // 13 (Addition) |
| 5 | dekho(a - b); // 7 (Subtraction) |
| 6 | dekho(a * b); // 30 (Multiplication) |
| 7 | dekho(a / b); // 3.333... (Division) |
| 8 | dekho(a % b); // 1 (Modulo - remainder) |
| 9 | dekho(a ** b); // 1000 (Power: 10^3) |
| 10 | |
| 11 | // String concatenation with + |
| 12 | dhoro greeting = "Hello" + " " + "World"; |
| 13 | dekho(greeting); // "Hello World" |
Comparison Operators
| Operator | Name | Example | Result |
|---|---|---|---|
== | Equal | 5 == 5 | sotti |
!= | Not Equal | 5 != 3 | sotti |
< | Less Than | 3 < 5 | sotti |
> | Greater Than | 5 > 3 | sotti |
<= | Less or Equal | 5 <= 5 | sotti |
>= | Greater or Equal | 5 >= 3 | sotti |
| 1 | dhoro x = 10; |
| 2 | dhoro y = 5; |
| 3 | |
| 4 | dekho(x == y); // mittha (false) |
| 5 | dekho(x != y); // sotti (true) |
| 6 | dekho(x < y); // mittha |
| 7 | dekho(x > y); // sotti |
| 8 | dekho(x <= 10); // sotti |
| 9 | dekho(x >= 10); // sotti |
| 10 | |
| 11 | // Comparing strings |
| 12 | dekho("apple" == "apple"); // sotti |
| 13 | dekho("abc" < "abd"); // sotti (lexicographic) |
Logical Operators
BanglaCode uses Bengali keywords for logical operators:
| Operator | Bengali | Meaning | Example | Result |
|---|---|---|---|---|
ebong | এবং | AND | sotti ebong mittha | mittha |
ba | বা | OR | sotti ba mittha | sotti |
na or ! | না | NOT | na sotti | mittha |
| 1 | // AND - both must be true |
| 2 | dekho(sotti ebong sotti); // sotti |
| 3 | dekho(sotti ebong mittha); // mittha |
| 4 | dekho(mittha ebong mittha); // mittha |
| 5 | |
| 6 | // OR - at least one must be true |
| 7 | dekho(sotti ba sotti); // sotti |
| 8 | dekho(sotti ba mittha); // sotti |
| 9 | dekho(mittha ba mittha); // mittha |
| 10 | |
| 11 | // NOT - inverts the value |
| 12 | dekho(na sotti); // mittha |
| 13 | dekho(na mittha); // sotti |
| 14 | dekho(!sotti); // mittha (alternative syntax) |
| 15 | |
| 16 | // Complex expressions |
| 17 | dhoro age = 25; |
| 18 | dhoro hasLicense = sotti; |
| 19 | |
| 20 | jodi (age >= 18 ebong hasLicense) { |
| 21 | dekho("Can drive!"); |
| 22 | } |
| 23 | |
| 24 | jodi (age < 13 ba age > 65) { |
| 25 | dekho("Special discount!"); |
| 26 | } |
Assignment Operators
| Operator | Example | Equivalent To |
|---|---|---|
= | x = 5 | Assign 5 to x |
+= | x += 3 | x = x + 3 |
-= | x -= 3 | x = x - 3 |
*= | x *= 3 | x = x * 3 |
/= | x /= 3 | x = x / 3 |
| 1 | dhoro x = 10; |
| 2 | |
| 3 | x += 5; // x is now 15 |
| 4 | dekho(x); |
| 5 | |
| 6 | x -= 3; // x is now 12 |
| 7 | dekho(x); |
| 8 | |
| 9 | x *= 2; // x is now 24 |
| 10 | dekho(x); |
| 11 | |
| 12 | x /= 4; // x is now 6 |
| 13 | dekho(x); |
Unary Operators
| Operator | Name | Example | Result |
|---|---|---|---|
- | Negation | -5 | -5 |
! or na | Logical NOT | !sotti | mittha |
| 1 | dhoro num = 5; |
| 2 | dekho(-num); // -5 |
| 3 | dekho(-(-num)); // 5 |
| 4 | |
| 5 | dhoro flag = sotti; |
| 6 | dekho(!flag); // mittha |
| 7 | dekho(na flag); // mittha |
| 8 | dekho(!!flag); // sotti (double negation) |
Member Access Operators
| Operator | Name | Example | Use Case |
|---|---|---|---|
. | Dot notation | obj.prop | Access known property |
[] | Bracket notation | obj["prop"] | Dynamic property access |
| 1 | // Object property access |
| 2 | dhoro person = {naam: "Rahim", boyosh: 25}; |
| 3 | |
| 4 | dekho(person.naam); // "Rahim" (dot notation) |
| 5 | dekho(person["boyosh"]); // 25 (bracket notation) |
| 6 | |
| 7 | // Dynamic property name |
| 8 | dhoro key = "naam"; |
| 9 | dekho(person[key]); // "Rahim" |
| 10 | |
| 11 | // Array index access |
| 12 | dhoro arr = [10, 20, 30, 40]; |
| 13 | dekho(arr[0]); // 10 |
| 14 | dekho(arr[2]); // 30 |
| 15 | |
| 16 | // String character access |
| 17 | dhoro str = "Hello"; |
| 18 | dekho(str[0]); // "H" |
| 19 | dekho(str[4]); // "o" |
| 20 | |
| 21 | // Nested access |
| 22 | dhoro data = { |
| 23 | users: [ |
| 24 | {naam: "A"}, |
| 25 | {naam: "B"} |
| 26 | ] |
| 27 | }; |
| 28 | dekho(data.users[0].naam); // "A" |
Operator Precedence
Operators are evaluated in the following order (highest to lowest):
| Priority | Operators | Description |
|---|---|---|
| 1 (highest) | [], . | Member access |
| 2 | () | Function call |
| 3 | -, !, na | Unary operators |
| 4 | ** | Exponentiation |
| 5 | *, /, % | Multiplication, division |
| 6 | +, - | Addition, subtraction |
| 7 | <, >, <=, >= | Comparison |
| 8 | ==, != | Equality |
| 9 | ebong | Logical AND |
| 10 | ba | Logical OR |
| 11 (lowest) | =, +=, etc. | Assignment |
| 1 | // Precedence examples |
| 2 | dekho(2 + 3 * 4); // 14 (not 20, * before +) |
| 3 | dekho((2 + 3) * 4); // 20 (parentheses override) |
| 4 | |
| 5 | dekho(2 ** 3 ** 2); // 512 (right-to-left: 2^(3^2) = 2^9) |
| 6 | |
| 7 | dekho(5 > 3 ebong 2 < 4); // sotti (comparison before AND) |
| 8 | |
| 9 | // Use parentheses for clarity |
| 10 | dhoro result = (a + b) * (c - d); |