Beispiel #1
0
        public void execute(PrgState state)
        {
            ImyDict <int, Tuple <string, StreamReader> > fileTable = state.getFileTable();
            ImyDict <string, int> symTable = state.getSymTable();

            try {
                if (fileTable.isInTuple(this.filename))
                {
                    throw new StmtException("File allready opened");
                }
            } catch (Exception e1) {
                throw new StmtException("Statement \"" + this.ToString() + "\" encountered a dictionary exception: " + e1.Message);
            }
            StreamReader buffReader;

            try {
                buffReader = new StreamReader(filename);
            } catch (FileNotFoundException) {
                throw new StmtException("File not found \"" + filename + "\"");
            }

            Tuple <string, StreamReader> entry = new Tuple <string, StreamReader>(filename, buffReader);
            int id = fileTable.generateId();

            fileTable.add(id, entry);
            symTable.add(var_file_id, id);
        }
Beispiel #2
0
        public void execute(PrgState state)
        {
            ImyDict <string, int> symTable = state.getSymTable();

            int val;

            try {
                val = e.eval(symTable);
                symTable.add(id, val);
            } catch (ExpException e) {
                throw new StmtException("Statement \"" + this.ToString() + "\": " + e.Message);
            }
        }
Beispiel #3
0
        public void execute(PrgState state)
        {
            ImyDict <string, int> symTable = state.getSymTable();
            ImyDict <int, Tuple <string, StreamReader> > fileTable = state.getFileTable();

            int          v;
            StreamReader buffReader;

            try {
                v = exp_file_id.eval(symTable);
            } catch (ExpException e) {
                throw new StmtException("Expression \"" + exp_file_id + "\" in statement + \"" + this.ToString() + "\" is invalid: " + e.Message);
            }

            try {
                buffReader = fileTable.get(v).Item2;
            } catch (Exception) {
                throw new StmtException("File does not exist or hasn't been open \"" + exp_file_id.ToString() + "\"");
            }

            try {
                string readValue = buffReader.ReadLine();

                int value;

                if (readValue == null)
                {
                    value = 0;
                }
                else
                {
                    Int32.TryParse(readValue, out value);
                }

                symTable.add(var_name, value);
            } catch (IOException e2) {
                throw new StmtException("Statement \"" + this.ToString() + "\" encountered an exception: " + e2.Message);
            }
        }