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 override int eval(MyIntDict <String, int> tab) { try { return(tab.get(id)); } catch (MyException.MyException ex) { throw ex; } }
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> 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); }
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) { MyIntDict <String, int> tabel = state.getSymTable(); MyIntStack <IntStatement> stack = state.getExecStack(); int val; try { val = exp.eval(tabel); } catch (MyException.MyException e) { throw e; } if (val != 0) { stack.push(first); } else { stack.push(second); } 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); }
override public int eval(MyIntDict <string, int> tab) { int val = 0; switch (op) { case 1: { val = first.eval(tab) + second.eval(tab); break; } case 2: { val = first.eval(tab) - second.eval(tab); break; } case 3: { val = first.eval(tab) * second.eval(tab); break; } case 4: { int divisor = second.eval(tab); if (divisor == 0) { throw new MyException.MyException("Divide by zero"); } val = first.eval(tab) / divisor; break; } default: break; } return(val); }
abstract public int eval(MyIntDict <string, int> tab);
public override int eval(MyIntDict <String, int> tab) { return(val); }