Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
Fixed boolean string concatenation
Browse files Browse the repository at this point in the history
  • Loading branch information
GabDug committed Jan 11, 2018
1 parent ba9257f commit bed1fac
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions src/eval_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@ def _eval_global(expression: list, var_dic: dict):
else:
return "false", "boolean"
elif main_operator[0] == 'or':
print("left0 " + str(left[0]))
print("rught0 " + str(right[0]))

if left[0] == "true" or right[0] == 'true':
return "true", "boolean"
else:
Expand All @@ -140,19 +137,9 @@ def _eval_global(expression: list, var_dic: dict):
raise Exception(f"type mismatch ({left[1]} {main_operator[0]} {right[1]})")

# String and int only
elif main_operator[0] in ["+", "<", ">", "<=", ">="]:
elif main_operator[0] in ["<", ">", "<=", ">="]:
if (left[1] == right[1]) and (left[1] == "integer" or left[1] == "string"):
if main_operator[0] == '+':
if left[1] != right[1]:
if left[1] == "string" and right[1] == "integer":
return left[0] + str(right[0]), "string"
elif left[1] == "integer" and right[1] == "string":
return str(left) + right, "string"
else:
raise Exception(f"type mismatch ({left[1]} {main_operator[0]} {right[1]})")
else:
return left[0] + right[0], "integer"
elif main_operator[0] == '<':
if main_operator[0] == '<':
if left[0] < right[0]:
return "true", "boolean"
else:
Expand All @@ -175,6 +162,17 @@ def _eval_global(expression: list, var_dic: dict):
else:
raise Exception(f"type mismatch ({left[1]} {main_operator[0]} {right[1]})")

elif main_operator[0] == '+':
if left[1] != right[1]:
if left[1] == "string" and (right[1] == "integer" or right[1] == "boolean"):
return left[0] + str(right[0]), "string"
elif (left[1] == "integer" or left[1] == "boolean") and right[1] == "string":
return str(left) + right, "string"
else:
raise Exception(f"type mismatch ({left[1]} {main_operator[0]} {right[1]})")
else:
return left[0] + right[0], "integer"

# Working with all types
elif main_operator[0] in ["==", "!="]:
if main_operator[0] == '==':
Expand Down Expand Up @@ -237,6 +235,7 @@ def find_operator(expression):
logger.addHandler(ch)
logger.info("Starting logger from module.")

dict_var = {}
print(ext_eval_global("a = 10", dict_var))
print(ext_eval_global("a + 1", dict_var))
# dict_var = {}
# print(ext_eval_global("a = 10", dict_var))
# print(ext_eval_global("a + 1", dict_var))
print(ext_eval_global("'e'+1"))

0 comments on commit bed1fac

Please sign in to comment.