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

OperatorNameExampleResult
+Addition5 + 38
-Subtraction5 - 32
*Multiplication5 * 315
/Division10 / 42.5
%Modulo10 % 31
**Exponent2 ** 38
1dhoro a = 10;
2dhoro b = 3;
3
4dekho(a + b); // 13 (Addition)
5dekho(a - b); // 7 (Subtraction)
6dekho(a * b); // 30 (Multiplication)
7dekho(a / b); // 3.333... (Division)
8dekho(a % b); // 1 (Modulo - remainder)
9dekho(a ** b); // 1000 (Power: 10^3)
10
11// String concatenation with +
12dhoro greeting = "Hello" + " " + "World";
13dekho(greeting); // "Hello World"

Comparison Operators

OperatorNameExampleResult
==Equal5 == 5sotti
!=Not Equal5 != 3sotti
<Less Than3 < 5sotti
>Greater Than5 > 3sotti
<=Less or Equal5 <= 5sotti
>=Greater or Equal5 >= 3sotti
1dhoro x = 10;
2dhoro y = 5;
3
4dekho(x == y); // mittha (false)
5dekho(x != y); // sotti (true)
6dekho(x < y); // mittha
7dekho(x > y); // sotti
8dekho(x <= 10); // sotti
9dekho(x >= 10); // sotti
10
11// Comparing strings
12dekho("apple" == "apple"); // sotti
13dekho("abc" < "abd"); // sotti (lexicographic)

Logical Operators

BanglaCode uses Bengali keywords for logical operators:

OperatorBengaliMeaningExampleResult
ebongএবংANDsotti ebong mitthamittha
baবাORsotti ba mitthasotti
na or !নাNOTna sottimittha
1// AND - both must be true
2dekho(sotti ebong sotti); // sotti
3dekho(sotti ebong mittha); // mittha
4dekho(mittha ebong mittha); // mittha
5
6// OR - at least one must be true
7dekho(sotti ba sotti); // sotti
8dekho(sotti ba mittha); // sotti
9dekho(mittha ba mittha); // mittha
10
11// NOT - inverts the value
12dekho(na sotti); // mittha
13dekho(na mittha); // sotti
14dekho(!sotti); // mittha (alternative syntax)
15
16// Complex expressions
17dhoro age = 25;
18dhoro hasLicense = sotti;
19
20jodi (age >= 18 ebong hasLicense) {
21 dekho("Can drive!");
22}
23
24jodi (age < 13 ba age > 65) {
25 dekho("Special discount!");
26}

Assignment Operators

OperatorExampleEquivalent To
=x = 5Assign 5 to x
+=x += 3x = x + 3
-=x -= 3x = x - 3
*=x *= 3x = x * 3
/=x /= 3x = x / 3
1dhoro x = 10;
2
3x += 5; // x is now 15
4dekho(x);
5
6x -= 3; // x is now 12
7dekho(x);
8
9x *= 2; // x is now 24
10dekho(x);
11
12x /= 4; // x is now 6
13dekho(x);

Unary Operators

OperatorNameExampleResult
-Negation-5-5
! or naLogical NOT!sottimittha
1dhoro num = 5;
2dekho(-num); // -5
3dekho(-(-num)); // 5
4
5dhoro flag = sotti;
6dekho(!flag); // mittha
7dekho(na flag); // mittha
8dekho(!!flag); // sotti (double negation)

Member Access Operators

OperatorNameExampleUse Case
.Dot notationobj.propAccess known property
[]Bracket notationobj["prop"]Dynamic property access
1// Object property access
2dhoro person = {naam: "Rahim", boyosh: 25};
3
4dekho(person.naam); // "Rahim" (dot notation)
5dekho(person["boyosh"]); // 25 (bracket notation)
6
7// Dynamic property name
8dhoro key = "naam";
9dekho(person[key]); // "Rahim"
10
11// Array index access
12dhoro arr = [10, 20, 30, 40];
13dekho(arr[0]); // 10
14dekho(arr[2]); // 30
15
16// String character access
17dhoro str = "Hello";
18dekho(str[0]); // "H"
19dekho(str[4]); // "o"
20
21// Nested access
22dhoro data = {
23 users: [
24 {naam: "A"},
25 {naam: "B"}
26 ]
27};
28dekho(data.users[0].naam); // "A"

Operator Precedence

Operators are evaluated in the following order (highest to lowest):

PriorityOperatorsDescription
1 (highest)[], .Member access
2()Function call
3-, !, naUnary operators
4**Exponentiation
5*, /, %Multiplication, division
6+, -Addition, subtraction
7<, >, <=, >=Comparison
8==, !=Equality
9ebongLogical AND
10baLogical OR
11 (lowest)=, +=, etc.Assignment
1// Precedence examples
2dekho(2 + 3 * 4); // 14 (not 20, * before +)
3dekho((2 + 3) * 4); // 20 (parentheses override)
4
5dekho(2 ** 3 ** 2); // 512 (right-to-left: 2^(3^2) = 2^9)
6
7dekho(5 > 3 ebong 2 < 4); // sotti (comparison before AND)
8
9// Use parentheses for clarity
10dhoro result = (a + b) * (c - d);