I am doing my python assignment, but there is an error when I wanted to test the case above.
Here is my code:
def evalTerm(env, t):
if type(t) == Node:
for label in t:
children = t[label]
if label == 'Number':
t = children[0]
return t
elif label == 'Add':
t1 = children[0]
v1 = evalTerm(env, t1)
t2 = children[1]
v2 = evalTerm(env, t2)
return v1 + v2
elif label == 'Multiply':
t1 = children[0]
v1 = evalTerm(env, t1)
t2 = children[1]
v2 = evalTerm(env, t2)
return v1 * v2
elif label == 'Variable':
x = children[0]
if x in env:
return env[x]
else:
print(x + " is unbound")
exit()
elif label == 'Int':
f = children[0]
v = evalTerm[env, f]
if v == 'True':
return 1
elif v == 'False':
return 0
elif label == 'Parens':
x = children[0]
v = evalTerm(env, x)
return v
elif type(f) == Leaf:
if f == 'True':
return 'True'
if f == 'False':
return 'False'
When I test it by using:
evalTerm({}, {'Int': ['True']})
it gives an error:
'function' object is not subscriptable
How could I fix it?
Node = dict,Leaf = strthing in your question!