symbolstack.java
来自「基于算符优先关心的」· Java 代码 · 共 46 行
JAVA
46 行
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 + =
减小字号Ctrl + -
显示快捷键?