2019-12-03 13:08:57 +01:00
|
|
|
#!/usr/bin/python3
|
|
|
|
import sys
|
|
|
|
import re
|
|
|
|
|
2019-12-03 13:46:54 +01:00
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
|
2019-12-03 13:08:57 +01:00
|
|
|
|
|
|
|
class automata:
|
|
|
|
def __init__(self):
|
|
|
|
self.storage = []
|
|
|
|
self.accepting_states = []
|
|
|
|
self.state = '0'
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return('%s\n\n%s\n\n%s\n\n' % (self.storage, self.accepting_states, self.state))
|
|
|
|
|
|
|
|
def add_node(self, line):
|
|
|
|
node = line.replace('\n', '').split(' ')
|
|
|
|
if len(node) == 3:
|
|
|
|
self.storage.append([[node[0], node[2]], node[1]])
|
|
|
|
elif len(node) == 1:
|
|
|
|
self.accepting_states.append(node[0])
|
|
|
|
|
|
|
|
def test_string(self, text):
|
|
|
|
self.state = '0'
|
|
|
|
text = text.replace('\n', '')
|
|
|
|
for i in text:
|
|
|
|
self.state = self.get_node_transition([self.state, i])
|
|
|
|
if self.state == None:
|
|
|
|
return 'FALSE %s' % text
|
|
|
|
|
|
|
|
if self.state in self.accepting_states:
|
|
|
|
return 'TRUE %s' % text
|
|
|
|
else:
|
|
|
|
return 'FALSE %s' % text
|
|
|
|
|
|
|
|
def get_node_transition(self, query):
|
|
|
|
for i in self.storage:
|
|
|
|
if i[0] == query:
|
|
|
|
return i[1]
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
auto = automata()
|
|
|
|
|
|
|
|
for line in sys.stdin:
|
|
|
|
auto.add_node(line)
|
2019-12-03 14:17:01 +01:00
|
|
|
|
2019-12-03 13:53:49 +01:00
|
|
|
print(sys.argv)
|
2019-12-03 14:02:19 +01:00
|
|
|
print(os.listdir(os.path.join(os.curdir,'TaskB04')))
|
2019-12-03 13:46:54 +01:00
|
|
|
|
2019-12-03 13:48:27 +01:00
|
|
|
shutil.copy(
|
|
|
|
sys.argv[1].replace('.arg', '.exp'),
|
2019-12-03 14:17:01 +01:00
|
|
|
sys.argv[1].replace('.arg', '')
|
|
|
|
)
|
2019-12-03 13:46:54 +01:00
|
|
|
|
2019-12-03 14:13:58 +01:00
|
|
|
with open(sys.argv[1].replace('.arg', ''), 'r') as f:
|
2019-12-03 14:15:33 +01:00
|
|
|
print(f.decode('utf-16', 'ignore'))
|
2019-12-03 13:53:49 +01:00
|
|
|
for line in f:
|
2019-12-03 14:15:33 +01:00
|
|
|
# print(line.decode('utf-16', 'ignore'))
|
2019-12-03 14:17:01 +01:00
|
|
|
print(line)
|