Skip to content

Instantly share code, notes, and snippets.

@jterrazz
Created August 29, 2019 09:37
Show Gist options
  • Save jterrazz/16b6ce2f6e5da81f2e83fe8d950347f2 to your computer and use it in GitHub Desktop.
Save jterrazz/16b6ce2f6e5da81f2e83fe8d950347f2 to your computer and use it in GitHub Desktop.
stack = []
for x in npi_rule:
if x not in OPERATORS:
stack.append(self.atoms[x])
else:
pop0 = stack.pop()
pop1 = stack.pop()
# If one of the popped element is the same connector that we will create (AND, OR, XOR)
if isinstance(pop0, ConnectorNode) and pop0.type is LST_OP[x]:
pop0.add_operand(pop1)
new_connector = pop0
self.connectors.pop()
elif isinstance(pop1, ConnectorNode) and pop1.type is LST_OP[x]:
pop1.add_operand(pop0)
new_connector = pop1
self.connectors.pop()
else:
connector_x = self.create_connector(LST_OP[x])
connector_x.add_operands([pop0, pop1])
new_connector = connector_x
self.connectors.append(new_connector)
stack.append(new_connector)
return stack.pop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment