print("One of your values is improperly formatted.")
print("One of your values is improperly formatted.")
case5:
case5:
print("Uninitialized variable.")
print("Uninitialized variable.")
case6:
print("Invalid expression.")
return
defcheck_errors(expr):
defcheck_errors(expr):
# Check for errors before parsing the expression
expr_small=expr.replace("","")# Remove spaces from the string, to make it easier to parse
expr_small=expr.replace("","")# Remove spaces from the string, to make it easier to parse
# Check if number of opening parantheses is equal to number of closing parantheses
# Check if number of opening parantheses is equal to number of closing parantheses
@ -56,12 +100,18 @@ def check_errors(expr):
# Check for errors after parsing the expression
expr=parse(expr)
expr=parse(expr)
ifexpr[0].isalpha()and(len(expr)==1orexpr[1]!='='):# If you just have an expression with a letter eg. 'x', or you use a variable without an assignment (e.g. 'x 5')
return6
forvalinexpr:
forvalinexpr:
ifval.count('.')>1:# A value can have at most 1 period
ifval.count('.')>1:# A value can have at most 1 period
return4
return4
ifval.isalpha()andnotvalinvariablesandval!=expr[0]:# If the token is a string, and isn't in the dictionary, and isn't the variable at index 0 (e.g. 'x' in 'x = 4')
ifval.isalpha()andnotvalinvariablesandval!=expr[0]:# If the token is a string, and isn't in the dictionary, and isn't the variable at index 0 (e.g. 'x' in 'x = 4')