-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
31 lines (21 loc) · 836 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from grammar import Grammar
from CYKAlgo import CYKAlgo
def main():
# G = Grammar("S->AB|XB;T->AB|XB;X->AT;A->a;B->b")
# w="aaabb"
print("Welcome to the CYK Interactive algorithm!")
command = "y"
while(command == "y"):
grammar_text = input("Enter the grammar in CNF form (E.g. S->AB|a;A->a;B->b): ")
if grammar_text == "": break
G = Grammar(grammar_text.strip())
w = input("Enter the string to check: ")
cykAlgo = CYKAlgo(G)
if (cykAlgo.membership(w.strip())):
print("The string w=\"{}\" is in grammar G!".format(w))
else:
print("The string w=\"{}\" is not in grammar G!".format(w))
command = input("To continue enter \"y\" or press any key to exit: ")
print("Bye!")
if __name__ == '__main__':
main()