ast.java

来自「语法分析器」· Java 代码 · 共 84 行

JAVA
84
字号
/**
 * this class used for define the node information a node include six aspects
 * 
 * @author:贺静
 * @version 1.2
 */
public class AST {
	// the type of the node
	private int type;

	private String text;

	// the child and the brother of the node
	private AST down, right;

	// the information for print
	protected String info = "";

	protected boolean isLeaf = true;

	public AST() {
	}

	public AST(boolean leaf) {
		this.isLeaf = leaf;
	}

	public AST(int type) {
		this.type = type;
		this.down = this.right = null;
	}

	/**
	 * @return a int as the type of the node
	 */
	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public String getText() {
		return this.text;
	}

	public void setText(String text) {
		this.text = text;
	}
/**
 * @return the brother of current node
 */
	public AST getRight() {
		return this.right;
	}
/**
 * @return the first child of current node
 */
	public AST getDown() {
		return this.down;
	}
	public void setRight(AST brother){
		this.right=brother;
	}
/**
 * @param child
 * add child to current token
 */
	public void addChild(AST child) {
		if (child == null)
			return;
		AST t = this.down;
		if (t != null) {
			while (t.right != null) {
				t = t.right;
			}
			t.right = child;
		} else {
			this.down = child;
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?