106 lines
3.1 KiB
Plaintext
106 lines
3.1 KiB
Plaintext
module: CommonTasks
|
|
function: add_numbers
|
|
body:
|
|
return num1 + num2
|
|
end body
|
|
parameter:
|
|
declare num1: int
|
|
declare num2: int
|
|
return_type: int
|
|
end function
|
|
end module
|
|
|
|
module: MathUtils
|
|
function: square_number
|
|
parameter:
|
|
declare number: int
|
|
return_type: int
|
|
body:
|
|
return number * number
|
|
end body
|
|
end function
|
|
end module
|
|
|
|
module: StringUtils
|
|
function: concatenate
|
|
parameter:
|
|
declare first_str: string
|
|
declare second_str: string
|
|
return_type: string
|
|
body:
|
|
return first_str + second_str
|
|
end body
|
|
end function
|
|
end module
|
|
|
|
module: MainModule
|
|
import: CommonTasks, MathUtils, StringUtils, BuiltinUtils
|
|
|
|
function: test
|
|
parameter:
|
|
declare first_str: string
|
|
declare second_str: string
|
|
return_type: string
|
|
body:
|
|
return first_str + second_str
|
|
end body
|
|
end function
|
|
|
|
function: main
|
|
parameter:
|
|
declare args: string
|
|
return_type: void
|
|
body:
|
|
declare input_number: int = BuiltinUtils.to_int(args)
|
|
|
|
if input_number <= 0 then
|
|
input_number = 5
|
|
end if
|
|
|
|
loop:
|
|
initializer:
|
|
declare i: int = 0
|
|
condition:
|
|
i < input_number
|
|
update:
|
|
i = i + 1
|
|
body:
|
|
if i % 2 == 0 then
|
|
BuiltinUtils.print("i is even: " + BuiltinUtils.to_string(i))
|
|
else
|
|
BuiltinUtils.print("i is odd: " + BuiltinUtils.to_string(i))
|
|
|
|
loop:
|
|
initializer:
|
|
declare j: int = 0
|
|
condition:
|
|
j < i
|
|
update:
|
|
j = j + 1
|
|
body:
|
|
if j == 1 then
|
|
BuiltinUtils.print("first inner")
|
|
else
|
|
if j % 2 == 0 then
|
|
BuiltinUtils.print("j even")
|
|
else
|
|
BuiltinUtils.print("j odd")
|
|
end if
|
|
end if
|
|
end body
|
|
end loop
|
|
end if
|
|
|
|
declare sum: int = CommonTasks.add_numbers(i, 10)
|
|
declare squared: int = MathUtils.square_number(sum)
|
|
BuiltinUtils.print(" i+10 squared = " + BuiltinUtils.to_string(squared))
|
|
end body
|
|
end loop
|
|
|
|
declare final_message: string = StringUtils.concatenate("Finished with input: ", BuiltinUtils.to_string(input_number))
|
|
BuiltinUtils.print(final_message)
|
|
end body
|
|
end function
|
|
|
|
end module
|