Beispiel #1
0
        /// <summary>
        /// Evaluates the Expression
        /// </summary>
        public override int Eval(MyIDictionary tbl, MyIHeap heap)
        {
            int leftOp  = mExp1.Eval(tbl, heap);
            int rightOp = mExp2.Eval(tbl, heap);

            switch (mOp)
            {
            case "+":
                return(leftOp + rightOp);

            case "-":
                return(leftOp - rightOp);

            case "*":
                return(leftOp * rightOp);

            case "/":
                if (rightOp == 0)
                {
                    throw new MyDivisionByZeroException("Division by zero");
                }
                else
                {
                    return(leftOp / rightOp);
                }

            default:
                return(0);
            }
        }
 //Evaluates the exp
 public override int Eval(MyIDictionary tbl, MyIHeap heap)
 {
     return(tbl.Lookup(mId));
 }
 // Evaluates the exp
 public override int Eval(MyIDictionary tbl, MyIHeap heap)
 {
     return(mNumber);
 }
 //Evaluates the Exp
 public abstract int Eval(MyIDictionary tbl, MyIHeap heap);