Show your support by donating any amount. (Note: We are still technically a for-profit company, so your contribution is not tax-deductible.) PayPal Acct: Feedback:
Donate to VoyForums (PayPal):
[ Login ] [ Contact Forum Admin ] [ Main index ] [ Post a new message ] [ Search | Check update time ] |
from Parser import ori_parse
p = "program.txt"
inputfile = ""
try:
inputfile = open(p).read().replace(chr(13) + chr(10),
chr(10)).replace(chr(13), chr(10)).split(chr(10))
except: print("couldn't open \"" + p + "\", exiting.") ; print("") ; quit()
print(inputfile)
for line in inputfile:
if len(line) > 0 :
token_list = ori_parse(line)
variables={}
def add(a,b):
sum= a+b
return sum
def div(a,b):
result=0
try:
if a > b:
result = a / b
elif b > a:
result = b / a
else:
result = 1
except ZeroDivisionError:
print("Please do not divide by zero")
except TypeError:
print("Make sure you have entered numbers")
return result
def multiply(a,b):
result = a*b
return result
def create_vari_dict():
if token_list[0] != "add" and "div" and "multiply" and token_list[1] == "=":
variables[token_list[0]] = token_list[2:]
return variables[token_list[0]]
def analyze_tokens():
analyze_list = create_vari_dict()
print (analyze_list)
if analyze_list[0] == "div" :
a = div(float(analyze_list[1]), float(analyze_list[2]))
if analyze_list[0] == "add" :
a = add(float(analyze_list[1]), float(analyze_list[2]))
if analyze_list[0] == "multiply":
a = multiply(float(analyze_list[1]), float(analyze_list[2]))
return a
variables[token_list[0]] = analyze_tokens()
print (variables[token_list[0]])