Guest User

ICE

a guest
Mar 29th, 2016
175
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Define empty stack
  2. Define empty output
  3. Define precedence = [
  4. "->" => 7
  5. "and" => 6
  6. "xor" => 5
  7. "or" => 5
  8. "<!=>" => 4
  9. "^" => 3
  10. "*" => 2
  11. "/" => 2
  12. "+" => 1
  13. "-" => 1
  14. ]
  15. For each token in input {
  16. Read token
  17. If token == number {
  18. If output == empty {
  19. Add type+token to output
  20. } else {
  21. If previous token was a number {
  22. Temp = last token from output
  23. Replace Temp with Temp*10+token
  24. } else {
  25. Add type+token to output
  26. }
  27. }
  28. } elseif token == operator || token == boolean {
  29. while last token on stack == operator {
  30. if (token != '^' && precedence[last token] <= precedence[token]) || (token == '^' && precedence[last token] < precedence[token]) {
  31. Move type+token from stack to output
  32. } else {
  33. break the loop
  34. }
  35. }
  36. Add type+token to stack
  37. } elseif token == ',' {
  38. while last token on stack != '(' {
  39. Move type+token from stack to output
  40. }
  41. } elseif token == ')' {
  42. while last token on stack != '(' {
  43. Move type+token from stack to output
  44. }
  45. If last token on stack == function {
  46. Move type+token from stack to output
  47. }
  48. } else {
  49. Add type+token to stack
  50. }
  51. }
  52. For each token in stack {
  53. Move type+token from stack to output
  54. }
  55. For each token in output - 2 {
  56. If token+2 != number {
  57. If operator == "+" {
  58. If both tokens are numbers {
  59. Add both numbers
  60. } elseif one of the tokens is a number {
  61. Load variable in A
  62. Add number
  63. } else {
  64. Load variable in A
  65. Add the other variable
  66. }
  67. Remove 2 elements in output
  68. } elseif operator == "-" {
  69. If both tokens are numbers {
  70. Sub both numbers
  71. } elseif one of the tokens is a number {
  72. Load variable in A
  73. Sub number
  74. } else {
  75. Load variable in A
  76. Sub the other variable
  77. }
  78. Remove 2 elements in output
  79. } elseif operator == "*" {
  80. If both tokens are numbers {
  81. Mul both numbers
  82. } else if one of the tokens is a number {
  83. Load variable in H
  84. Load number in L
  85. Mul HL
  86. Load L in A
  87. } else {
  88. Load variable in H
  89. Load variable in L
  90. Mul HL
  91. Load L in A
  92. }
  93. Remove 2 elements in output
  94. }
  95. } else {
  96. }
  97. }
RAW Paste Data