Пример #1
0
def TestTP():
    a1 = Automaton("dummy")
    a1.from_txtfile("test/a.af")
    a2 = Automaton("dummy1")
    a2.from_txtfile("test/b.af")
    a1.to_graphviz(a1.name + ".gv")
    a2.to_graphviz(a2.name + ".gv")
    print(a1)
    print(a2)
    print(concat(a1, a2))
    a1star = kleene(a1)
    print()
    print(a1star)
    a1star.to_graphviz("a1star.gv")

    a1a2 = concat(a1, a2)
    print()
    print(a1a2)
    a1a2.to_graphviz("a1a2.gv")

    a1ora2 = union(a1, a2)
    print()
    print(a1ora2)
    a1ora2.to_graphviz("a1ora2.gv")
Пример #2
0
def union(a1: Automaton, a2: Automaton) -> Automaton:
    # TODO: implement union
    return a1


##################

if __name__ == "__main__":
    if len(sys.argv) != 3:
        usagestring = "Usage: {} <automaton-file1.af> <automaton-file2.af>"
        error(usagestring.format(sys.argv[0]))

    # First automaton, argv[1]
    a1 = Automaton("dummy")
    a1.from_txtfile(sys.argv[1])
    a1.to_graphviz(a1.name + ".gv")
    print(a1)

    # Second automaton, argv[2]
    a2 = Automaton("dummy")
    a2.from_txtfile(sys.argv[2])
    a2.to_graphviz(a2.name + ".gv")
    print(a2)

    a1star = kleene(a1)
    print()
    print(a1star)
    a1star.to_graphviz("a1star.gv")

    a1a2 = concat(a1, a2)
Пример #3
0
    return False


##################


def recognizes(a: 'Automaton', word: str) -> bool:
    #TODO implement!
    return False


##################

if __name__ == "__main__":
    if len(sys.argv) != 3:
        usagestring = "Usage: {} <automaton-file.af> <word-to-recognize>"
        error(usagestring.format(sys.argv[0]))

    automatonfile = sys.argv[1]
    word = sys.argv[2]

    a = Automaton("dummy")
    a.from_txtfile(automatonfile)

    if not is_deterministic(a):
        print("ERROR")
    elif recognizes(a, word):
        print("YES")
    else:
        print("NO")