public ProgState execute(ProgState prog) { MyIDictionary <string, int> dict = prog.getDict(); try { if (dict.isDefined(this.id) == 1) { dict.update(id, exp.eval(dict)); } else { dict.add(id, exp.eval(dict)); } return(prog); } catch (StmtExceptions e) { throw new ControllerException(e); } catch (DivizionByZeroException e) { throw new ControllerException(e); } }
public ProgState execute(ProgState prog) { MyIDictionary <string, int> dict = prog.getDict(); MyIFileTable <Tuple> Tpl = prog.getFile(); try { int val = exp.eval(dict); Tuple tpl = Tpl.get(val); if (tpl != null) { tpl.getST().Close(); Tpl.remove(val); } else { throw new ControllerException("The file does not exist!! \n"); } } catch (StmtExceptions e) { throw new ControllerException(e); } catch (IOException e) { Console.WriteLine(e.ToString()); } return(prog); }
public ProgState execute(ProgState prog) { MyIDictionary <string, int> dict = prog.getDict(); MyIFileTable <Tuple> Tpl = prog.getFile(); try { if (Tpl.isEmpty() == 1) { for (int i = 1; i <= Tpl.getKey(); i++) { Tuple tpl = Tpl.get(i); if (tpl != null && tpl.getName() == filename) { throw new ControllerException("The file does not exist!! \n"); } } } StreamReader st = new StreamReader(filename); Tuple tup = new Tuple(filename, st); Tpl.add(tup); dict.add(varName, Tpl.getKey()); return(prog); } catch (FileNotFoundException e) { Console.WriteLine(e.ToString()); } catch (DictExceptions e) { throw new ControllerException(e.ToString()); } return(null); }
public ProgState execute(ProgState prog) { MyIList <int> list = prog.getList(); MyIDictionary <string, int> dict = prog.getDict(); try { list.add(ex.eval(dict)); return(prog); } catch (StmtExceptions e) { throw new ControllerException(e); } }
public ProgState execute(ProgState prog) { MyIStack <IStmt> stk = prog.getStk(); MyIDictionary <string, int> dict = prog.getDict(); try { if (ex.eval(dict) > 0) { stk.push(thenS); } else { stk.push(elseS); } } catch (StmtExceptions e) { throw new ControllerException(e); } return(prog); }
public ProgState execute(ProgState prog) { MyIDictionary <string, int> dict = prog.getDict(); MyIFileTable <Tuple> tpl = prog.getFile(); try { int val = exp.eval(dict); Tuple tup = tpl.get(val); if (tup != null) { string st = tup.getST().ReadLine(); if (st != null) { if (dict.isDefined(name) == 0) { dict.add(name, int.Parse(st)); } else { dict.update(name, int.Parse(st)); } } } else { throw new ControllerException("The file does not exist !!! \n"); } } catch (StmtExceptions e) { throw new ControllerException(e); } catch (IOException e) { Console.WriteLine(e.ToString()); } return(prog); }