Skip to content

Commit f7631bb

Browse files
committed
修复do-while的编译问题
1 parent 2568b32 commit f7631bb

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

.mclib

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"id":"default",
55
"functions":[
66
{
7-
"id":"generateSequence",
7+
"id":"generateSequenceDoWhile",
88
"normalParams":[
99

1010
],
@@ -15,7 +15,7 @@
1515
]
1616
},
1717
{
18-
"id":"_while_1721ca59-7dd8-4e3b-b146-190ad749a4f2",
18+
"id":"_dowhile_78ddf9e4-56ed-4439-93bc-bceb4e47f9ec",
1919
"normalParams":[
2020

2121
],
@@ -26,7 +26,7 @@
2626
]
2727
},
2828
{
29-
"id":"expression_67b9dd31-2e5e-4873-a1a3-f4b5f0da11e2",
29+
"id":"_dowhile_de4d3e61-9c4a-4c3f-81ae-3e7decf37e3b",
3030
"normalParams":[
3131

3232
],
@@ -37,7 +37,7 @@
3737
]
3838
},
3939
{
40-
"id":"_while_block_4b041b7f-b519-423e-82cf-f816f0d548a3",
40+
"id":"expression_52569370-85ad-4996-bbe1-8b209ead925a",
4141
"normalParams":[
4242

4343
],

src/main/kotlin/top/mcfpp/antlr/McfppImVisitor.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,8 @@ open class McfppImVisitor: mcfppParserBaseVisitor<Any?>() {
699699
Project.ctx = ctx
700700
//调用完毕,将子函数的栈销毁
701701
Function.addCommand("data remove storage mcfpp:system " + Project.config.defaultNamespace + ".stack_frame[0]")
702-
//调用完毕,将子函数的栈销毁
702+
//返回1
703+
Function.addCommand("return 1")
703704
Function.currFunction = Function.currFunction.parent[0]
704705
Function.addCommand("#do while end")
705706
}
@@ -919,8 +920,10 @@ open class McfppImVisitor: mcfppParserBaseVisitor<Any?>() {
919920
Function.addCommand("#" + ctx.text)
920921
//return语句
921922
if(ctx.BREAK() != null){
923+
//break,完全跳出while
922924
Function.addCommand("return 0")
923925
}else{
926+
//continue,跳过当次
924927
Function.addCommand("return 1")
925928
}
926929
Function.currFunction.isReturned = true

src/test/kotlin/top/mcfpp/test/LogicStatementTest.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,32 @@ class LogicStatementTest {
3939
""".trimIndent()
4040
MCFPPStringTest.readFromString(test, "D:\\.minecraft\\saves\\MCFPP Studio\\datapacks")
4141
}
42+
43+
@Test
44+
fun doWhileTest() {
45+
val test =
46+
"""
47+
func generateSequenceDoWhile(){
48+
dynamic int i = 0;
49+
do {
50+
print(i);
51+
i = i + 1;
52+
} while(i < 10);
53+
}
54+
""".trimIndent()
55+
MCFPPStringTest.readFromString(test, "D:\\.minecraft\\saves\\MCFPP Studio\\datapacks")
56+
}
57+
58+
@Test
59+
fun forTest() {
60+
val test =
61+
"""
62+
func generateSequenceFor(){
63+
for(dynamic int i = 0; i < 10; i = i + 1){
64+
print(i);
65+
}
66+
}
67+
""".trimIndent()
68+
MCFPPStringTest.readFromString(test, "D:\\.minecraft\\saves\\MCFPP Studio\\datapacks")
69+
}
4270
}

0 commit comments

Comments
 (0)