text: from lexer import *
  
  
  class Postfixer:
      def __init__(self, tokens):
          self.tokens = tokens
  
      def prefix_postfix(self):
          idx = 0
          while idx < len(self.tokens) - 1:
              token = self.tokens[idx]
              if token.ttype == TokenType.NOT:
                  tmp = token
                  self.tokens[idx] = self.tokens[idx + 1]
                  self.tokens[idx + 1] = tmp
                  idx += 2
              idx += 1
  
      def infix_postfix(self):
          stack = []
          ret = []
          for token in self.tokens:
              print(token.ttype)
              if token.ttype == TokenType.VAR or token.ttype == TokenType.NOT:
                  ret.append(token)
              elif (
                  token.ttype == TokenType.AND
                  or token.ttype == TokenType.OR
                  or token.ttype == TokenType.IMPLIES
              ):
                  while len(stack) > 0:
                      if (
                          stack[-1].ttype == TokenType.AND
                          or stack[-1].ttype == TokenType.OR
                          or stack[-1].ttype == TokenType.IMPLIES
                      ):
                          ret.append(stack.pop())
                      else:
                          break
                  stack.append(token)
              elif token.ttype == TokenType.LPAREN:
                  stack.append(token)
              elif token.ttype == TokenType.RPAREN:
                  while len(stack) > 0:
                      if (
                          stack[-1].ttype == TokenType.AND
                          or stack[-1].ttype == TokenType.OR
                      ):
                          ret.append(stack.pop())
                      elif stack:
                          stack.pop()
          if len(stack) > 0:
              ret += list(reversed(stack))
          self.tokens = ret
  