-
Notifications
You must be signed in to change notification settings - Fork 4
/
DFA_Tester.py
28 lines (26 loc) · 866 Bytes
/
DFA_Tester.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 26 23:32:07 2018
@author: shashi
"""
import pickle
import sys
#from DFA_CLASS import DFA
if __name__ == "__main__":
with open(sys.argv[1],'rb') as inputfile: #input binary file command line argument 1
dfa = pickle.load(inputfile)
while True: #test as long as user wants
test = input('ENTER THE STRING\n')
state = dfa.Start
for a in test: #loop over all the symbols in the test string
state = dfa.Transition[state][a]
if state in dfa.Final: #check if last state is a final state
print('ACCEPTED')
else:
print('REJECTED')
choice = input('DO YOU WANT TO CONTINUE?(y/n): ') #ask user whether to continue or not
if choice == 'y':
continue
else:
break