public int Calculate() { switch (token.type) { case Types.type.PLUS: { return(son.Calculate()); } case Types.type.MINUS: { return(-son.Calculate()); } case Types.type.NOT: { if (son.Calculate() == 0) { return(1); } return(0); } case Types.type.INC: { if (son is AtomNode) { int num = VarList.Get(token.value).Calculate(); ITreeNode node = VarList.Get(son.ToOut()); VarList.Add(son.ToOut(), new BinarNode(new Token(Types.type.PLUS, "+"), node, new AtomNode(new Token(Types.type.INTEGER, "1")))); return(num); } throw new Exception(); } case Types.type.DEC: { if (son is AtomNode) { int num = VarList.Get(token.value).Calculate(); ITreeNode node = VarList.Get(son.ToOut()); VarList.Add(son.ToOut(), new BinarNode(new Token(Types.type.MINUS, "-"), node, new AtomNode(new Token(Types.type.INTEGER, "1")))); return(num); } throw new Exception(); } } throw new Exception(); }
public int Calculate() { if (condition.Calculate() != 0) { return(block.Calculate()); } return(0); }
public int Calculate() { while (condition.Calculate() != 0) { circlesCount++; block.Calculate(); if (circlesCount > 10000) { throw new StackOverflowException(); } } return(0); }
// calculate the expression public int Calculate() { return(root.Calculate()); }
public int Calculate() { switch (token.type) { case Types.type.MULT: return(left.Calculate() * right.Calculate()); case Types.type.DIV: { int a = right.Calculate(); if (a == 0) { a++; throw new NullDivisionException(); } return(left.Calculate() / a); } case Types.type.MOD: { int a = right.Calculate(); if (a == 0) { a++; throw new NullDivisionException(); } return(left.Calculate() % a); } case Types.type.EQUAL: { VarList.Add(left.ToOut(), right); return(VarList.Get(token.value).Calculate()); } case Types.type.MAX: return(Math.Max(left.Calculate(), right.Calculate())); case Types.type.MIN: return(Math.Min(left.Calculate(), right.Calculate())); case Types.type.POWER: return((int)Math.Pow(left.Calculate(), right.Calculate())); case Types.type.PLUS: return(left.Calculate() + right.Calculate()); case Types.type.MINUS: return(left.Calculate() - right.Calculate()); case Types.type.LARGER: { if (left.Calculate() > right.Calculate()) { return(1); } break; } case Types.type.LARGEREQUAL: { if (left.Calculate() >= right.Calculate()) { return(1); } break; } case Types.type.SMALLER: { if (left.Calculate() < right.Calculate()) { return(1); } break; } case Types.type.SMALLEREQUAL: { if (left.Calculate() <= right.Calculate()) { return(1); } break; } case Types.type.ISEQUAL: { if (left.Calculate() == right.Calculate()) { return(1); } break; } case Types.type.NOTEQUAL: { if (left.Calculate() != right.Calculate()) { return(1); } break; } case Types.type.AND: { if ((left.Calculate() != 0) && (right.Calculate() != 0)) { return(1); } break; } case Types.type.OR: { if ((left.Calculate() != 0) || (right.Calculate() != 0)) { return(1); } break; } } return(0); }