Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. public void parseStmt(String token) throws IOException
  2. {
  3. int val;
  4. String text;
  5. if (token.equals("load")) // ::= load <string>
  6. {
  7. token = getToken();
  8. text = parseString(token);
  9.  
  10. line = loadFile(text) + line;
  11. }
  12. else if (token.equals("print")) // ::= print <string> | print <expr>
  13. {
  14. token = getToken();
  15.  
  16. if (token.charAt(0) == '"')
  17. {
  18. text = parseString (token);
  19.  
  20. // execute part
  21. if (eval == true)
  22. System.out.println(text);
  23. }
  24. else
  25. {
  26. val = parseExpr(token);
  27.  
  28. // execute part
  29. if (eval == true)
  30. System.out.println(val);
  31. }
  32. }
  33. else if (token.equals("input")) // ::= input <var>
  34. {
  35. token = getToken();
  36. val = parseVar(token);
  37.  
  38. // execute part
  39. if (eval == true)
  40. {
  41. System.out.print("? ");
  42. val = scan.nextInt();
  43. storeVar(token, val);
  44. }
  45. }
  46. else if (token.equals("if"))
  47. {
  48. token = getToken();
  49. // determines whether the condition was true or not
  50. boolean cond = parseCond(token);
  51. // assigns the boolean value (true or false) to the global eval boolean
  52. eval = cond;
  53. token = getToken();
  54. parseStmt(token);
  55. }
  56. else if (isVar(token))
  57. {
  58. }
  59. else
  60. {
  61. reportError(token);
  62. }
  63. eval = true;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement