jfz-2023-s473555/TaskB00/run.py

48 lines
1.5 KiB
Python
Raw Permalink Normal View History

2023-10-31 20:00:56 +01:00
import sys
import csv
from numpy import append
if len(sys.argv) == 1:
print("Default arguments parsed")
sys.argv.append("fsa_description.arg")
sys.argv.append("test1.in")
sys.argv.append("test1.exp")
with open(sys.argv[1], "r", newline="", encoding="utf8") as csvfile:
filereader = csv.reader(csvfile, delimiter="\t", quotechar="|")
fsa_description = list(filereader)
accepting_state = int(fsa_description[-1][0])
fsa_description = fsa_description[:-1]
fsa_description_map = {}
for item in fsa_description:
tuple = (int(item[0]), item[2])
fsa_description_map[tuple] = int(item[1])
with open(sys.argv[2], "r", newline="", encoding="utf8") as csvfile:
filereader = csv.reader(csvfile, delimiter="\t", quotechar="|")
2023-10-31 20:47:05 +01:00
test_in = list(filereader)
2023-10-31 20:00:56 +01:00
with open(sys.argv[3], "r", newline="", encoding="utf8") as csvfile:
filereader = csv.reader(csvfile, delimiter="\t", quotechar="|")
2023-10-31 20:47:05 +01:00
test_out = list(filereader)
2023-10-31 20:00:56 +01:00
2023-10-31 20:47:05 +01:00
for i, word in enumerate(test_in):
2023-10-31 20:00:56 +01:00
current_state = 0
if len(word) != 0:
for letter in word[0]:
current_state = fsa_description_map[(current_state, letter)]
2023-10-31 20:47:05 +01:00
print(str(i + 1) + "\t", end="")
2023-10-31 20:00:56 +01:00
if current_state == accepting_state:
2023-10-31 20:47:05 +01:00
print("YES\t", end="")
if "YES" != test_out[i][0]:
print(" ERROR", end="")
2023-10-31 20:00:56 +01:00
else:
2023-10-31 20:47:05 +01:00
print("NO", end="")
if "NO" != test_out[i][0]:
print(" ERROR", end="")
print()