public void PrintMenu() { foreach (Command com in commands.Values()) { String line = " " + com.GetKey() + ": " + com.GetDescription(); Console.WriteLine(line); } }
public ProgramState Execute(ProgramState state) { MyIDictionary <int, MyPair <string, StreamReader> > fileTable = state.GetFileTab(); MyIDictionary <string, int> symTable = state.GetSymTab(); // 1. check whether the filename is not already in the file table // If it exists stop the execution with an appropiate error message foreach (MyPair <string, StreamReader> pair in fileTable.Values()) { if (pair.GetFirst().Equals(filename)) { throw new MyStatementExecutionException("File " + filename + " already open."); } } // 2. open the file filename. If the file does not exists or other IO error occurs, // stop the execution with an appropiate error message StreamReader sr; try { sr = new StreamReader(filename); } catch (FileNotFoundException) { throw new MyStatementExecutionException("File " + filename + " does not exist"); } catch (IOException e) { throw new MyStatementExecutionException(e.ToString()); } // 3. create a new entrance into the file table which maps a new unique integer id // to the (filename, StreamReader class created before) pair fileTable.Put(++fd, new MyPair <string, StreamReader>(filename, sr)); // 4. set the var_file_id to that new unique integer key into the sym-table. symTable.Put(var_file_id, fd); // 5. return return(null); }
public PrgState Execute(PrgState state) { MyIDictionary <int, MyPair <String, StreamReader> > fileTable = state.GetFileTable(); foreach (MyIPair <String, StreamReader> ff in fileTable.Values()) { if (ff.GetFirst().Equals(this.filename)) { throw new MyException("File already used"); } } MyIDictionary <String, int> symTable = state.GetSymTable(); StreamReader streamReader = new StreamReader(this.filename); int unq = ran++; MyPair <String, StreamReader> tup = new MyPair <String, StreamReader>(this.filename, streamReader); fileTable.Add(unq, tup); symTable.Add(var_file_id, unq); return(state); }