def exec_func_body(func_body,passed): """Executes the body of the function""" if ops.null(func_body):return str(evaluate(ops.rest(passed),[])) if ops.first(func_body).isalpha and ops.first(func_body) in local_dict: passed=ops.append(passed,[str(local_dict[ops.first(func_body)])]) local_dict[ops.first(func_body)]=int(local_dict[ops.first(func_body)])-1 return exec_func_body(ops.rest(func_body),passed) else:return exec_func_body(ops.rest(func_body),ops.append(passed,[ops.first(func_body)]))
def evaluate(lists,final): """Performs arithmetic and logical operations""" if ops.null(lists):return final[0] elif ops.first(lists)=='(':return evaluate(ops.rest(lists),final) elif ops.first(lists).isdigit():return evaluate(ops.rest(lists),ops.append(final,[int(ops.first(lists))])) elif ops.first(lists)==')': op=opdet(final) if op=='+':f=add elif op=='*':f=mul elif op=='/':f=div elif op=='-':f=sub elif op=='%':f=mod elif op=='>':f=gt elif op=='and':f=and_ elif op=='<':f=lt elif op=='=':f=eq result=ops.last(final) final=ops.rest1(final) while type(ops.last(final))==int: result=int(f(ops.last(final),result)) final=ops.rest1(final) final=ops.rest1(final) return evaluate(ops.rest(lists),ops.append(final,[result])) else:return evaluate(ops.rest(lists),ops.append(final,[ops.first(lists)]))
def evaluate_funcbody(dummy,lists): """Evaluates the function body""" if ops.null(dummy):return lists if ops.first(dummy).isalpha():return evaluate_funcbody(ops.rest(dummy),ops.append(lists,[local_dict[ops.first(dummy)]])) else:return evaluate_funcbody(ops.rest(dummy),ops.append(lists,[ops.first(dummy)]))