Refactored some code to try and make it more inline with best pratices. Renamed parser as it conflicted with a standard Python library.

This commit is contained in:
2020-07-26 00:25:09 -05:00
parent a1c260d0fa
commit fac2b2d625
5 changed files with 58 additions and 60 deletions
+9 -9
View File
@@ -1,12 +1,12 @@
import ptoken as token
import tokenizer
import expression
import calc_engine
from base_unit import Token, TokenType
from calc_engine import calculate_results
from expression import Expression, Variable
from tokenizer import get_tokens_from_expression_string, stringify_token_list
import factors
import jsonpickle
import itertools
import copy
import parser
from ast_gen import Parser
base_list = [1, 2, 4, 6, 12]
tolerance = .05
@@ -151,8 +151,8 @@ json = jsonpickle.json.loads(open(fileLocation).read())
with open("expression.json", "r") as f:
#j = jsonpickle.json.load(f)
exp = jsonpickle.decode(f.read())
tokens = tokenizer.get_tokens_from_expression_string(exp.expression)
tree = parser.Parser(tokens)
tokens = get_tokens_from_expression_string(exp.expression)
tree = Parser(tokens)
#results = calc_engine.calculate_results(tokens.copy())
#print(results)
@@ -187,7 +187,7 @@ for r in res:
count +=1
t = tree.update_variables(vs)#tokenizer.replace_variables(tokens, list(r))
#tokenizer.print_token_list(t)
result = calc_engine.calculate_results(tree.ast)
result = calculate_results(tree.ast)
if result <= int(exp.wrong_response * (1 + tolerance)) and result >= int(exp.wrong_response * (1 - tolerance)):
if not result in answers:
answers[result] = tree.get_tokens()
@@ -201,6 +201,6 @@ with open("results.txt", "w") as f:
print("Answers Found: %d" %(len(answers)))
for k in answers:
f.write("Result: %s for expression: " %(format(k, ".6f")))
f.write(tokenizer.stringify_token_list(answers[k]))
f.write(stringify_token_list(answers[k]))