This is official repository for kannada-script (Forked from BhaiLang)
Kannada Script is a toy programming language written in Typescript.
npm i -g kannada-script
Edit the file with a text editor. You can also try out your code on Kannada Script PlayGround
namaskara
helu "Hello anna";
matte sigona
kannadascript test.kans
hello anna
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
matte sigona
This too
Variables can be declared using idu
.
namaskara
idu a = 10;
idu b = "two";
idu c = 15;
a = a + 1;
b = 21;
c *= 2;
matte sigona
Numbers and strings are like other languages. Null values can be denoted using khali
. sari
and thappu
are the boolean values.
namaskara
idu a = 10;
idu b = 10 + (15*20);
idu c = "two";
idu d = 'ok';
idu e = khali;
idu f = sari;
idu g = thappu;
matte sigona
Use helu
to print anything to console.
namaskara
helu "Hello World";
idu a = 10;
{
idu b = 20;
helu a + b;
}
helu 5, 'ok', khali , sari , thappu;
matte sigona
kannadascript supports if-else-if ladder construct , enadru
block will execute if condition is sari
, otherwise one of the subsequently added illa andre
blocks will execute if their respective condition is sari
, and the enu illa andre
block will eventually execute if all of the above conditions are thappu
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
Statements inside ellivargu
blocks are executed as long as a specified condition evaluates to sari. If the condition becomes thappu
, statement within the loop stops executing and control passes to the statement following the loop. Use saaku nilsu
to break the loop and munde nodu
to continue within loop.
namaskara
idu a = 0;
ellivargu (a < 10) {
a += 1;
enadru (a == 5) {
helu "loop olaginda helu ", a;
munde nodu;
}
enadru (a == 6) {
saaku nilsu;
}
helu a;
}
helu "done";
matte sigona
You can explore abstract syntax tree(AST) of kannadascript here.