📄 treenode.cs
字号:
using System;
using System.Collections;
using System.Text;
namespace compiler
{
class TreeNode
{
//child
ArrayList child = new ArrayList();
//用户数字表示不同种类的构造函数
int type;
//拥有孩子的个数
int numberOfChildren=0;
//constructor
public TreeNode(int typefrom)
{
this.type = typefrom;
}
//语义分析时候使用的
public void action()
{
}
//添加节点孩子
public bool addChildren(TreeNode oneChild)
{
try {
this.child.Add(oneChild);
this.numberOfChildren++;
return true;
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
return false;
}
}
//添加token孩子
public bool addChildren(Token oneChild)
{
try
{
this.child.Add(oneChild);
this.numberOfChildren++;
return true;
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
return false;
}
}
//返回非终结符的名字
public string getName()
{
switch (this.type)
{
case -1: return "树顶";
case 0: return "程序";
case 1: return "分程序";
case 2: return "全局声明";
case 3: return "常量声明";
case 4 : return "常量定义";
case 5: return "数组声明";
case 6: return "数组定义";
case 7: return "变量声明";
case 8: return "变量定义";
case 9: return "方法部分";
case 10: return "参数说明";
case 11: return "参数定义";
case 12: return "返回类型";
case 13: return "方法体";
case 14: return "方法体内容";
case 15: return "方法调用";
case 16: return "传参数";
case 17: return "数组元素赋值";
case 18: return "表达式";
case 19: return "项";
case 20: return "因子";
case 21: return "数组元素";
case 22: return "变量赋值语句";
case 23: return "条件语句";
case 24: return "条件";
case 25: return "循环语句";
case 26: return "读语句";
case 27: return "写语句";
case 28: return "返回语句";
default: return "wrong";
}
}
//返回孩子的个数
public int getChildCount()
{
return this.numberOfChildren;
}
//选中一个孩子
public Object getAChild(int index)
{
return (this.child[index]);
}
//返回当前节点的类型
public int getType()
{
return this.type;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -