Skip to content

Commit 7917869

Browse files
committed
英文目录框架建立
1 parent 1a34f2d commit 7917869

30 files changed

+1035
-10
lines changed

docs/.vitepress/sidebar.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ export const sidebar : DefaultTheme.Sidebar = {
5252
{
5353
text: "泛型",
5454
items: [
55+
{"text": "编译确定量", link: "/zh/quickstart/07generic/01concrete_var"},
56+
{"text": "泛型函数", link: "/zh/quickstart/07generic/02generic_function"},
57+
{"text": "泛型类", link: "/zh/quickstart/07generic/03generic_class"}
5558
]
5659
},
5760
{
@@ -82,5 +85,88 @@ export const sidebar : DefaultTheme.Sidebar = {
8285
{ text: "Gradle配置和使用", link: "/zh/quickstart/11gradle/01gradle-configuration" }
8386
]
8487
}
88+
],
89+
"/en/quickstart/":[
90+
{
91+
text: "Project Configure",
92+
items: [
93+
{ text: "Create Project", link: "/en/quickstart/01project/01create-project" },
94+
{ text: "Configuration File", link: "/en/quickstart/01project/02config-file" }
95+
]
96+
},
97+
{
98+
text: "Basic Syntax",
99+
items: [
100+
{ text: "Variable", link: "/en/quickstart/02base/01variables" },
101+
{ text: "Comments", link: "/en/quickstart/02base/02comments" },
102+
{ text: "Logic Statement", link: "/en/quickstart/02base/03logic-statements" },
103+
{ text: "Top Statement", link: "/en/quickstart/02base/04top-statements" }
104+
]
105+
},
106+
{
107+
text: "Namespace",
108+
items: [
109+
{ text: "Namespace", link: "/en/quickstart/03namespace/01namespace" }
110+
]
111+
},
112+
{
113+
text: "Function",
114+
items: [
115+
{ text: "Definition and Calling", link: "/en/quickstart/04function/01define-and-call" },
116+
{ text: "Static Parameter", link: "/en/quickstart/04function/02static-params" },
117+
{ text: "Inline Function", link: "/en/quickstart/04function/03inline-function" },
118+
{ text: "Compile-time Function", link: "/en/quickstart/04function/04compiletime-function" }
119+
]
120+
},
121+
{
122+
text: "Class",
123+
items: [
124+
{ text: "Define and instantiate", link: "/en/quickstart/05class/01define-and-instantiate" },
125+
{ text: "Class Field", link: "/en/quickstart/05class/02member" },
126+
{ text: "Inheritance and Abstract", link: "/en/quickstart/05class/03inheritance-abstract" }
127+
]
128+
},
129+
{
130+
text: "Interface",
131+
items: [
132+
{ text: "Define and Implement", link: "/en/quickstart/06interface/01define-and-implement" }
133+
]
134+
},
135+
{
136+
text: "Generic",
137+
items: [
138+
{"text": "Concrete Var", link: "/en/quickstart/07generic/01concrete_var"},
139+
{"text": "Generic Function", link: "/en/quickstart/07generic/02generic_function"},
140+
{"text": "Generic Class", link: "/en/quickstart/07generic/03generic_class"}
141+
]
142+
},
143+
{
144+
text: "Template",
145+
items: [
146+
{ text: "Define and instantiate", link: "/en/quickstart/08template/01define-and-instantiate" },
147+
{ text: "Template Parameter", link: "/en/quickstart/08template/02template-parameters" }
148+
]
149+
},
150+
{
151+
text: "Libary",
152+
items: [
153+
{ text: "Import and Use", link: "/en/quickstart/09library/01import-and-use" },
154+
{ text: "Export", link: "/en/quickstart/09library/02export-library" }
155+
]
156+
},
157+
{
158+
text: "MNI Framework",
159+
items: [
160+
{ text: "Introduce", link: "/en/quickstart/10mni/01mni-framework" },
161+
{ text: "Implementation", link: "/en/quickstart/10mni/02mni-framework-implementation" },
162+
{ text: "Use var and function in Java", link: "/en/quickstart/10mni/03javavar" },
163+
]
164+
},
165+
{
166+
text: "Develop with Gradle",
167+
items: [
168+
{ text: "Configure and use gradle", link: "/en/quickstart/11gradle/01gradle-configuration" }
169+
]
170+
}
85171
]
86172
}

docs/en/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ hero:
99
actions:
1010
- theme: brand
1111
text: QuickStart
12-
link: /zh/quickstart/index
12+
link: /en/quickstart/index
1313
- theme: alt
1414
text: Overview
1515
link: /en/overview
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TODO
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TODO
File renamed without changes.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
lastUpdated: true
3+
---
4+
5+
# 逻辑语句
6+
7+
::: tip
8+
MCFPP中的逻辑语句和C/Java中的逻辑语句完全一致。如果你对其他语言足够熟悉,你可以跳过这一节。
9+
:::
10+
11+
## if语句
12+
13+
`if`语句是一种条件语句,它用来判断一个条件是否成立。如果条件成立,那么`if`语句中的代码块将会被执行。`if`语句的语法如下:
14+
15+
```mcfpp
16+
if (condition){
17+
#code
18+
}
19+
```
20+
21+
`condition`是一个布尔表达式,它的值为`true``false`。如果`condition`的值为`true`,那么`#code`中的代码块将会被执行。
22+
23+
`if`语句还可以和`else`语句一起使用,`else`语句用来在`if`语句的条件不成立时执行代码块。`if-else`语句的语法如下:
24+
25+
```mcfpp
26+
if (condition){
27+
#code1
28+
}else{
29+
#code2
30+
}
31+
```
32+
33+
`condition`是一个布尔表达式,它的值为`true``false`。如果`condition`的值为`true`,那么`#code1`中的代码块将会被执行;否则,`#code2`中的代码块将会被执行。
34+
35+
可以使用`else if`语句用来在`if`语句的条件不成立时判断另一个条件。`if-else if-else`语句的语法如下:
36+
37+
```mcfpp
38+
if (condition1){
39+
#code1
40+
}else if (condition2){
41+
#code2
42+
}else{
43+
#code3
44+
}
45+
```
46+
47+
## while语句和do-while语句
48+
49+
`while`语句是一种循环语句,它用来重复执行一个代码块,直到条件不成立。`while`语句的语法如下:
50+
51+
```mcfpp
52+
while (condition){
53+
#code
54+
}
55+
```
56+
57+
`condition`是一个布尔表达式。如果`condition`的值为`true`,那么则执行`#code`代表的代码块。此后,再次判断`condition`的值,如果`condition`的值为`true`,那么`#code`代表代码块将会被执行;如此循环,直到`condition`的值为`false`
58+
59+
`do-while`语句和`while`类似,但是无论条件是否成立,它都会先执行因此循环体中的语句,而后再判断条件来决定是否继续进行。`do-while`语句的语法如下:
60+
61+
```mcfpp
62+
do{
63+
#code
64+
}while (condition);
65+
```
66+
67+
## for语句
68+
69+
`for`语句是循环的一种稍复杂的版本,它的语法如下:
70+
71+
```mcfpp
72+
for (forinit; condition; forupdate){
73+
#code
74+
}
75+
```
76+
77+
`forinit`是一个初始化表达式,它用来初始化循环变量。`condition`是一个布尔表达式,它用来判断循环是否继续。`forupdate`是一个更新表达式,它用来更新循环变量。`#code`代表了循环体,即循环体中的代码。在运行的时候,`for`语句的执行过程如下:
78+
79+
1. 执行`forinit`,初始化循环变量。
80+
2. 判断`condition`的值,如果`condition`的值为`true`,则执行`#code`代表的代码块,然后执行`forupdate`,更新循环变量,再次判断`condition`的值。
81+
3. 如果`condition`的值为`false`,则退出循环。
82+
83+
`for`循环中,`forinit`声明的变量只在`for`循环中有效。
84+
85+
## break和continue语句
86+
87+
`break`语句用来跳出整个循环,`continue`语句用来跳过本次循环。例如:
88+
89+
```mcfpp
90+
for (int i = 0; i < 10; i++){
91+
if (i == 5){
92+
break;
93+
}
94+
if (i == 3){
95+
continue;
96+
}
97+
#code
98+
}
99+
```
100+
101+
在上面的例子中,当`i`的值为`5`时,`break`语句会跳出整个循环;当`i`的值为`3`时,`continue`语句会跳过本次循环,直接进行下一次循环。因此,i在每次循环中的变化为:`0``1``2``4``5`,最后跳出循环。
102+
103+
`break``continue`语句只能在循环中使用。
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
lastUpdated: true
3+
---
4+
5+
# 顶层语句
6+
7+
在MCFPP中,允许在文件的开始直接编写语句而无需额外定义函数,即顶层语句。顶层语句处于一个隐式的函数中,这个函数每个文件有且只有一个,且不能被外部调用。它的返回值类型为`void`
8+
9+
```mcfpp
10+
print("Top statement");
11+
12+
func main(){
13+
print("Function");
14+
}
15+
```
16+
17+
在编译后,会生成两个函数——分别对应main函数以及顶层语句对应的默认函数。
18+
19+
顶层语句只能在文件的开始编写,即在函数定义或类定义之前。顶层语句可以调用文件中声明的其他函数和类
20+
21+
```mcfpp
22+
main();
23+
24+
func main(){
25+
print("Function");
26+
}
27+
```
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
lastUpdate: true
3+
---
4+
5+
# 命名空间
6+
7+
MCFPP中的命名空间和MC中的命名空间是同一种东西。这也意味着,命名空间只能是小写字母、数字,点和下划线的组合。
8+
9+
你可以在文件中声明一个命名空间,这样文件中的所有函数和变量都会被放置在这个命名空间中。例如:
10+
11+
```mcfpp
12+
namespace test;
13+
14+
func test(){ # test:test函数
15+
print(i);
16+
}
17+
```
18+
19+
一个文件中只能声明一次命名空间。
20+
21+
同样的,你也可以在项目配置文件中声明这个命名空间。
22+
23+
```json
24+
{
25+
"file":[
26+
"*"
27+
"D:/workspace/mcfpp/project/*"
28+
],
29+
"version":"1.19.4",
30+
"include":[
31+
"D:/workspace/mcfpp/another_project.json"
32+
],
33+
"targetPath":"./out",
34+
//工程的默认命名空间。可选,默认为default // [!code focus]
35+
"namespace":"mcfpp" // [!code focus]
36+
}
37+
```
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
lastUpdate: true
3+
---
4+
5+
# 定义和调用
6+
7+
MCFPP函数的定义方式和C/Java有较大的区别,而更加接近于Python的语法。
8+
9+
## 函数定义
10+
11+
MCFPP中,函数的定义语法如下:
12+
13+
```mcfpp
14+
func functionName(parameter1, parameter2, ...) -> returnType{
15+
#函数体
16+
}
17+
```
18+
19+
`func`是函数的关键字,`functionName`是函数的标识符或者说名字,而紧随其后的`parameter1, parameter2, ...`则是函数的参数列表,`returnType`是可选的,即函数的返回类型。函数体则是由`{}`包裹的一系列语句。下面是一个实际的例子:
20+
21+
```mcfpp
22+
func add(int a, int b) -> int{
23+
return a + b;
24+
}
25+
```
26+
27+
这个函数的名字是`add`,它有两个整数类型的参数`a``b`,返回值也是一个整数类型。这个函数的作用是把两个参数相加并返回结果。
28+
29+
## return
30+
31+
`return`和Minecraft中的`return`命令作用相同,都是用于返回函数的返回值。它的语法即为`return expression;`,其中`expression`是一个表达式,它的值就是函数的返回值。
32+
33+
如果一个函数定义了返回值类型,那么它的每一个分支都必须有`return`语句,即函数必定返回一个值。且`return`语句返回的值必须和函数的返回值类型相同,或者是返回值类型的子类型。
34+
35+
如果一个函数没有定义返回值类型,那么默认为`void`,即不会返回任何值。这个时候,`return`语句仍然是可用的,但是它的语法变为`return;`,即不带任何表达式。它将会起到立刻终止函数运行的作用。
36+
37+
## 函数的调用
38+
39+
MCFPP中,函数的调用语法和C/Java一样,即`functionName(parameter1, parameter2, ...);`。其中,`functionName`是函数的名字,`parameter1, parameter2, ...`是要传递给函数的参数。下面是一个实际的例子:
40+
41+
```mcfpp
42+
func test(){
43+
print(add(1, 2)); #上面定义的add函数
44+
}
45+
```
46+
47+
这个例子中,`test`函数调用了`add`函数,并传递了两个参数`1``2``add`函数返回了`3`,因此`test`函数将会打印出`3`
48+
49+
## 函数的传参
50+
51+
函数中,对参数的修改不会影响到函数外部的变量。例如:
52+
53+
```mcfpp
54+
func test(int a){
55+
a = 5;
56+
}
57+
58+
void main(){
59+
int a = 0;
60+
test(a);
61+
print(a); #输出0
62+
}
63+
```
64+
65+
在这个例子中,`test`函数对传入的参数`a`进行了修改,但是`main`函数中的`a`并没有受到影响。
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
lastUpdate: true
3+
---
4+
5+
# static关键字
6+
7+
`static`关键字用于声明一个静态参数。静态参数表示,在参数传递的过程中,是传递的参数本身而不是参数的值,因此在函数中对参数的修改会影响外部的变量。例如:
8+
9+
```mcfpp
10+
func test(static int a){
11+
a = 5;
12+
}
13+
14+
void main(){
15+
int a = 0;
16+
test(a);
17+
print(a); #输出5
18+
}
19+
```

0 commit comments

Comments
 (0)