Syntax of SRON
A scope of a SRON's code starts with a function and it is started with an open curly brace '{' and ended with a close curly brace '}'. Almost all instructions inside a function are written in the below format:
attribute : statement
Attribute defines the types of statement and is used to tell the compiler that this statement is written with XYZ intention. There are many attributes provides in SRON:
1) name : this attribute is used to declare a function name.
{
name : function_name
}
2) args : this attribute is used to declare a function arguments.
{
name : fnc
args : (Int a, String b)
}
{
name : MAIN
args : (List arglist)
}
3) console : this attribute is used to print values on the terminal/command line.
{
name : MAIN
console : ("Hello, World!")
}
4) type : this attribute is used to set the return type of the function
{
name : get_int
type : Int
return : 27062003
}
5) return : this attribute is used to return a value from a function
{
name : get_pi
return : PI
}
6) for : this attribute is used to declare a for-loop.
{
name : MAIN
for : {
range : (Int i = 0, 5)
console : ( i , '\n')
}
}
7) range : this attribute is used to declare the range of for-loop.
{
name : MAIN
for : {
range : (Int i = 0, 10 , 2)
console : ( i , '\n' )
}
}
8) while : this attribute is used to declare a while loop.
{
name : MAIN
while : {
condition : true
console : ( "SRON\n" )
}
}
9) condition : this attribute is used to check if the given condition is true or false. This attribute is used with 'while', 'if' and 'elif' attributes.
{
name : MAIN
while : {
condition : false
@ the statement of condition attribute only requires a 'Bool' type value.
}
}
10) if : this attribute is used to declare a if statement.
{
name : MAIN
Any val = 10
if : {
@ the integer value can be converted to boolean type value
condition : val
println(val)
}
}
11) elif : this attribute is used to declare an elif statement.
{
name : MAIN
Int val = 9
if : {
condition : ~{ val%2 == 0 }~
println("Even")
}
elif : {
condition : ~{ val%3 == 0 }~
@ the control flow will come here only if the code within the 'if'
@ attribute will not be executed.
println("Divisible by Three")
}
}
12) else : this attribute is used to declare a else statement.
{
name : MAIN
variables : Int val = 7
if : {
condition : ~{ val%2 == 0 }~
println("Even")
}
else : {
println("Odd")
@ this statement will execute only if the above
@ if-attribute is not executed.
}
}
13) foreach : this attribute is used to iterate linearly over String or List.
{
name : main
foreach : {
@ 'on' attribute is used to specify on what value
@ will the foreach will iterate with what variable
on : Any val, [1,2,3,4,5]
println(val)
}
}
14) rotate : this attribute is used to rotate value or swap value.
{
name : main
Int val1 = 91
Double val2 = 1001.27112
String val3 = "SRON"
console : (val1, ' ', val2 , ' ' , val3)
rotate : (val1 , val2, val3)
console : (val1, ' ', val2 , ' ' , val3)
}
Last updated