This commit is contained in:
HOME-VM-TOSCHOOL 2023-11-18 00:24:23 +01:00
parent 24d9d79d4c
commit 2f2fb0d770

View File

@ -8,7 +8,7 @@ DEBUG = False
alfabet = "abc"
EPS = "<eps>"
sys.setrecursionlimit(4100)
# sys.setrecursionlimit(4100)
def print_debug(*args, **kwargs):
@ -18,9 +18,9 @@ def print_debug(*args, **kwargs):
if len(sys.argv) == 1:
print("Default arguments parsed\n")
sys.argv.append("eps.arg")
sys.argv.append("eps.in")
sys.argv.append("eps.exp")
sys.argv.append("simple2.arg")
sys.argv.append("simple2.in")
sys.argv.append("simple2.exp")
with open(sys.argv[1], mode="r", newline="", encoding="utf8") as csvfile:
filereader = csv.reader(csvfile, delimiter="\t", quotechar="|")
@ -115,12 +115,14 @@ def is_correct(current_state: str) -> bool:
return False
def go_threw_states(current_state: str, word: str, letter: str) -> str:
def find_final_state(current_state: str, word: str, letter: str) -> str:
next_states = fsa_description_map[(current_state, letter)]
for next_state in next_states:
ending_state = traverse_states(next_state, word)
if is_correct(ending_state):
return ending_state # found a correct state
if letter != EPS:
word = word[1:]
current_state = traverse_states(next_state, word)
if is_correct(current_state):
return current_state # found a correct state
return current_state
@ -144,17 +146,26 @@ def traverse_states(current_state: str, word: str) -> str:
ending_state = traverse_states(next_state, word[1:])
if is_correct(ending_state):
return ending_state # found a correct state
return "-2" # no correct state found
return "-2" # no correct state found
return "-3" # fatal error
is_difference = []
for i, word in enumerate(test_in):
if i == 5:
print(word)
current_state = "0"
if len(word) != 0:
current_state = traverse_states(current_state, word)
print(str(i + 1) + "\t", end="")
if current_state == "-3":
print("FATAL ERROR")
exit(-1)
if current_state in accepting_state:
print("YES\t", end="")
if "YES" != test_out[i] and "TRUE" != test_out[i]: