예제 #1
0
 def visit(tree):
     if DEBUG:
         print(f"step--{tree}")
         print(f"type:{type(tree)}")
         print(f"children:{len(tree.children)}")
     if isinstance(tree, Tree):
         # rule matches that propagate the visitor down to the actual rules / operations
         if tree.data == "start":
             return get_operations.visit(tree.children[0])
         if tree.data == "orexpr":
             return get_operations.visit(tree.children[0])
         if tree.data == "andexpr":
             return get_operations.visit(tree.children[0])
         if tree.data == "notexpr":
             return get_operations.visit(tree.children[0])
         if tree.data == "implyexpr":
             return get_operations.visit(tree.children[0])
         if tree.data == "bicondexpr":
             return get_operations.visit(tree.children[0])
         # return the value of the variable to the last operation
         if tree.data == "variable":
             opvar = TreeNodes.OP_VAR(tree.children[0].value)
             if not opvar in get_operations.operations:
                 get_operations.operations.append(opvar)
             return opvar
         # the operations
         if tree.data == "not":
             opnot = TreeNodes.OP_NOT(get_operations.visit(tree.children[0]))
             if not opnot in get_operations.operations:
                 get_operations.operations.append(opnot)
             return opnot
         if tree.data == "and":
             opand = TreeNodes.OP_AND(get_operations.visit(tree.children[0]), get_operations.visit(tree.children[1]))
             if not opand in get_operations.operations:
                 get_operations.operations.append(opand)
             return opand
         if tree.data == "or":
             opor = TreeNodes.OP_OR(get_operations.visit(tree.children[0]), get_operations.visit(tree.children[1]))
             if not opor in get_operations.operations:
                 get_operations.operations.append(opor)
             return opor
         if tree.data == "bicondition":
             bicondop = TreeNodes.OP_BICOND(get_operations.visit(tree.children[0]), get_operations.visit(tree.children[1]))
             if not bicondop in get_operations.operations:
                 get_operations.operations.append(bicondop)
             return bicondop
         if tree.data == "imply":
             opimply = TreeNodes.OP_IMPLY(get_operations.visit(tree.children[0]), get_operations.visit(tree.children[1]))
             if not opimply in get_operations.operations:
                 get_operations.operations.append(opimply)
             return opimply
         if tree.data == "parentesis":
             paren = TreeNodes.OP_PAREN(get_operations.visit(tree.children[0]))
             return paren