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)
        {
            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);
        }