Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Define empty stack
- Define empty output
- Define precedence = [
- "->" => 7
- "and" => 6
- "xor" => 5
- "or" => 5
- "<!=>" => 4
- "^" => 3
- "*" => 2
- "/" => 2
- "+" => 1
- "-" => 1
- ]
- For each token in input {
- Read token
- If token == number {
- If output == empty {
- Add type+token to output
- } else {
- If previous token was a number {
- Temp = last token from output
- Replace Temp with Temp*10+token
- } else {
- Add type+token to output
- }
- }
- } elseif token == operator || token == boolean {
- while last token on stack == operator {
- if (token != '^' && precedence[last token] <= precedence[token]) || (token == '^' && precedence[last token] < precedence[token]) {
- Move type+token from stack to output
- } else {
- break the loop
- }
- }
- Add type+token to stack
- } elseif token == ',' {
- while last token on stack != '(' {
- Move type+token from stack to output
- }
- } elseif token == ')' {
- while last token on stack != '(' {
- Move type+token from stack to output
- }
- If last token on stack == function {
- Move type+token from stack to output
- }
- } else {
- Add type+token to stack
- }
- }
- For each token in stack {
- Move type+token from stack to output
- }
- For each token in output - 2 {
- If token+2 != number {
- If operator == "+" {
- If both tokens are numbers {
- Add both numbers
- } elseif one of the tokens is a number {
- Load variable in A
- Add number
- } else {
- Load variable in A
- Add the other variable
- }
- Remove 2 elements in output
- } elseif operator == "-" {
- If both tokens are numbers {
- Sub both numbers
- } elseif one of the tokens is a number {
- Load variable in A
- Sub number
- } else {
- Load variable in A
- Sub the other variable
- }
- Remove 2 elements in output
- } elseif operator == "*" {
- If both tokens are numbers {
- Mul both numbers
- } else if one of the tokens is a number {
- Load variable in H
- Load number in L
- Mul HL
- Load L in A
- } else {
- Load variable in H
- Load variable in L
- Mul HL
- Load L in A
- }
- Remove 2 elements in output
- }
- } else {
- }
- }
Add Comment
Please, Sign In to add comment