Exemple #1
0
 def createAutomata(self, inp):
     print "Regex: ", inp
     nfaObj = regex2nfa(inp)
     self.nfa = nfaObj.getNFA()
     self.dfaObj = nfa2dfa(self.nfa)
     self.dfa = self.dfaObj.getDFA()
     self.minDFA = self.dfaObj.getMinimisedDFA()
     if self.dotFound:
         drawGraph(self.dfa, "dfa")
         drawGraph(self.nfa, "nfa")
         drawGraph(self.minDFA, "mdfa")
         dfafile = "graphdfa.png"
         nfafile = "graphnfa.png"
         mindfafile = "graphmdfa.png"
         self.nfaimagefile = Image.open(nfafile)
         self.dfaimagefile = Image.open(dfafile)
         self.mindfaimagefile = Image.open(mindfafile)
         self.nfaimg = ImageTk.PhotoImage(self.nfaimagefile)
         self.dfaimg = ImageTk.PhotoImage(self.dfaimagefile)
         self.mindfaimg = ImageTk.PhotoImage(self.mindfaimagefile)
def main():
	regex = "(01*1)*1"
	if len(sys.argv)>1:
		regex = sys.argv[1]
	print "Regular Expression: ", regex
	nfaObj = regex2nfa(regex)
	nfa = nfaObj.getNFA()
	dfaObj = nfa2dfa(nfa)
	dfa = dfaObj.getDFA()
	minDFA = dfaObj.getMinimisedDFA()
	print "\nNFA: "
	nfaObj.displayNFA()
	print "\nDFA: "
	dfaObj.displayDFA()
	print "\nMinimised DFA: "
	dfaObj.displayMinimisedDFA()
	if isInstalled("dot"):        
		drawGraph(dfa, "dfa")
		drawGraph(nfa, "nfa")
		drawGraph(minDFA, "mdfa")
		print "\nGraphs have been created in the code directory"
		print minDFA.getDotFile()
aut_nfa.add_transition(1,'x',0)
aut_nfa.add_transition(1,'y',3)
aut_nfa.add_transition(2,'x',0)
aut_nfa.add_transition(2,'y',3)
aut_nfa.add_transition(3,'x',3)
aut_nfa.add_transition(3,'y',3)
####
aut_nfa.add_final_state(3)
aut_nfa.display_automata()
automata.display_nx_automata(aut_nfa, "nfa", "NFA")

		##########
		# Part 2 #
		##########

nfa2dfa_obj = nfa2dfa('nfa2dfa')
nfa2dfa_obj.set_nfa(aut_nfa)
nfa2dfa_obj.set_charset(aut_nfa.char_set)
nfa2dfa_obj.build_dfa()
aut_dfa = nfa2dfa_obj.dfa
nfa2dfa_obj.display_automata()
automata.display_nx_automata(aut_dfa, "dfa", "DFA")

		##########
		# Part 3 #
		##########

nfa2mindfa_obj = dfa2mindfa(aut_dfa)
nfa2mindfa_obj.minimiseIt()

aut_min_dfa = automata("min_dfa")