|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
def parse(expr):
|
|
|
|
|
|
|
|
|
|
opers = ['+', '-', '*', '/']
|
|
|
|
|
opers = ['+', '-', '*', '/', '=']
|
|
|
|
|
|
|
|
|
|
num_par = 0
|
|
|
|
|
tokenized = []
|
|
|
|
@ -9,19 +9,19 @@ def parse(expr):
|
|
|
|
|
while index < len(expr):
|
|
|
|
|
if expr[index] in opers:
|
|
|
|
|
tokenized.append(expr[index])
|
|
|
|
|
index += 1
|
|
|
|
|
|
|
|
|
|
elif expr[index].isdigit() or expr[index] == '.':
|
|
|
|
|
while (index < len(expr)) and (expr[index].isdigit() or expr[index] == '.'):
|
|
|
|
|
temp_string += expr[index]
|
|
|
|
|
index += 1
|
|
|
|
|
tokenized.append(temp_string)
|
|
|
|
|
temp_string = ""
|
|
|
|
|
|
|
|
|
|
elif expr[index] == '(':
|
|
|
|
|
num_par = 1
|
|
|
|
|
temp_string += expr[index]
|
|
|
|
|
index += 1
|
|
|
|
|
while num_par != 0 and index < len(expr):
|
|
|
|
|
while index < len(expr) and num_par != 0:
|
|
|
|
|
temp_string += expr[index]
|
|
|
|
|
if expr[index] == '(':
|
|
|
|
|
num_par += 1
|
|
|
|
@ -30,9 +30,18 @@ def parse(expr):
|
|
|
|
|
index += 1
|
|
|
|
|
|
|
|
|
|
tokenized.append(temp_string)
|
|
|
|
|
temp_string = ""
|
|
|
|
|
|
|
|
|
|
elif expr[index].isalpha(): # If you encounter a variable
|
|
|
|
|
temp_string += expr[index]
|
|
|
|
|
index += 1
|
|
|
|
|
while index < len(expr) and expr[index].isalpha():
|
|
|
|
|
temp_string += expr[index]
|
|
|
|
|
index += 1
|
|
|
|
|
tokenized.append(temp_string)
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
index += 1
|
|
|
|
|
|
|
|
|
|
temp_string = ""
|
|
|
|
|
|
|
|
|
|
return tokenized
|
|
|
|
|