📄 tree.cs
字号:
else if (type == 17)
{
this.arrayElem_give_action(useSentence);
}
//变量赋值语句
else if (type == 22)
{
this.var_give_action(useSentence);
}
//条件语句
else if (type == 23)
{
Object intExp = condition_action(useSentence, returnType);
if (intExp is Double)
{
return intExp;
}
else if (intExp == null)
{
continue;
}
else { throw new Exception("返回类型错误"); }
}
//循环语句
else if (type == 25)
{
Object intExp = loop_action(useSentence, returnType);
if (intExp is Double)
{
return intExp;
}
else if (intExp == null)
{
continue;
}
else { throw new Exception("返回类型错误"); }
}
//读语句
else if (type == 26)
{
read_action(useSentence);
}
//写语句
else if (type == 27)
{
write_action(useSentence);
}
//返回语句
else if (type == 28)
{
Object douExp = return_action(useSentence);
if (douExp is Double)
{
return douExp;
}
else
{
throw new Exception("返回类型错误");
}
}
//错误
else
{
throw new Exception("语句错误 " + the_funct_in_cont.getName());
}
}
else { throw new Exception("语句错误 " + the_funct_in_cont.getName()); }
}
if (whereIs < 1) { throw new Exception("缺少return语句"); } else { return null; }
}
else if (returnType == "real[]")
{
// 必须有retrurn 且return 后面的表达式必须是Symbol array
//进入方法体内容 只有一个孩子
for (int i = 0; i < child; i++)
{
TreeNode the_funct_in_cont = (TreeNode)the_funct_in.getAChild(i);
Object sentence = the_funct_in_cont.getAChild(0);
if (sentence is Token)
{
//空语句
continue;
}
else if (sentence is TreeNode)
{
TreeNode useSentence = (TreeNode)sentence;
//节点类型
int type = useSentence.getType();
//数组声明
if (type == 5)
{
action((TreeNode)useSentence.getAChild(1), useSentence);
}
//变量声明
else if (type == 7)
{
the_var_decl_action(useSentence);
}
//方法调用语句
else if (type == 15)
{
Object shouldNull = the_funct_call_action(useSentence);
if (shouldNull != null)
{
throw new Exception("语句错误 " + useSentence.getName() + ((Token)useSentence.getAChild(0)).getValue());
}
}
//数组元素赋值语句
else if (type == 17)
{
this.arrayElem_give_action(useSentence);
}
//变量赋值语句
else if (type == 22)
{
this.var_give_action(useSentence);
}
//条件语句
else if (type == 23)
{
Object intExp = condition_action(useSentence, returnType);
if (intExp is Symbol)
{
return intExp;
}
else if (intExp == null)
{
continue;
}
else { throw new Exception("返回类型错误"); }
}
//循环语句
else if (type == 25)
{
Object intExp = loop_action(useSentence, returnType);
if (intExp is Symbol)
{
return intExp;
}
else if (intExp == null)
{
continue;
}
else { throw new Exception("返回类型错误"); }
}
//读语句
else if (type == 26)
{
read_action(useSentence);
}
//写语句
else if (type == 27)
{
write_action(useSentence);
}
//返回语句
else if (type == 28)
{
Object douExp = return_action(useSentence);
if (douExp is Symbol)
{
Symbol useExp = (Symbol)douExp;
if (useExp.isTheArray() && useExp.getType() == 2)
{
return useExp;
}
else
{
throw new Exception("返回类型错误");
}
}
else
{
throw new Exception("返回类型错误");
}
}
//错误
else
{
throw new Exception("语句错误 " + the_funct_in_cont.getName());
}
}
else { throw new Exception("语句错误 " + the_funct_in_cont.getName()); }
}
if (whereIs < 1) { throw new Exception("缺少return语句"); } else { return null; }
}
else { throw new Exception("参数类型错误 " + returnType); }
}
catch (Exception e)
{
errorCount++; MyInvoke mi = new MyInvoke(change);
errorCount++; theOutIn.BeginInvoke(mi, e.Message);
return null;
}
}
//返回语句
Object return_action(TreeNode the_return)
{
try
{
if (the_return.getChildCount() == 1)
{
return null;
}
else if (the_return.getChildCount() == 2)
{
return the_expression_action((TreeNode)the_return.getAChild(1));
}
else { throw new Exception("返回类型错误"); }
}
catch (Exception e)
{
errorCount++;
MyInvoke mi = new MyInvoke(change);
theOutIn.BeginInvoke(mi, e.Message); return null;
}
}
//写语句
void write_action(TreeNode the_write)
{
try
{
TreeNode the_expression = (TreeNode)the_write.getAChild(0);
Object result = the_expression_action(the_expression);
MyInvoke mi = new MyInvoke(change);
if (result is Int32)
{
string write= (Int32)result + "\n";
this.theOutIn.BeginInvoke(mi, write);
}
else if (result is Double)
{
string write= (Double)result + "\n";
this.theOutIn.BeginInvoke(mi, write);
}
else
{ throw new Exception("表达式类型错误"); }
}
catch (Exception e)
{
errorCount++; MyInvoke mi = new MyInvoke(change);
theOutIn.BeginInvoke(mi, e.Message);
}
}
//读语句
void read_action(TreeNode the_read)
{
try
{
string name = ((Token)the_read.getAChild(0)).getValue();
TheInvoke ti = new TheInvoke(setText);
this.theOutIn.BeginInvoke(ti, "");
Remind ri = new Remind(setRemind);
this.lable1.BeginInvoke(ri, true);
while (!this.canRead)
{
Thread.Sleep(30);
}
//重新设为不能读
canRead = false;
this.lable1.BeginInvoke(ri, false);
this.theOutIn.BeginInvoke(ti, "");
int type = find(name).getType();
if (type == 1)
{
Change(name, Convert.ToInt32(readValue));
}
else if (type == 2)
{
Change(name, Convert.ToDouble(readValue));
}
else { throw new Exception("变量 " + name + "类型错误"); }
}
catch (OverflowException oe)
{
errorCount++; MyInvoke mi = new MyInvoke(change);
theOutIn.BeginInvoke(mi, "输入 " + readValue + "超过规定范围"+oe.Message);; }
catch (FormatException fe)
{
errorCount++; MyInvoke mi = new MyInvoke(change);
theOutIn.BeginInvoke(mi, "输入 " + readValue + " 形式错误" + fe.Message);
}
catch (Exception e)
{
errorCount++; MyInvoke mi = new MyInvoke(change);
theOutIn.BeginInvoke(mi, e.Message);
}
}
//循环语句 动作
Object loop_action(TreeNode the_loop,string returnType)
{
try
{
Tr
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -