Skip to content
This repository was archived by the owner on Aug 18, 2025. It is now read-only.

Commit a0687da

Browse files
committed
新增hata.cn文件,包含基本的数学运算、字符串处理和控制结构示例,展示命名空间的使用和函数调用逻辑。
1 parent 5caaaae commit a0687da

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

hata.cn

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
using lib <io>;
2+
using lib <time>;
3+
using ns math;
4+
using ns utils::string;
5+
6+
// 常量定义
7+
const MAX_COUNT : int = 100;
8+
const PI : float = 3.14159;
9+
const APP_NAME : string = "CodeNothing Demo";
10+
11+
// 命名空间定义
12+
ns math {
13+
fn add(a : int, b : int) : int {
14+
return a + b;
15+
};
16+
17+
fn multiply(a : int, b : int) : int {
18+
return a * b;
19+
};
20+
};
21+
22+
// 嵌套命名空间
23+
ns utils {
24+
ns string {
25+
fn reverse(text : string) : string {
26+
// 调用库函数进行字符串处理
27+
return text; // 简化实现
28+
};
29+
};
30+
};
31+
32+
fn main() : int {
33+
using ns math;
34+
using ns utils::string;
35+
// 变量声明和赋值
36+
counter : int = 0;
37+
message : string = "Hello, CodeNothing!";
38+
is_running : bool = true;
39+
40+
// 使用库函数输出
41+
std::println(APP_NAME);
42+
std::println("开始演示核心语句...");
43+
44+
// 导入命名空间
45+
46+
47+
// 条件语句
48+
if (counter < MAX_COUNT && is_running) {
49+
std::println("条件满足,继续执行");
50+
} else {
51+
std::println("条件不满足");
52+
};
53+
54+
// for循环
55+
for (i : 1..5) {
56+
counter += i;
57+
58+
if (i == 3) {
59+
std::println("跳过i=3");
60+
continue;
61+
};
62+
63+
result : int = add(i, counter);
64+
std::println("i=" + i + ", result=" + result);
65+
};
66+
67+
// while循环
68+
temp : int = 0;
69+
while (temp < 3) {
70+
temp++;
71+
std::println("while循环: " + temp);
72+
73+
if (temp >= 2) {
74+
break;
75+
};
76+
};
77+
78+
// 自增自减操作
79+
num : int = 10;
80+
num++; // 后置自增
81+
++num; // 前置自增
82+
num -= 5; // 复合赋值
83+
84+
// 命名空间函数调用
85+
sum : int = math::multiply(num, 2);
86+
std::println("最终结果: " + sum);
87+
88+
// 嵌套命名空间调用
89+
90+
reversed : string = reverse("test");
91+
92+
return 0;
93+
};

0 commit comments

Comments
 (0)