public PrgState Execute(PrgState state) { MyIDictionary <String, int> symTable = state.GetSymTable(); int file_id = this.exp_file_id.Eval(symTable); MyIPair <String, StreamReader> fileTable = state.GetFileTable().Lookup(file_id); if (fileTable == null) { throw new MyException("File not opened"); } int anotherVal; String line = fileTable.GetSecond().ReadLine(); if (line == null) { anotherVal = 0; } else { anotherVal = System.Convert.ToInt32(line); } if (symTable.IsDefinedU(var_name)) { symTable.Update(var_name, anotherVal); } else { symTable.Add(var_name, anotherVal); } return(state); }
public int Add(string fileName) { if (FileExists(fileName)) { throw new FileTableException("Duplicate file name!"); } int fileDescriptor = positionTable.CurrentFree; TextReader reader; try { reader = new StreamReader(fileName); }catch (Exception) { throw new FileTableException("Could not open file!"); } fileTable.Add(fileDescriptor, new Tuple <string, TextReader>(fileName, reader)); positionTable.UpdateCurrentFree(); return(fileDescriptor); }
public void AddSymTable(string id, int val) { try { symTable.Add(id, val); } catch (DataTypesException e) { Console.WriteLine(e.StackTrace); throw new ExpException("Error at addSymTable"); } }
public PrgState Execute(PrgState state) { MyIStack <IStmt> stk = state.GetExeStack(); MyIDictionary <String, int> symTbl = state.GetSymTable(); int val = exp.Eval(symTbl); if (symTbl.IsDefinedU(id)) { symTbl.Update(id, val); } else { symTbl.Add(id, val); } return(state); }
public ProgramState Execute(ProgramState programState) { MyIDictionary <string, int> symbolTable = programState.SymbolTable; int value = expression.Evaluate(symbolTable); if (symbolTable.ContainsKey(id)) { symbolTable.Update(id, value); } else { symbolTable.Add(id, value); } return(programState); }
public PrgState <T> Execute <T>(PrgState <T> state) { MyIDictionary symTbl = state.GetSymTable(); int val; val = mExp.Eval(symTbl, state.GetHeap()); if (symTbl.IsDefined(mId)) { symTbl.Update(mId, val); } else { symTbl.Add(mId, val); } return(null); }
public PrgState <T> Execute <T>(PrgState <T> state) { MyIHeap heap = state.GetHeap(); MyIDictionary symTable = state.GetSymTable(); if (symTable.IsDefined(mVarName)) { symTable.Update(mVarName, heap.Size() + 1); heap.Put(heap.Size() + 1, mExp.Eval(symTable, heap)); } else { symTable.Add(mVarName, heap.Size() + 1); heap.Put(heap.Size() + 1, mExp.Eval(symTable, heap)); } 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); }
public ProgramState Execute(ProgramState programState) { MyIDictionary <string, int> symbolTable = programState.SymbolTable; int fileDescriptor = expFileId.Evaluate(symbolTable); if (!programState.FileTable.TryGetValue(fileDescriptor, out Tuple <string, TextReader> value)) { throw new StatementException("Invalid file id provided!"); } TextReader reader = value.Item2; string line; try { line = reader.ReadLine(); }catch (Exception) { throw new StatementException("Error while reading from file!"); } int intValue = 0; if (line != null && !int.TryParse(line, out intValue)) { throw new StatementException("File contains non-numeric values!"); } if (symbolTable.ContainsKey(varName)) { symbolTable.Update(varName, intValue); } else { symbolTable.Add(varName, intValue); } return(programState); }
public void AddCommand(Command command) { commands.Add(command.Key, command); }
public void addCommand(Command c) { commands.Add(c.GetKey(), c); }