public PrgState(ADT.IDictionary <string, int> s, IExeStack <Statement> exe, IOutput <int> o, IFileTable <int, FileData> ft)
 {
     this.symbolTable = s;
     this.exeStack    = exe;
     this.output      = o;
     this.filetable   = ft;
 }
示例#2
0
        public PrgState Execute(PrgState p)
        {
            ADT.IDictionary <string, int> dict = p.Dict;
            int val = this.expr.Eval(dict);

            if (val != 0)
            {
                p.Stack.Push(thenstmt);
            }
            else
            {
                p.Stack.Push(elsestmt);
            }
            return(p);
        }
        public int Eval(ADT.IDictionary <string, int> dict)
        {
            int resl = this.left.Eval(dict);
            int resr = this.right.Eval(dict);

            if (this.op == '+')
            {
                return(resl + resr);
            }
            else if (this.op == '-')
            {
                return(resl - resr);
            }
            else if (this.op == '*')
            {
                return(resl * resr);
            }
            else if (this.op == '%')
            {
                if (resr == 0)
                {
                    throw new DivideByZeroException("Division by 0");
                }
                else
                {
                    return(resl % resr);
                }
            }
            else
            {
                if (resr == 0)
                {
                    throw new DivideByZeroException("Division by 0");
                }
                else
                {
                    return(resl / resr);
                }
            }
        }
 public int Eval(ADT.IDictionary <string, int> dict)
 {
     return(dict.getValue(this.varName));
 }
示例#5
0
 public int Eval(ADT.IDictionary <string, int> dict)
 {
     return(this.value);
 }