public PrgState execute(PrgState state) { MyIStack <IStmt> stack = state.getStk(); MyIDictionary <string, int> symTable = state.getSymTable(); int val = exp.Eval(symTable); if (symTable.isDefined(id)) { symTable.update(id, val); } else { symTable.put(id, val); } return(null); }
public PrgState execute(PrgState state) { MyIStack <IStmt> stk = state.getExeStack(); MyIDictionary <String, int> symTbl = state.getSymTable(); IFileTable <int, FileTuple> fileTbl = state.getFileTable(); int value_exp = this.exp_file_id.eval(symTbl); FileTuple ft = fileTbl.getValue(value_exp); if (!symTbl.isDefined(ft.getFileName())) { //throw new MyStmtExecException("The key is not defined in the file table"); } StreamReader streamReader = ft.getStreamReader(); int val = -1; try { String line = streamReader.ReadLine(); if (line == null) { val = 0; } else { try { val = int.Parse(line); } catch (Exception ex) { Console.WriteLine(ex.Message); } } symTbl.put(this.var_name, val); } catch (IOException ex) { throw new Exception(ex.Message); } return(state); }
public PrgState execute(PrgState state) { MyIStack <IStmt> stk = state.getExeStack(); IFileTable <int, FileTuple> filetable = state.getFileTable(); MyIDictionary <String, int> symTbl = state.getSymTable(); try { FileStream reader = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read); StreamReader bufferedStream = new StreamReader(reader); int id = IdGenerator.generateId(); FileTuple tuple = new FileTuple(this.filename, bufferedStream); filetable.put(id, tuple); symTbl.put(this.var_file_id, id); } catch (Exception ex) { throw new Exception(ex.Message); } return(state); }
public PrgState execute(PrgState state) { MyIStack <IStmt> stk = state.getExeStack(); MyIDictionary <String, int> symTbl = state.getSymTable(); try { int val = exp.eval(symTbl); //if (!symTbl.isDefined(this.id)) //throw new MyStmtExecException("The variable is not assigned"); //int address = symTbl.get(this.id); //heap.put(address, val); symTbl.put(this.id, val); //we assign the new values } catch (Exception ex) { Console.WriteLine("ASSIGN ERROR"); } return(state); }
public void addCommand(Command c) { commands.put(c.getKey(), c); }