我为我的个人语言编写了翻译(差不多),我已经实施了cin, cout, variable
声明和其他声明。
现在我坚持使用实现if
语句,首先是nested if
语句。
当有多个if
时,我无法结束nested if
语句块
因为它因为其他块的结束而在获得块的实际结束之前停止
示例:
if var is 7 <- at every if my method start
if var is greater than 6
if var is less than 8
write no
else
write yes
end
else <- my method get this line but
write ok
end
else <- it should give me this line
write no
end
这是我的代码,我尝试了不同的代码,这是更好的
String [] Control = Global.Code; //这是源代码 bool isAlone = false;
int ok = 0; // variable to return (line of the else or end)
for (int i = riga + 1; i < Control.Length; i++)
{
restart:
if (Control[i].Contains("if"))
{
isAlone = true;
}
if (Control[i] == "end" && isAlone == true)
{
isAlone = false;
i += 1;
goto restart;
}
if(Control[i] == "end" || Control[i] == "else" && isAlone == false )
{
ok = i;
break;
}
}
return ok;
}