コード例 #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);
            }
        }
コード例 #2
0
 //Evaluates the exp
 public override int Eval(MyIDictionary tbl, MyIHeap heap)
 {
     return(tbl.Lookup(mId));
 }
コード例 #3
0
 // Evaluates the exp
 public override int Eval(MyIDictionary tbl, MyIHeap heap)
 {
     return(mNumber);
 }
コード例 #4
0
 //Evaluates the Exp
 public abstract int Eval(MyIDictionary tbl, MyIHeap heap);