Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. def parse(self, exp):
  2. opers = []
  3. output = []
  4. for x in exp:
  5. if x in self.ops:
  6. if opers:
  7. while opers and self.ops.get(opers[-1]) >= self.ops.get(x):
  8. output.append(opers.pop())
  9. opers.append(x)
  10. elif x == '(':
  11. opers.append(x)
  12. elif x == ')':
  13. while opers and opers[-1] != '(':
  14. output.append(opers.pop())
  15. opers.pop()
  16. else:
  17. output.append(x)
  18. while opers:
  19. x = opers.pop()
  20. if x != '(' and x != ')':
  21. output.append(x)
  22. return output
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement