⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 symbolstack.java

📁 基于算符优先关心的
💻 JAVA
字号:
package parser;
import java.util.ArrayList;
/**
 * the stack which will be used to contain the expression and $
 * @author Yuanhang Yang
 *
 */
public class SymbolStack{
	ArrayList<Symbol> prefix = new ArrayList<Symbol>();
	
	public SymbolStack() {

	}
	/**function: add symbol s into the ArrayList :prefix
	 * 
	 * @param s  symbol
	 */
	public void push(Symbol s){
		prefix.add(s);
	}
	/**function: remove the most top token from prefix
	 * 
	 * @return	 the  symbol have be removed
	 */
	public Symbol pop(){		
		return prefix.remove(prefix.size()-1);
	}
	/**function:get the top token in prefix 
	 * 
	 * @return  the top token 
	 */
	public Symbol peek(){
		return prefix.get(prefix.size()-1);
	}
	/**function: get the frist Terminal from prefix
	 * 
	 * @return the first Terminal in the prefix
	 */
	public Symbol getFirstTerminal(){
		for(int i = prefix.size()-1; i>=0; --i){
			if(prefix.get(i).tokenType <= TokenType.dollor )
				return prefix.get(i);
		}
		return null;
	}
}

⌨️ 快捷键说明

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