A toy programming language to learn coding in Kannada, written in TypeScript.
Kannadigarinda, Kannadigarigoskara 🔥 (Forked from BhaiLang)
Playground ·
Documentation ·
Engineering in Kannada
namaskara
kelasa factorial(n) {
enadru (n <= 1) {
kodu 1;
}
kodu n * factorial(n - 1);
}
prathi (idu i = 1; i <= 5; i += 1) {
helu i + "! =", factorial(i);
}
matte sigona
Every keyword can also be written in Kannada script:
ನಮಸ್ಕಾರ
ಇದು ಹೆಸರು = "ಕನ್ನಡ";
ಹೇಳು "ನಮಸ್ಕಾರ " + ಹೆಸರು;
ಮತ್ತೆ ಸಿಗೋಣ
npm i -g kannada-script
Create a file, for example hello.kans, and write your program in it:
namaskara
helu "Namaskara Jagattu!";
matte sigona
Run it:
kannadascript hello.kans
Or skip the install and use the online playground: examples, sharable links,
input for kelu(), a one-click switch between English letters and ಕನ್ನಡ ಲಿಪಿ, and errors that point at the line.
| Keyword | ಕನ್ನಡ | Meaning | Like |
|---|---|---|---|
namaskara |
ನಮಸ್ಕಾರ | hello, program starts | |
matte sigona |
ಮತ್ತೆ ಸಿಗೋಣ | see you again, program ends | |
helu |
ಹೇಳು | say | console.log |
idu |
ಇದು | this is | let |
enadru |
ಏನಾದ್ರು | if ever | if |
illa andre |
ಇಲ್ಲ ಅಂದ್ರೆ | if not | else if |
enu illa andre |
ಏನು ಇಲ್ಲ ಅಂದ್ರೆ | if nothing else | else |
ellivargu |
ಎಲ್ಲಿವರೆಗೂ | until when | while |
prathi |
ಪ್ರತಿ | for every | for |
saaku nilsu |
ಸಾಕು ನಿಲ್ಸು | enough, stop | break |
munde nodu |
ಮುಂದೆ ನೋಡು | look ahead | continue |
kelasa |
ಕೆಲಸ | work | function |
kodu |
ಕೊಡು | give | return |
sari / thappu |
ಸರಿ / ತಪ್ಪು | right / wrong | true / false |
khali |
ಖಾಲಿ | empty | null |
mattu / athava / alla |
ಮತ್ತು / ಅಥವಾ / ಅಲ್ಲ | and / or / not | && / || / ! |
namaskara is the entrypoint for the program and all program must end with matte sigona. Anything outside of it will be ignored.
This will be ignored
namaskara
// Write code here
/* multi line
comments too */
matte sigona
This too
Variables are declared using idu. Numbers and strings work like in other languages (strings support escapes like \n and \"). sari and thappu are the booleans, khali is null and [ ] creates an array. Kannada letters and digits (೦-೯) work in names and numbers.
namaskara
idu a = 10;
idu b = "two", c;
idu d = [1, 'mooru', sari, khali];
a += 1;
helu a, b, c, d;
matte sigona
Arithmetic + - * / %, comparison == != < <= > >=, logical mattu (&&), athava (||), alla (!), and the assignments = += -= *= /= %=.
namaskara
idu a = 7;
helu a + 3, a % 3, -a, (a > 5) mattu (a < 10), alla sari;
matte sigona
Use helu to print anything to console.
namaskara
helu "Hello World";
helu 5, 'ok', khali, sari, thappu;
matte sigona
| Function | ಕನ್ನಡ | What it does |
|---|---|---|
uddha(x) |
ಉದ್ದ | length of a string or array |
serisu(list, x) |
ಸೇರಿಸು | adds x to the end of an array |
tegi(list) |
ತೆಗಿ | removes and returns the last element |
sankhye(x) |
ಸಂಖ್ಯೆ | converts to a number |
pada(x) |
ಪದ | converts to a string |
poorna(x) |
ಪೂರ್ಣ | rounds down to a whole number |
kelu(prompt) |
ಕೇಳು | reads a line of input |
The enadru block runs if its condition is sari, otherwise the first illa andre block whose condition is sari runs, and finally the enu illa andre block. thappu, khali, 0 and "" count as false.
namaskara
idu a = 10;
enadru (a < 20) {
helu "a is less than 20";
} illa andre ( a < 25 ) {
helu "a is less than 25";
} enu illa andre {
helu "a is greater than or equal to 25";
}
matte sigona
ellivargu repeats while its condition is sari, prathi is a counting loop. Use saaku nilsu to break the loop and munde nodu to continue.
namaskara
idu a = 0;
ellivargu (a < 10) {
a += 1;
enadru (a == 5) {
munde nodu;
}
enadru (a == 7) {
saaku nilsu;
}
helu a;
}
prathi (idu i = 1; i <= 3; i += 1) {
helu i, "x 9 =", i * 9;
}
matte sigona
Declare functions with kelasa and return a value with kodu. Functions support recursion and closures, and can be passed around as values.
namaskara
kelasa jodisu(a, b) {
kodu a + b;
}
helu jodisu(2, 3);
matte sigona
namaskara
idu hesaru = kelu("Ninna hesaru? ");
idu hannu = ["mavu", "bale"];
serisu(hannu, "halasu");
hannu[0] = "seebe";
helu "Namaskara " + hesaru, hannu, uddha(hannu);
matte sigona
To work on Kannada Script itself, build it from source:
git clone https://github.com/chandansgowda/kannada-script.git
cd kannada-script
npm install
npm run build # parser, interpreter, CLI and the playground
npm run test
npm run dev # website at http://localhost:3000
node packages/cli/bin/index.js hello.kans # run the CLI you built
The CLI is published from packages/cli (cd packages/cli && npm publish).
The repo has packages/parser (tokenizer + recursive descent parser producing an AST), packages/interpreter (tree-walking interpreter), packages/cli and apps/docs (the website & playground). You can explore the abstract syntax tree (AST) of kannadascript here.