it's so easy to code Nilaa.
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
>> 2 ^ 2
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"
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
Nilaa includes if-else conditional statements to control the program flow, similar to other programming languages.
- 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)
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
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
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)
>> kootal(5, 5)
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)
>> vanakkam("Nilaa", 3)
>> "this is a string"
>> "hello hello hello"
>> Vanakkam Vanakkam Vanakkam Nilaa
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])
>> [1, 2, 3, 4, 5]
>> [1, 2, 3, 3, 4, 5]
>> 1, 2, 4, 4, 5, 6
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_PATTIYALAA([1, 2, 3])
>> THIRUMBU Example
>> SEYAL anupu()
>> MARI i = 5
>> THIRUMBU i
>> THODARU & NIRUTHU Example
>> MARI a = 
>> IDHUVARAI i = 0 ILIRUNDHU 10 ENIL
>> ENDRAL i == 4 ENIL
>> VERUENDRAL i == 8 ENIL
>> MARI a = a + i
>> 0, 1, 2, 3, 5, 6, 7