Beispiel #1
0
 public override int eval(ImyDict <string, int> sym)
 {
     try
     {
         return(sym.get(name));
     }
     catch (Exception) {
         throw new ExpException("Variable " + name + " is not in the sym table\n");
     }
 }
Beispiel #2
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);
            }
        }
Beispiel #3
0
        public PrgState 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;
                buffReader.Close();
                fileTable.remove(v);
            } catch (Exception) {
                throw new StmtException("File does not exist or hasn't been open");
            }

            return(null);
        }