it's so easy to code Nilaa.
Operators
An operator performs some operation on single or multiple operands (data value) and produces a result. For example 1 + 2, where + sign is an operator and 1 is left operand and 2 is right operand. + operator adds two numeric values and produces a result which is 3 in this case.
You can also use Brackets to define the order of precedense in which these operators get executed. Power operators can be used as 2 ^ 2 which results in 4.
>> 1 + 2 * 3
>> (1 + 2) * 3
>> -4
>> 2 ^ 2
Output
>> 7
>> 9
>> 4
>> 4
Variables
Variable means anything that can vary. Nilaa includes variables which hold the data value and it can be changed anytime.
Nilaa uses reserved keyword MARI to declare a variable. A variable must have a unique name. You can assign a value to a variable using equal to (=) operator when you declare it or before using it.
>> MARI a = 5
>> MARI b = a/5
>> MARI c = "two"
Output
>> 5
>> 1.0
>> two
Comparison & Logical Operators
Comparison and Logical operators are used to test for true or false. Comparison operators are used in logical statements to determine equality or difference between variables or values. Logical operators are used to determine the logic between variables or values.
You can use UNMAI and POI to make TRUE or FALSE statements and use MATRUM and ALLA instead of AND and OR.
>> 5 == 5
>> 6 == 4
>> (2 + 8) == (5 + 5)
>> 6 != 4
>> 6 != 4 MATRUM 5 == 1
>> 5 < 6
>> UNMAI
>> POI
Output
>> 1
>> 0
>> 1
>> 1
>> 0
>> 1
>> 1
>> 0
IF Condition
Nilaa includes if-else conditional statements to control the program flow, similar to other programming languages.
JavaScript includes following forms of if-else conditions:
- ENDRAL condition
- ENDRAL-VERU condition
- VERUENDRAL condition
MUDI is used to define that the conditional statement is ended. ENIL is used after the condition and executes the following lines if the condition is true.
PATHIVU is the print function of Nilaa. It prints everything inside it.
>> ENDRAL 5 == 5 ENIL PATHIVU(123)
>> ENDRAL 5 != 5 ENIL PATHIVU(123) VERU PATHIVU(321)
>> ENDRAL 5 != 5 ENIL PATHIVU(123) VERUENDRAL 5 == 5 ENIL PATHIVU(312) VERU PATHIVU(321)
Output
>> 123
>> 321
>> 312
FOR loops
The FOR (IDHUVARAI) loop requires following three parts.
Initializer: Initialize a counter variable to start with
Condition: specify a condition that must evaluate to true for next iteration
Iteration: increase or decrease counter
>> MARI result = 1
>> IDHUVARAI i = 1 ILIRUNDHU 6 ENIL
>> MARI result = result * i
>> MUDI
>> PATHIVU(result)
Output
>> 120
WHILE loops
Nilaa includes WHILE (APPODHU) loop to execute code repeatedly till it satisfies a specified condition. Unlike for loop, while loop only requires condition expression.
>> MARI i = 1
>> APPODHU i < 100 ENIL
>> MARI i = i + 1
>> MUDI
>> PATHIVU(i)
Output
>> 100
Functions
Nilaa provides functions similar to most of the scripting and programming languages.
In Nilaa, a function allows you to define a block of code, give it a name and then execute it as many times as you want.
A Nilaa function can be defined using function (SEYAL) keyword.
>> SEYAL kootal(a, b)
>> PATHIVU(a + b)
>> MUDI
>> kootal(5, 5)
Output
>> 10
Strings
String is a primitive data type in Nilaa. A string is textual content. It must be enclosed in single or double quotation marks. You can use * to multiply the string the certain number of times mentioned after and use + to append another string.
>> "this is a "+"string"
>> "hello " * 3
>> SEYAL vanakkam(aal, murai)
>> PATHIVU("Vanakkam " * murai + aal)
>> MUDI
>> vanakkam("Nilaa", 3)
Output
>> "this is a string"
>> "hello hello hello"
>> Vanakkam Vanakkam Vanakkam Nilaa
Lists
A list (PATTIYAL) is created by placing all the items (elements) inside square brackets [], separated by commas.
You can add more elements to a list by using + followed by the element, use * to add two lists together and
/index number to get that value in list.
Append, Pop and Extend can be applied to a list by using SERKA(), NEEKKU() and NEETU() respectively.
>> [1, 2, 3, 4] + 5
>> [1, 2, 3] * [3, 4, 5]
>> [1, 2, 3] / 0
>> MARI pattiyal = [1, 2, 3]
>> SERKA(pattiyal, 4)
>> NEEKKU(pattiyal, 2)
>> NEETU(pattiyal, [4, 5, 6])
>> PATHIVU(pattiyal)
Output
>> [1, 2, 3, 4, 5]
>> [1, 2, 3, 3, 4, 5]
>> 1
>> 1, 2, 4, 4, 5, 6
Helper Functions
You can use IDHU_ENNAA(), IDHU_ELUTHAA(), IDHU_PATTIYALAA(), THIRUMBU, THODARU, NIRUTHU to find if a value is number, string, list or to return, continue and stop while writing your Nilaa program.
>> IDHU_ENNAA(5)
>> IDHU_ELUTHAA("Nilaa")
>> IDHU_PATTIYALAA([1, 2, 3])
Output
>> 1
>> 1
>> 1
>> THIRUMBU Example
>> SEYAL anupu()
>> MARI i = 5
>> THIRUMBU i
>> MUDI
>> anupu()
Output
>> 5
>> THODARU & NIRUTHU Example
>> MARI a = []
>> IDHUVARAI i = 0 ILIRUNDHU 10 ENIL
>> ENDRAL i == 4 ENIL
>> THODARU
>> VERUENDRAL i == 8 ENIL
>> NIRUTHU
>> MUDI
>> MARI a = a + i
>> MUDI
>> PATHIVU(a)
Output
>> 0, 1, 2, 3, 5, 6, 7