From 4237c7db7acdd4cd1d4d48cc324fd6df0758f378 Mon Sep 17 00:00:00 2001 From: Luke Date: Fri, 25 Apr 2025 14:41:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=A4=8D=E6=9D=82=E7=9A=84?= =?UTF-8?q?=E5=B5=8C=E5=A5=97=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test | 191 ++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 151 insertions(+), 40 deletions(-) diff --git a/test b/test index d2eb11e..cb9adee 100644 --- a/test +++ b/test @@ -52,61 +52,172 @@ module: MainModule end body end function + function: main + parameter: + declare args: string + return_type: void + body: + declare input_number: int = BuiltinUtils.to_int(args) - 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 - 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)) - 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)) + if i > 2 then + BuiltinUtils.print("i is greater than 2") loop: initializer: - declare j: int = 0 + declare k: int = 0 condition: - j < i + k < 3 update: - j = j + 1 + k = k + 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 + BuiltinUtils.print("k = " + BuiltinUtils.to_string(k)) + + if k == 2 then + BuiltinUtils.print("k is two") + + loop: + initializer: + declare n: int = 0 + condition: + n < 2 + update: + n = n + 1 + body: + BuiltinUtils.print("n = " + BuiltinUtils.to_string(n)) + + if n == 1 then + BuiltinUtils.print("n is one") + + if i > 3 then + BuiltinUtils.print("deep i > 3 block") + + loop: + initializer: + declare x: int = 0 + condition: + x < 2 + update: + x = x + 1 + body: + if x == 1 then + BuiltinUtils.print("x is one at depth") + else + BuiltinUtils.print("x is zero at depth") + end if + end body + end loop + end if + end if + end body + end loop 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 + else + BuiltinUtils.print("i is odd: " + BuiltinUtils.to_string(i)) - declare final_message: string = StringUtils.concatenate("Finished with input: ", BuiltinUtils.to_string(input_number)) - BuiltinUtils.print(final_message) - end body + 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") + + if j > 2 then + BuiltinUtils.print("j > 2, deeper if") + + loop: + initializer: + declare y: int = 0 + condition: + y < 2 + update: + y = y + 1 + body: + BuiltinUtils.print("y in deep even j loop: " + BuiltinUtils.to_string(y)) + if y == 1 then + BuiltinUtils.print("y is one") + end if + end body + end loop + end if + + else + BuiltinUtils.print("j odd") + + loop: + initializer: + declare m: int = 0 + condition: + m < 2 + update: + m = m + 1 + body: + BuiltinUtils.print("m = " + BuiltinUtils.to_string(m)) + + if m == 1 then + BuiltinUtils.print("m is one") + + if j > 3 then + BuiltinUtils.print("j > 3, going deeper") + + loop: + initializer: + declare z: int = 0 + condition: + z < 2 + update: + z = z + 1 + body: + BuiltinUtils.print("z = " + BuiltinUtils.to_string(z)) + end body + end loop + end if + end if + end body + end loop + 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