int i = stk.Count -2; if (i >= 0) return (ParseObject)stk[i]; else return null;} public void pop2Push(ParseObject p){ int i = stk.Count ; if (i >= 2) { pop(); pop(); push(p);} else push(p);}}} ParseObject解析对象类: public class ParseObject{ public const int VERB=1000; public const int VAR=1010; public const int MULTVAR=1020; protected int value, type; public ParseObject(int val, int typ) { value = val; type = typ; } public int getValue() { return value;} public int getType() { return type;}} Parser解析类: public class Parser{
public Parser(string line, StudentData kd, ListBox pt) { stk = new Stack (); actionList = new ArrayList (); setData(kd, pt); buildStack(line); buildChain();}
public void setData(StudentData kd, ListBox pt) { dat = new Data(kd.getData ()); ptable = pt;} public void Execute() { while(stk.hasMoreElements () ) { chn.sendToChain (stk);} for(int i=0; i< actionList.Count ; i++ ) { Verb v = (Verb)actionList[i]; v.setData (dat, ptable); v.Execute ();}}}