Esempio n. 1
0
 def generate_begins_with(self):
     alphabet = self.dfa_alphabet.text().split(',')
     if alphabet[0] != '' and self.lineEdit.text() != '':
         dfa = DFA.dfa_begins_with(self.lineEdit.text(), alphabet)
         dfa_list.append(dfa)
         item = QStandardItem(dfa.get_tuple_string())
         dfa_model_list.appendRow(item)
         self.dialog.accept()
Esempio n. 2
0
 def generate_contains(self):
     alphabet = self.dfa_alphabet.text().split(',')
     input = self.lineEdit_3.text()
     if alphabet[0] != '' and input != '':
         dfa = DFA.dfa_contains(input, alphabet)
         dfa_list.append(dfa)
         item = QStandardItem(dfa.get_tuple_string())
         dfa_model_list.appendRow(item)
         self.dialog.accept()
Esempio n. 3
0
 def or_dfa(self):
     indexes = self.dfa_list.selectedIndexes()
     if len(indexes) == 2:
         dfa1 = dfa_list[dfa_model_list.itemFromIndex(indexes[0]).row()]
         dfa2 = dfa_list[dfa_model_list.itemFromIndex(indexes[1]).row()]
         dfa3 = dfa1 | dfa2
         dfa_list.append(dfa3)
         item = QStandardItem(dfa3.get_tuple_string())
         dfa_model_list.appendRow(item)
Esempio n. 4
0
    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()
Esempio n. 5
0
    def not_operation(self):
        new_dfa = self.DFA.not_operation()
        dfa_list.append(new_dfa)
        item = QStandardItem(new_dfa.get_tuple_string())

        dfa_model_list.appendRow(item)
Esempio n. 6
0
    def minimize_2(self):
        new_dfa = self.DFA.minimize_reverse()
        dfa_list.append(new_dfa)
        item = QStandardItem(new_dfa.get_tuple_string())

        dfa_model_list.appendRow(item)
Esempio n. 7
0
    transitions = {
        ('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',
Esempio n. 8
0
    def to_dfa(self):
        new_dfa = self.NDFA.to_dfa()
        dfa_list.append(new_dfa)
        item = QStandardItem(new_dfa.get_tuple_string())

        dfa_model_list.appendRow(item)