Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }