diff --git a/TaskB00/run.py b/TaskB00/run.py new file mode 100644 index 0000000..92f967e --- /dev/null +++ b/TaskB00/run.py @@ -0,0 +1,41 @@ +import sys +import csv + +from numpy import append + +print(sys.argv) +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="|") + test1_in = list(filereader) + +with open(sys.argv[3], "r", newline="", encoding="utf8") as csvfile: + filereader = csv.reader(csvfile, delimiter="\t", quotechar="|") + test1_out = list(filereader) + + +for word in test1_in: + current_state = 0 + if len(word) != 0: + for letter in word[0]: + current_state = fsa_description_map[(current_state, letter)] + if current_state == accepting_state: + print("YES") + else: + print("NO")