コード例 #1
0
 def test_Pushdown_Automata_BadConstruction_3(self):
     try:
         M = machine.PushdownAutomata([['q_0', '1']], 'q_0', '0', ['q_0'])
         self.assertTrue(False)
         del M
     except:
         self.assertTrue(True)
コード例 #2
0
ファイル: ui.py プロジェクト: CodeCommandante/ThePeoplesRepo
def runPDAProgram(params: list):
    print('Enter strings to check if they are in the language on the machine, L(M).')
    print('When you are finished, enter \'quit\'')
    M = machine.PushdownAutomata(params[0],params[1],params[2],params[3])
    userIn = input()
    while not userIn == 'quit':
        if M.run(userIn):
            print(userIn,'is in the language!')
        else:
            print(userIn,'is not in the language!')
        userIn = input()
    return
コード例 #3
0
 def test_Pushdown_Automata_run_1(self):
     M = machine.PushdownAutomata(
         [['q0', 'a', '0', 'q1', '10'], ['q1', 'a', '1', 'q1', '11'],
          ['q1', 'b', '1', 'q2', ''], ['q2', 'b', '1', 'q2', ''],
          ['q2', '', '0', 'q0', '']], 'q0', '0', ['q0'])
     self.assertTrue(M.run(''))
     self.assertTrue(M.run('ab'))
     self.assertTrue(M.run('aabb'))
     self.assertTrue(M.run('aaabbb'))
     self.assertTrue(M.run('aaaaabbbbb'))
     self.assertFalse(M.run('aabbab'))
     self.assertFalse(M.run('aaabbbab'))
     del M