?? 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 + -