📄 tree.cs
字号:
this.var_give_action(useSentence);
}
//条件语句
else if (type == 23)
{
condition_action(useSentence, returnType);
}
//循环语句
else if (type == 25)
{
loop_action(useSentence, returnType);
}
//读语句
else if (type == 26)
{
read_action(useSentence);
}
//写语句
else if (type == 27)
{
write_action(useSentence);
}
//返回语句
else if (type == 28)
{
if (return_action(useSentence) == null)
{
return null;
}
else
{
throw new Exception("返回类型错误");
}
}
//错误
else
{
throw new Exception("语句错误 " + the_funct_in_cont.getName());
}
}
else { throw new Exception("语句错误 " + the_funct_in_cont.getName()); }
}
return null;
}
else if (returnType == "int")
{
// 必须有retrurn 且return 后面的表达式必须是int
//进入方法体内容 只有一个孩子
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 Int32)
{
return intExp;
}
else if (intExp == null)
{
continue;
}
else { throw new Exception("返回类型错误"); }
}
//循环语句
else if (type == 25)
{
Object intExp = loop_action(useSentence, returnType);
if (intExp is Int32)
{
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 intExp = return_action(useSentence);
if (intExp is Int32)
{
return intExp;
}
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 == "int[]")
{
// 必须有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 intExp = return_action(useSentence);
if (intExp is Symbol)
{
Symbol useExp = (Symbol)intExp;
if (useExp.isTheArray() && useExp.getType() == 1)
{
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 if (returnType == "real")
{
// 必须有retrurn 且return 后面的表达式必须是real
//进入方法体内容 只有一个孩子
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());
}
}
//数组元素赋值语句
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -