public ProgState execute(ProgState programState) { try { int descriptor = fileDescriptor.evaluate(programState.getSymbolTable); FileTable <int, FileData> fileTable = programState.getFileTable; StreamReader bufferedReader = fileTable.getValue(descriptor).Buffer; string line = bufferedReader.ReadLine(); ConstExpr value; if (line == null) { value = new ConstExpr(0); } else { value = new ConstExpr(int.Parse(line)); } Statement assignment = new AssignStmt(variable, value); return(assignment.execute(programState)); } catch (IOException) { throw (new InterpreterException("error: file could not be read")); } }
public ProgState execute(ProgState state) { SymbolTable <string, int> table = state.getSymbolTable; Output <int> outs = state.getOutput; outs.add(exp.evaluate(table)); return(state); }
public ProgState execute(ProgState state) { ExeStack <Statement> stack = state.getExeStack; stack.push(stm2); stack.push(stm1); return(state); }
public ProgState execute(ProgState state) { SymbolTable <string, int> table = state.getSymbolTable; int val = exp.evaluate(table); table.add(name, val); return(state); }
public ProgState execute(ProgState state) { ExeStack <Statement> stack = state.getExeStack; SymbolTable <string, int> table = state.getSymbolTable; int val = exp.evaluate(table); if (val != 0) { stack.push(stm1); } else { stack.push(stm2); } return(state); }
public ProgState execute(ProgState programState) { try { int descriptor = fileDescriptor.evaluate(programState.getSymbolTable); FileTable <int, FileData> fileTable = programState.getFileTable; StreamReader bufferedReader = fileTable.getValue(descriptor).Buffer; bufferedReader.Close(); fileTable.remove(descriptor); return(programState); } catch (IOException) { throw (new InterpreterException("error: file could not be closed")); } }
public ProgState execute(ProgState state) { FileTable <int, FileData> fileT = state.getFileTable; if (isOpen(fileName, fileT)) { throw new InterpreterException("error: file could not be open"); } try { StreamReader bufferedReader = new StreamReader(fileName); FileData fd = new FileData(fileName, bufferedReader); int id = Generator.generator(); SymbolTable <string, int> symT = state.getSymbolTable; fileT.add(id, fd); symT.add(fileId, id); } catch (IOException e) { throw new InterpreterException("error: file could not be open"); } return(state); }