Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public ProgState execute(ProgState state)
        {
            MyIntStack <IntStatement> stack = state.getExecStack();

            stack.push(second);
            stack.push(first);
            return(null);
        }
Ejemplo n.º 3
0
        public ProgState execute(ProgState state)
        {
            MyIntList <int> dataout = state.getOut();

            try {
                dataout.add(exp.eval(state.getSymTable()));
            }
            catch (MyException.MyException e) {
                throw e;
            }
            return(null);
        }
Ejemplo n.º 4
0
        public ProgState execute(ProgState state)
        {
            MyIntDict <String, int> tabel = state.getSymTable();
            int val;

            try {
                val = exp.eval(tabel);
                if (tabel.exists(id))
                {
                    tabel.update(id, val);
                }
                else
                {
                    tabel.add(id, val);
                }
            }
            catch (MyException.MyException e) {
                throw e;
            }
            return(null);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        public ProgState execute(ProgState state)
        {
            MyIntDict <String, int>   tabel = state.getSymTable();
            MyIntStack <IntStatement> stack = state.getExecStack();
            int val;

            try {
                val = exp.eval(tabel);
            }
            catch (MyException.MyException e) {
                throw e;
            }
            if (val != 0)
            {
                stack.push(first);
            }
            else
            {
                stack.push(second);
            }
            return(null);
        }
Ejemplo n.º 7
0
        public ProgState execute(ProgState state)
        {
            IntFileTable fileTable = state.getFileTable();

            if (fileTable.file_is_open(filename))
            {
                throw new MyException.MyException("File is already open!");
            }

            StreamReader reader;

            try{
                reader = new StreamReader(filename);
            } catch (IOException e) {
                throw new MyException.MyException("Invalid path");
            }
            int index = fileTable.add(new Tuple <String, StreamReader>(filename, reader));
            MyIntDict <String, int> symtable = state.getSymTable();

            symtable.add(var_file_id, index);
            return(null);
        }