From 753d0ea1db207cb5a9f51145df5afc7723e46925 Mon Sep 17 00:00:00 2001 From: HOME-VM-TOSCHOOL Date: Tue, 31 Oct 2023 20:49:46 +0100 Subject: [PATCH] zad B02 --- TaskB02/fsa_description.arg | 13 ++++++++++ TaskB02/run.py | 47 +++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 TaskB02/fsa_description.arg create mode 100644 TaskB02/run.py diff --git a/TaskB02/fsa_description.arg b/TaskB02/fsa_description.arg new file mode 100644 index 0000000..b191fda --- /dev/null +++ b/TaskB02/fsa_description.arg @@ -0,0 +1,13 @@ +0 1 1 +0 5 0 +1 5 1 +1 2 0 +2 3 1 +2 4 0 +3 3 1 +3 2 0 +4 3 1 +4 4 0 +5 5 1 +5 5 0 +2 \ No newline at end of file diff --git a/TaskB02/run.py b/TaskB02/run.py new file mode 100644 index 0000000..d5d5863 --- /dev/null +++ b/TaskB02/run.py @@ -0,0 +1,47 @@ +import sys +import csv + +from numpy import append + +if len(sys.argv) == 1: + print("Default arguments parsed\n") + sys.argv.append("fsa_description.arg") + sys.argv.append("test.in") + sys.argv.append("test.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="|") + test_in = list(filereader) + +with open(sys.argv[3], "r", newline="", encoding="utf8") as csvfile: + filereader = csv.reader(csvfile, delimiter="\t", quotechar="|") + test_out = list(filereader) + + +for i, word in enumerate(test_in): + current_state = 0 + if len(word) != 0: + for letter in word[0]: + current_state = fsa_description_map[(current_state, letter)] + + print(str(i + 1) + "\t", end="") + if current_state == accepting_state: + print("YES\t", end="") + if "YES" != test_out[i][0]: + print(" ERROR", end="") + else: + print("NO", end="") + if "NO" != test_out[i][0]: + print(" ERROR", end="") + print()