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); }
public ProgState( MyIntStack <IntStatement> stack, MyIntDict <String, int> dict, MyIntList <int> list, IntFileTable _fileTable, IntStatement statement) { execStack = stack; symTable = dict; output = list; filetable = _fileTable; originalProgram = statement; execStack.push(statement); }
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); }
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); }