Example #1
0
        public PrgState Execute(PrgState state)
        {
            MyIDictionary <String, int> symTable = state.GetSymTable();
            int file_id = this.exp_file_id.Eval(symTable);
            MyIPair <String, StreamReader> fileTable = state.GetFileTable().Lookup(file_id);

            if (fileTable == null)
            {
                throw new MyException("File not opened");
            }
            int    anotherVal;
            String line = fileTable.GetSecond().ReadLine();

            if (line == null)
            {
                anotherVal = 0;
            }
            else
            {
                anotherVal = System.Convert.ToInt32(line);
            }
            if (symTable.IsDefinedU(var_name))
            {
                symTable.Update(var_name, anotherVal);
            }
            else
            {
                symTable.Add(var_name, anotherVal);
            }
            return(state);
        }
Example #2
0
        public PrgState Execute(PrgState state)
        {
            MyIList <int> list = state.GetPrintList();

            list.Add1(exp.Eval(state.GetSymTable(), state.GetHeap()));
            return(null);
        }
Example #3
0
        public PrgState Execute(PrgState state)
        {
            MyIList <int> ot = state.GetOut();
            MyIDictionary <String, int> symtbl = state.GetSymTable();
            int val = exp.Eval(symtbl);

            ot.Add(val);
            return(state);
        }
Example #4
0
 public PrgState <T> Execute <T>(PrgState <T> state)
 {
     if (mExp.Eval(state.GetSymTable(), state.GetHeap()) > 0)
     {
         state.AddExeStack((T)(IStmt)this);
         state.AddExeStack((T)mStatement);
     }
     return(null);
 }
Example #5
0
 public PrgState <T> Execute <T>(PrgState <T> state)
 {
     if (mExp.Eval(state.GetSymTable(), state.GetHeap()) != 0)
     {
         state.AddExeStack((T)mThenS);
     }
     else
     {
         state.AddExeStack((T)mElseS);
     }
     return(null);
 }
Example #6
0
        public PrgState <T> Execute <T>(PrgState <T> state)
        {
            MyIStack <T> stk2 = new MyStack <T>();

            stk2.Push((T)mStmt);
            int          id   = state.GetId();
            MyDictionary sym2 = new MyDictionary();

            sym2 = (MyDictionary)state.GetSymTable().DeepCopy();
            PrgState <T> state2 = new PrgState <T>(
                stk2, sym2, state.GetOut(), state.GetHeap(), ++id);

            return(state2);
        }
Example #7
0
        public PrgState Execute(PrgState state)
        {
            MyIStack <IStmt>            stk    = state.GetExeStack();
            MyIDictionary <String, int> symtbl = state.GetSymTable();

            if (exp.Eval(symtbl) != 0)
            {
                stk.Push(thenS);
            }
            else
            {
                stk.Push(elseS);
            }
            return(state);
        }
Example #8
0
 public PrgState Execute(PrgState state)
 {
     try
     {
         int val = exp_file_id.Eval(state.GetSymTable());//what to eval
         MyPair <String, StreamReader> entry = state.GetFileTable().Lookup(val);
         entry.GetSecond().Close();
         state.GetFileTable().Delete(val, entry);
     }
     catch (Exception e)
     {
         throw new MyException("Something went wrong!");
     }
     return(state);
 }
Example #9
0
        public PrgState Execute(PrgState state)
        {
            MyIStack <IStmt> stk      = state.GetStk();
            IStmt            thenStmt = this.thenS;
            IStmt            elseStmt = this.elseS;

            if (exp.Eval(state.GetSymTable(), state.GetHeap()) != 0)
            {
                stk.Push(thenStmt);
            }
            else
            {
                stk.Push(elseStmt);
            }
            return(null);
        }
Example #10
0
        public PrgState <T> Execute <T>(PrgState <T> state)
        {
            MyIHeap       heap     = state.GetHeap();
            MyIDictionary symTable = state.GetSymTable();

            if (symTable.IsDefined(mVarName))
            {
                heap.Update(symTable.Lookup(mVarName), mExp.Eval(symTable, heap));;
            }
            else
            {
                throw new ArgumentException("Heap address undefined");
            }

            return(null);
        }
Example #11
0
        public PrgState Execute(PrgState state)
        {
            MyIStack <IStmt>            stk    = state.GetExeStack();
            MyIDictionary <String, int> symTbl = state.GetSymTable();
            int val = exp.Eval(symTbl);

            if (symTbl.IsDefinedU(id))
            {
                symTbl.Update(id, val);
            }
            else
            {
                symTbl.Add(id, val);
            }
            return(state);
        }
Example #12
0
        PrgState IStmt.Execute(PrgState state)
        {
            MyIStack <IStmt> stack = new MyLibStack <IStmt>();
            Stack <MyIDictionary <MyMap> > symtable = state.GetSymTable();
            MyIList <int> printList = state.GetPrintList();
            IHeap <HMap>  h         = state.GetHeap();

            MyLibStack <IStmt> crtstm = new MyLibStack <IStmt>();


            PrgState childPrgState = new PrgState(stack, symtable, printList, stmt, h);

            childPrgState.id = state.id * 10;


            return(childPrgState);
        }
Example #13
0
        public PrgState <T> Execute <T>(PrgState <T> state)
        {
            MyIDictionary symTbl = state.GetSymTable();
            int           val;

            val = mExp.Eval(symTbl, state.GetHeap());

            if (symTbl.IsDefined(mId))
            {
                symTbl.Update(mId, val);
            }
            else
            {
                symTbl.Add(mId, val);
            }
            return(null);
        }
Example #14
0
        public PrgState Execute(PrgState state)
        {
            Stack <MyIDictionary <MyMap> > symTbl = state.GetSymTable();
            IHeap <HMap> heap    = state.GetHeap();
            int          address = symTbl.ElementAt(0).Lookup(this.var);

            try
            {
                HMap h = (HMap)heap.Gett(address);
                h.SetAddr(address);
                h.SetCont(exp.Eval(symTbl, heap));
            }
            catch (MissingMemberException e)
            {
            }
            return(null);
        }
Example #15
0
        public PrgState Execute(PrgState state)
        {
            MyIStack <IStmt> stk = state.GetStk();

            IStmt[] s = this.stmt;
            int     k = exp.Eval(state.GetSymTable(), state.GetHeap());

            while (k > 0)
            {
                for (int i = 0; i < s.Length; i++)
                {
                    stk.Push(s[i]);
                }
                k--;
            }
            return(null);
        }
Example #16
0
        public PrgState <T> Execute <T>(PrgState <T> state)
        {
            MyIHeap       heap     = state.GetHeap();
            MyIDictionary symTable = state.GetSymTable();

            if (symTable.IsDefined(mVarName))
            {
                symTable.Update(mVarName, heap.Size() + 1);
                heap.Put(heap.Size() + 1, mExp.Eval(symTable, heap));
            }
            else
            {
                symTable.Add(mVarName, heap.Size() + 1);
                heap.Put(heap.Size() + 1, mExp.Eval(symTable, heap));
            }

            return(null);
        }
Example #17
0
        public PrgState Execute(PrgState state)
        {
            Exp exp = this.exp;
            Stack <MyIDictionary <MyMap> > symTbl = state.GetSymTable();
            String       id  = this.id;
            IHeap <HMap> h   = state.GetHeap();
            int          val = exp.Eval(symTbl, h);

            if (symTbl.ElementAt(0).IsDefined(id))
            {
                symTbl.ElementAt(0).Update(id, val);
            }
            else
            {
                MyMap m = new MyMap(id, val);
                symTbl.ElementAt(0).Add(m);
            }
            return(null);
        }
Example #18
0
        public PrgState Execute(PrgState state)
        {
            MyIDictionary <int, MyPair <String, StreamReader> > fileTable = state.GetFileTable();

            foreach (MyIPair <String, StreamReader> ff in fileTable.Values())
            {
                if (ff.GetFirst().Equals(this.filename))
                {
                    throw new MyException("File already used");
                }
            }
            MyIDictionary <String, int> symTable = state.GetSymTable();
            StreamReader streamReader            = new StreamReader(this.filename);
            int          unq = ran++;
            MyPair <String, StreamReader> tup = new MyPair <String, StreamReader>(this.filename, streamReader);

            fileTable.Add(unq, tup);
            symTable.Add(var_file_id, unq);
            return(state);
        }
Example #19
0
        public PrgState Execute(PrgState state)
        {
            Stack <MyIDictionary <MyMap> > symTbl = state.GetSymTable();
            IHeap <HMap> heap  = state.GetHeap();
            String       v     = this.var;
            int          index = heap.GiveHeapLocation();

            int val = exp.Eval(symTbl, heap);

            if (symTbl.ElementAt(0).IsDefined(v))
            {
                symTbl.ElementAt(0).Update(v, index);
            }

            else
            {
                MyMap m = new MyMap(v, index);
                symTbl.ElementAt(0).Add(m);
            }

            heap.Add1(val);

            return(null);
        }
Example #20
0
        public PrgState <T> Execute <T>(PrgState <T> state)
        {
            state.AddOut(mExp.Eval(state.GetSymTable(), state.GetHeap()).ToString());

            return(null);
        }