예제 #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)
예제 #2
0
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()
예제 #3
0
from automata import *
from nfa2dfa import *
from regex2nfa import *
from dfa2mindfa import *


		##########
		# Part 1 #
		##########
regex2nfa_obj=regex2nfa("g")
regex2nfa_obj.convert_to_nfa()

aut_nfa = automata('nfa')
aut_nfa.add_char("x")
aut_nfa.add_char("y")
aut_nfa.add_state()
aut_nfa.add_state()
aut_nfa.add_state()
aut_nfa.add_state()
aut_nfa.add_transition(1,'x',3)
aut_nfa.add_transition(1,'#',2)
aut_nfa.add_transition(3,'#',4)
aut_nfa.add_transition(4,'y',1)
####
aut_nfa.add_transition(0,'x',1)
aut_nfa.add_transition(0,'y',2)
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)