recursive long test1 in C00

This commit is contained in:
HOME-VM-TOSCHOOL 2023-11-16 01:29:09 +01:00
parent 521708dae4
commit 3f3c3da759
2 changed files with 11 additions and 13 deletions

View File

@ -1,6 +1,7 @@
{ {
"cSpell.words": [ "cSpell.words": [
"csvfile", "csvfile",
"setrecursionlimit",
"testnfa" "testnfa"
], ],
"[plaintext]": { "[plaintext]": {

View File

@ -5,7 +5,9 @@ from tokenize import Comment
from numpy import append from numpy import append
DEBUG = False DEBUG = False
alfabet = "a" alfabet = "xyz"
sys.setrecursionlimit(4100)
def print_debug(*args, **kwargs): def print_debug(*args, **kwargs):
@ -15,9 +17,9 @@ def print_debug(*args, **kwargs):
if len(sys.argv) == 1: if len(sys.argv) == 1:
print("Default arguments parsed\n") print("Default arguments parsed\n")
sys.argv.append("test1.arg") sys.argv.append("long.arg")
sys.argv.append("test1.in") sys.argv.append("long.in")
sys.argv.append("test1.exp") sys.argv.append("long.exp")
with open(sys.argv[1], mode="r", newline="", encoding="utf8") as csvfile: with open(sys.argv[1], mode="r", newline="", encoding="utf8") as csvfile:
filereader = csv.reader(csvfile, delimiter="\t", quotechar="|") filereader = csv.reader(csvfile, delimiter="\t", quotechar="|")
@ -49,9 +51,10 @@ with open(sys.argv[1], mode="r", newline="", encoding="utf8") as csvfile:
print_debug( print_debug(
f"WARNING - duplicate letter: key = ({item[0]} | {letter}) | line: {num + 1}" f"WARNING - duplicate letter: key = ({item[0]} | {letter}) | line: {num + 1}"
) )
fsa_description_map[tuple].append(item[1])
tuple = (item[0], letter) tuple = (item[0], letter)
# fsa_description_map[tuple].append(item[1]) # fsa_description_map[tuple].append(item[1])
fsa_description_map[tuple] = item[1] fsa_description_map[tuple] = [item[1]]
if is_error: if is_error:
exit(-1) exit(-1)
@ -108,7 +111,7 @@ def traverse_states(current_state: str, word: str) -> str:
ending_state = traverse_states(next_state, word[1:]) ending_state = traverse_states(next_state, word[1:])
if is_correct(ending_state): if is_correct(ending_state):
return ending_state # found a correct state return ending_state # found a correct state
return "-1" # no correct state found return "-2" # no correct state found
else: else:
return "-1" # unspecified next state return "-1" # unspecified next state
return current_state # end of the word return current_state # end of the word
@ -118,13 +121,7 @@ is_difference = []
for i, word in enumerate(test_in): for i, word in enumerate(test_in):
current_state = "0" current_state = "0"
if len(word) != 0: if len(word) != 0:
for letter in word: current_state = traverse_states(current_state, word)
if (current_state, letter) in fsa_description_map:
current_state = fsa_description_map[(current_state, letter)]
else:
current_state = "-1"
break
# ending_state = traverse_states(current_state, word)
print(str(i + 1) + "\t", end="") print(str(i + 1) + "\t", end="")
if current_state in accepting_state: if current_state in accepting_state: