sdht0 / automata-from-regex Goto Github PK
View Code? Open in Web Editor NEWA python program to build nfa, dfa and minimised DFA from given regular expression. Uses Tkinter for GUI and GraphViz for graphs.
A python program to build nfa, dfa and minimised DFA from given regular expression. Uses Tkinter for GUI and GraphViz for graphs.
Encountering some trouble while comparing equal status:
It's not equal while a status is in ending states , and another one is not in ending stats:
Fixed with coming codes:
def minimise(self):
states = list(self.dfa.states)
n = len(states)
unchecked = dict()
count = 1
distinguished = []
equivalent = dict(zip(range(len(states)), [{s} for s in states]))
pos = dict(zip(states, range(len(states))))
for i in range(n - 1):
for j in range(i + 1, n):
if not ([states[i], states[j]] in distinguished or [states[j], states[i]] in distinguished):
if (states[i] in self.dfa.finalstates and states[j] not in self.dfa.finalstates) or (states[i] not in self.dfa.finalstates and states[j] in self.dfa.finalstates):
distinguished.append([states[i], states[j]])
continue
eq = 1
toappend = []
for char in self.dfa.language:
s1 = self.dfa.gettransitions(states[i], char)
print "debug trans "
print s1
s2 = self.dfa.gettransitions(states[j], char)
if len(s1) != len(s2):
eq = 0
break
if len(s1) > 1:
raise BaseException("Multiple transitions detected in DFA")
elif len(s1) == 0:
continue
s1 = s1.pop()
s2 = s2.pop()
if s1 != s2:
if [s1, s2] in distinguished or [s2, s1] in distinguished:
eq = 0
break
else:
toappend.append([s1, s2, char])
eq = -1
if eq == 0:
distinguished.append([states[i], states[j]])
elif eq == -1:
s = [states[i], states[j]]
s.extend(toappend)
unchecked[count] = s
count += 1
else:
p1 = pos[states[i]]
p2 = pos[states[j]]
if p1 != p2:
st = equivalent.pop(p2)
for s in st:
pos[s] = p1
equivalent[p1] = equivalent[p1].union(st)
newFound = True
while newFound and len(unchecked) > 0:
newFound = False
toremove = set()
for p, pair in unchecked.items():
for tr in pair[2:]:
if [tr[0], tr[1]] in distinguished or [tr[1], tr[0]] in distinguished:
unchecked.pop(p)
distinguished.append([pair[0], pair[1]])
newFound = True
break
for pair in unchecked.values():
p1 = pos[pair[0]]
p2 = pos[pair[1]]
if p1 != p2:
st = equivalent.pop(p2)
for s in st:
pos[s] = p1
equivalent[p1] = equivalent[p1].union(st)
if len(equivalent) == len(states):
self.minDFA = self.dfa
else:
self.minDFA = self.dfa.newBuildFromEquivalentStates(equivalent, pos)
python cli.py "01(0+101)*" the result is not correct
Anything I misunderstood?
can you check the results here ..
my input was : x(x+y)*+z
https://image.ibb.co/dx6fSa/Screenshot_from_2017_05_24_20_42_39.png
1 -> 3 on "z"
i can't understand why this is there .. maybe i miss something ...
the results follow the yellow draw on the youtube video example .. except that one for me
hi, when i try to create new DFAfromNFA with arguement of constructor- object created with NFAfromRegex i get "AttributeError: 'NFAfromRegex' object has no attribute 'getEClose'"
because this attribute is in Automata class. How can i solve this problem.
Thank you!
as we know , a complete regular expression should hava '|'
http://stackoverflow.com/questions/247167/exclusive-or-in-regular-expression
for example, how to do this one:
/^(foo|bar){1}$/
how to use sign chars ( + - " ' ) in regular expression entry ?
Ex:
"[a-zA-Z0-9]"
how to enter this ????
at first comes double qoutation the chars from a to z or A to Z or 0 - 9 and at last double qoutation again
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.