• API
• FAQ
• Tools
• Archive
SHARE
TWEET # ICE a guest Mar 29th, 2016 84 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 {
17.     If token == number {
18.         If output == empty {
20.         } else {
21.             If previous token was a number {
22.                 Temp = last token from output
23.                 Replace Temp with Temp*10+token
24.             } else {
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.         }
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 {
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 {
60.             } elseif one of the tokens is a number {
63.             } else {
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 {
73.                 Sub number
74.             } else {
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 {
85.                 Mul HL
87.             } else {