Parsing list of lists for Transition state for DFA in python -



Parsing list of lists for Transition state for DFA in python -

class dfa:

#q=list of strings, alphabet = list of single char strings, s = start #state, f = list of states(strings) q, delta = list of lists def __init__(self, q, alphabet, s, f, delta): self.states = q self.alphabet = alphabet self.starts = s self.finals = f self.delta = delta self.currentstate = self.starts homecoming def transition_to_nextstate(self,input_value): if ((self.currentstate + input_value) not in self.delta): self.currentstate = none homecoming self.currentstate self.currentstate = self.delta[self.currentstate] homecoming self.currentstate #go start state def isstartstate(self): self.currentstate = self.starts #print(self.starts) #check in final state def isacceptstate(self): if (self.currentstate in self.finals): print("accepted") homecoming true else: print("not accepted") homecoming false #return true if inputstr accepted , false if not def processinputstr(self,inputstr): self.isstartstate() letter in inputstr: print("input:",letter) self.currentstate = self.transition_to_nextstate(letter) print("current state:", self.currentstate) if (self.currentstate == none): homecoming self.isacceptstate() go on homecoming self.isacceptstate()

my transition_to_nextstate function not working.

the dfa beingness sent: q: ['q1','q2','q3'] alphabet: ['0','1'] s: 'q1' f: ['q2'] delta: [['q1','a','q1'],['q1','b','q2]]

i can't parse list find next state machine should transition to. ideas welcome!

i believe problem in line

if ((self.currentstate + input_value) not in self.delta)

the look self.currentstate + input_value gives concatenated string i.e. if input_value = '1' gives q11

while self.delta list of lists, can't match string list.

dfa

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -