Simple LogicParser in Python