示例#1
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);
 }
示例#2
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);
        }
示例#3
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);
        }