Added a function to the Tokenizer to return a string of the tokens.
This commit is contained in:
@@ -168,8 +168,13 @@ for r in res:
|
|||||||
#if result <= tol and result >= int(exp.wrong_response - exp.wrong_response * tolerance):
|
#if result <= tol and result >= int(exp.wrong_response - exp.wrong_response * tolerance):
|
||||||
|
|
||||||
|
|
||||||
for k in answers:
|
#for k in answers:
|
||||||
print("Result: %s for expression: " %(format(k, ".8f")))
|
# print("Result: %s for expression: " %(format(k, ".8f")))
|
||||||
tokenizer.print_token_list(answers[k])
|
# 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]))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -114,3 +114,10 @@ def print_token_list(tokens):
|
|||||||
for tk in tokens:
|
for tk in tokens:
|
||||||
print("%s " %(tk.value), end = "")#, token.TokenType.get_token_type_name(tk.type)), end = "")
|
print("%s " %(tk.value), end = "")#, token.TokenType.get_token_type_name(tk.type)), end = "")
|
||||||
print()
|
print()
|
||||||
|
|
||||||
|
def stringify_token_list(tokens):
|
||||||
|
text = ''
|
||||||
|
for tk in tokens:
|
||||||
|
text += str(tk.value)
|
||||||
|
text += '\n'
|
||||||
|
return text
|
||||||
|
|||||||
Reference in New Issue
Block a user