Example #1
0
        public ProgState execute(ProgState state)
        {
            MyIntDict <String, int> symtable  = state.getSymTable();
            IntFileTable            filetable = state.getFileTable();

            if (!symtable.exists(exp_file_id))
            {
                throw new MyException.MyException("File descriptor not found!");
            }
            int index_file = symtable.get(exp_file_id);

            if (!filetable.exists(index_file))
            {
                throw new MyException.MyException("File descriptor does not exist!");
            }
            StreamReader reader = filetable.get(index_file).Item2;

            try {
                reader.Close();
            } catch (IOException e) {
                throw new MyException.MyException("File can not be close!");
            }
            filetable.remove(index_file);
            return(null);
        }
Example #2
0
 public override int eval(MyIntDict <String, int> tab)
 {
     try {
         return(tab.get(id));
     }
     catch (MyException.MyException ex) {
         throw ex;
     }
 }
Example #3
0
        public ProgState execute(ProgState state)
        {
            MyIntDict <String, int> symtable  = state.getSymTable();
            IntFileTable            filetable = state.getFileTable();

            if (!symtable.exists(exp_file_id))
            {
                throw new MyException.MyException("File descriptor not found!");
            }
            int index_file = symtable.get(exp_file_id);

            if (!filetable.exists(index_file))
            {
                throw new MyException.MyException(("File descriptor does not exist!"));
            }
            StreamReader reader = filetable.get(index_file).Item2;
            String       line;

            try {
                line = reader.ReadLine();
            } catch (IOException e) {
                line = "";
            }
            int value = 0;

            if (line != "")
            {
                value = Int32.Parse(line);
            }

            if (symtable.exists(var_name))
            {
                symtable.update(var_name, value);
            }
            else
            {
                symtable.add(var_name, value);
            }
            return(null);
        }