Advertisement
Guest User

ff

a guest
Jan 23rd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. package Model.Statements;
  2.  
  3. import Exceptions.MyStmtException;
  4. import Model.Expressions.ConstExp;
  5. import Model.Expressions.Exp;
  6. import Model.PrgState;
  7. import Model.Utils.MyIDictionary;
  8. import Model.Utils.MyIHeap;
  9. import Model.Utils.MyIStack;
  10.  
  11. public class sleepStmt implements IStmt{
  12. Exp number;
  13.  
  14. public sleepStmt(Exp nr){
  15. this.number = nr;
  16. }
  17.  
  18. public PrgState execute(PrgState state){
  19. MyIStack<IStmt> localStack= state.getStk();
  20. MyIDictionary<String, Integer> localSym = state.getSymTable();
  21. MyIHeap<Integer> localHeap = state.getHeap();
  22.  
  23. Integer nr = null;
  24. try {
  25. nr = this.number.eval(localSym,localHeap);
  26. } catch (MyStmtException e) {
  27. e.printStackTrace();
  28. }
  29. Integer nr1 = nr;
  30.  
  31. if(nr > 0){
  32. nr1 = nr - 1;
  33. localStack.push(new sleepStmt(new ConstExp(nr1)));
  34. }
  35. return null;
  36. }
  37.  
  38. public String toString(){
  39. String rez = "";
  40. rez = rez + "sleep(" + this.number.toString() + ")";
  41. return rez;
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement