def create_dfa(self): alphabet = self.dfa_alphabet.text().split(',') start = self.dfa_start.text() finals = self.dfa_finals.text().split(',') transitions = {} for row in range(0, self.dfa_transitions.rowCount()): state = self.dfa_transitions.item(row, 0) char = self.dfa_transitions.item(row, 1) next_state = self.dfa_transitions.item(row, 2) if state is not None and char is not None and next_state is not None: state = state.text() char = char.text() next_state = next_state.text() transitions[(state, char)] = next_state if alphabet[0] != '' and start != '' and finals[ 0] != '' and transitions != {}: dfa = DFA(alphabet, transitions, start, finals) dfa_list.append(dfa) item = QStandardItem(dfa.get_tuple_string()) dfa_model_list.appendRow(item) self.dialog.accept()
('q0', 'a'): 'q0', ('q0', 'b'): 'q1', ('q1', 'a'): 'q2', ('q1', 'b'): 'q1', ('q2', 'a'): 'q0', ('q2', 'b'): 'q3', ('q3', 'a'): 'q2', ('q3', 'b'): 'q1', } start = 'q0' finals = ['q3'] dfa = DFA(alphabet, transitions, start, finals) dfa_list.append(dfa) dfa_model_list.appendRow(QStandardItem(dfa.get_tuple_string())) # ----------------------------- # # Example 2 # # Simple DFA # # "Starts with 'ba'" # ----------------------------- # alphabet = ['a', 'b'] transitions = { ('q0', 'a'): '{}', ('q0', 'b'): 'q1', ('q1', 'a'): 'q2', ('q1', 'b'): '{}', ('q2', 'a'): 'q2', ('q2', 'b'): 'q2', ('{}', 'a'): '{}',