djfz-2019/TaskB01/run

47 lines
994 B
Plaintext
Raw Normal View History

2019-11-24 21:22:07 +01:00
#!/usr/bin/python3
import sys
import re
class automate:
self.storage = []
self.accepting_states = []
self.state = '0'
def add_node(self, line):
node = line.split(' ')
if len(node) == 3:
self.storage.append([[node[0], node[2]], node[1]])
elif len(node) == 1:
self.accepting_states.append()
def test_string(self, text):
for i in text:
self.state = self.get_node_transition([self.state, i])
if self.state == None:
return 'FALSE'
if self.state in self.accepting_states:
return 'TRUE'
else:
return 'FALSE'
def get_node_transition(self, query):
for i in self.storage:
if i[0] == query:
return i[1]
return None
auto = automate()
for line in sys.stdin:
auto.add_node(line)
f = open(sys.argv[1], 'r')
for line in f:
print(auto.test_string(line))