npm install -g kalkatia-lang 📋npm installation
npm install -g kalkatia-lang
Create a file test.kalkatia:
mama x = 10; chakallas(x);
Use KalkatiaLang in a JavaScript project.
import KalkatiaLang from "kalkatia-lang";
const code = `
mama x = 20;
chakallas(x);
`;
const translatedCode = KalkatiaLang.translate(code);
console.log("Translated JavaScript Code:");
console.log(translatedCode);
eval(translatedCode);In KPL, variables are declared using the keyword 'mama' followed by the variable name.
mama x = 5; chakallas(x);
Arrays are declared using 'aasteLadees'. This is how you declare an array with multiple values.
mama y = aasteLadees(1, 2, 3, 4, 5); chakallas(y);
To print values to the console, use 'chakallas'.
chakallas("Hello, MamaLog");KPL provides a loop structure using 'ayiChakkar'. The loop consists of variable assignment, condition, and increment/decrement operation.
mama i = 0;
ayiChakkar(i = 0; i < 5; i++) {
chakallas("Tumra value: " + i);
}KPL has a straightforward if-else block, where 'mamaAgar' represents the if condition and 'naiTohMama' represents the else.
mama z = 4;
mamaAgar(z > 5) {
chakallas("z bada hai");
}
naiTohMama {
chakallas("z chota h");
}In KPL, functions are defined using 'dhabbaji'. The function definition starts with 'dhabbaji', followed by the function name and parameters.
dhabbaji add(a, b) {
khuljao(a + b);
}
mama result = add(5, 10);
chakallas(result);KPL uses 'aar' for logical AND and 'ya' for logical OR.
mama x = 5;
mama y = 10;
mamaAgar(x > 3 aar y < 20) {
chakallas("Both conditions are true");
}
naiTohMama {
chakallas("One or both conditions are false");
}For switch-case functionality, we use 'jaundice', instead of break we use 'dharlis'.
mama day = 2;
jaundice(day) {
case 1:
chakallas("Soombaar");
dharlis;
case 2:
chakallas("Mangal");
dharlis;
default:
chakallas("itwaaar");
}For returning values, we use 'khuljao'.
dhabbaji add(a, b) {
khuljao(a + b);
}
mama result = add(5, 10);
chakallas(result);BubbleSort Algo
// Bubble Sort in KolkataLang
dhabbaji bubbleSort(arr) {
mama n = arr.length;
mama i = 0; // Declare 'i' outside the loop
mama j = 0; // Declare 'j' outside the loop
ayiChakkar(i = 0; i < n - 1; i++) { // Initialize 'i' without redeclaring
ayiChakkar(j = 0; j < n - i - 1; j++) { // Initialize 'j' without redeclaring
mamaAgar(arr[j] > arr[j + 1]) {
// Swap elements
mama temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
khuljao(arr); // Return the sorted array
}
// Test the bubbleSort function
mama arr = aasteLadees(64, 34, 25, 12, 22, 11, 90); // Create an array
chakallas("Unsorted array:");
chakallas(arr);
mama sortedArr = bubbleSort(arr); // Sort the array
chakallas("Sorted array:");
chakallas(sortedArr);