Added a function to the Tokenizer to return a string of the tokens.

This commit is contained in:
2020-04-25 22:31:11 -05:00
parent 00bd817a99
commit 350021a42b
2 changed files with 15 additions and 3 deletions
+8 -3
View File
@@ -168,8 +168,13 @@ for r in res:
#if result <= tol and result >= int(exp.wrong_response - exp.wrong_response * tolerance):
for k in answers:
print("Result: %s for expression: " %(format(k, ".8f")))
tokenizer.print_token_list(answers[k])
#for k in answers:
# print("Result: %s for expression: " %(format(k, ".8f")))
# tokenizer.print_token_list(answers[k])
with open("results.txt", "w") as f:
for k in answers:
f.write("Result: %s for expression: " %(format(k, ".6f")))
f.write(tokenizer.stringify_token_list(answers[k]))
+7
View File
@@ -114,3 +114,10 @@ def print_token_list(tokens):
for tk in tokens:
print("%s " %(tk.value), end = "")#, token.TokenType.get_token_type_name(tk.type)), end = "")
print()
def stringify_token_list(tokens):
text = ''
for tk in tokens:
text += str(tk.value)
text += '\n'
return text