IEXPR ParseAtrithExpr(IEXPR exp) { Queue<IEXPR> que = new Queue<IEXPR>(); Stack<IEXPR> ops = new Stack<IEXPR>(); bool isop = true; int sub = 0; if (exp != null) { que.Enqueue(exp); i++; } if (Current.val.ToString() == "(") { i++; } while (true) { if (Current.val.ToString() == "+") { ArithPushStack(que, ops, new Add()); isop = true; } else if (Current.val.ToString() == "-") { ArithPushStack(que, ops, new Sub()); isop = true; } else if (Current.val.ToString() == "*") { ArithPushStack(que, ops, new Mul()); isop = true; } else if (Current.val.ToString() == "/") { ArithPushStack(que, ops, new Div()); isop = true; } else if (Current.val.ToString() == "%") { ArithPushStack(que, ops, new Mod()); isop = true; } else if (Current.val.ToString() == "(") { ArithPushStack(que, ops, new OpenSub()); sub++; } else if (Current.val.ToString() == ")") { if (sub < 0) { i++; i++; break; } else { ArithPushStack(que, ops, new CloseSub()); sub--; } } else if (Current.val.ToString() == "<") { ArithPushStack(que, ops, new CompareLess()); isop = true; } else if (Current.val.ToString() == "=") { ArithPushStack(que, ops, new CompareEqu()); isop = true; } else if (Current.val.ToString() == ">") { ArithPushStack(que, ops, new CompareGrt()); isop = true; } else { if (isop == false) { i--; break; } else { IEXPR ex = ParseExpr(true); que.Enqueue(ex); isop = false; } } i++; } while (ops.Count > 0) { que.Enqueue(ops.Pop()); } AritemeticExpr e = new AritemeticExpr(); e.code = que.ToArray(); return e; }
IEXPR ParseAtrithExpr(IEXPR exp) { Queue <IEXPR> que = new Queue <IEXPR>(); Stack <IEXPR> ops = new Stack <IEXPR>(); bool isop = true; int sub = 0; if (exp != null) { que.Enqueue(exp); i++; } if (Current.val.ToString() == "(") { i++; } while (true) { if (Current.val.ToString() == "+") { ArithPushStack(que, ops, new Add()); isop = true; } else if (Current.val.ToString() == "-") { ArithPushStack(que, ops, new Sub()); isop = true; } else if (Current.val.ToString() == "*") { ArithPushStack(que, ops, new Mul()); isop = true; } else if (Current.val.ToString() == "/") { ArithPushStack(que, ops, new Div()); isop = true; } else if (Current.val.ToString() == "%") { ArithPushStack(que, ops, new Mod()); isop = true; } else if (Current.val.ToString() == "(") { ArithPushStack(que, ops, new OpenSub()); sub++; } else if (Current.val.ToString() == ")") { if (sub < 0) { i++; i++; break; } else { ArithPushStack(que, ops, new CloseSub()); sub--; } } else if (Current.val.ToString() == "<") { ArithPushStack(que, ops, new CompareLess()); isop = true; } else if (Current.val.ToString() == "=") { ArithPushStack(que, ops, new CompareEqu()); isop = true; } else if (Current.val.ToString() == ">") { ArithPushStack(que, ops, new CompareGrt()); isop = true; } else { if (isop == false) { i--; break; } else { IEXPR ex = ParseExpr(true); que.Enqueue(ex); isop = false; } } i++; } while (ops.Count > 0) { que.Enqueue(ops.Pop()); } AritemeticExpr e = new AritemeticExpr(); e.code = que.ToArray(); return(e); }