def testGlobalVariables(self): scope = Scope() scope['i'] = 1 self.If = If('i') self.If.add_child(Script('j = i')) self.If.add_child(Script('i = 0')) self.If.afterscript = Script('assert i == 0') self.If.play(Scope(scope)) self.assertEquals(scope['i'], 0)
def test_get(self): defs = Scope(()).extend('g', 2).extend('f', 1).extend('x', 2).extend('x', 3) defs2 = defs.extend('x', 3) defs3 = defs.extend('f', 3) assert defs2.get('x') == 3 assert defs2.get('x') == 3 assert defs3.get('f') == 3 assert defs.get('x') == 3 defs_a = Scope(()) defs_b = defs_a.extend('x',0) assert(defs_b.get('x') == 0) assert(defs_b.get('x') == 0)
def play(self, scope=None): scope = Scope(scope) scope['_USER_INDEX_'] = self.user_index assert self.scripts == [] and self.children == [] global_reporter = scope.lookup('global_reporter') if global_reporter: reporter = global_reporter.get_reporter() scope['reporter'] = reporter else: reporter = None try: if self.iteration_factory: self.before(scope) for i in range(self.iteration_count): # TODO: put _ITERATION_INDEX_ in iteration scope instead of user scope scope['_ITERATION_INDEX_'] = i iteration = self.iteration_factory.create() iteration.player = self.player Player.execute_here(self, iteration, scope) self.after(scope) else: try: for i in range(self.iteration_count): scope['_ITERATION_INDEX_'] = i self.children.append(self.player) Player.play(self, scope) finally: self.children = [] except Errors.TerminateUser, e: log.exception('User terminated because of %s' % e)
def __init__(self): self.global_scope = Scope("GLOBAL") self.global_scope.build_global([ BuiltInTypeSymbol("STRING"), BuiltInTypeSymbol("INT"), BuiltInTypeSymbol("BOOL"), BuiltInTypeSymbol("NULL"), ])
def __init__(self, parent, scope: Scope = None): self.definitions = [] self.alterations = [] if scope is None: scope = Scope(parent.scope.scope_handler) self.scope = scope super().__init__(parent, scope)
def setUp(self): self.it_factory = IterationFactory() self.player = Script() self.scope = Scope() self.it_factory.beforescript.script = 'i = i + 1' self.user = User(self.player, 2, self.it_factory) self.user.beforescript.script = 'i = 0' self.user.afterscript.script = 'assert i == 2'
def add_module(self, module, buffer_size=2**11): if module not in self.modules: s = Scope(buffer_size) s.set_title(module.__class__.__name__) module.set_scope(s) self.modules.append(module) self.partition() return True return False
def enterWhile_stmt(self, ctx: TinyParser.While_stmtContext): self.blockCt += 1 self.scope = Scope("BLOCK %d" % self.blockCt, self.scope) self.symbolTables.append(self.scope) # Labels for control statements out = "out%d" % self.blockCt repeat = "block%d" % self.blockCt self.assembly_code.append(["label %s" % (repeat)]) self.labelStack.append(repeat) self.labelStack.append(out)
def playmain(self, basescope): for script in self.scripts: script.execute(basescope) for child in self.children: #child.play(Scope(basescope)) # this has memory leak, use below... new_scope = Scope(basescope) child.play(new_scope) # XXX: fix memory leak -- why I need this? new_scope.clear()
def program_f(self, args): scope = Scope('global') children_scopes = get_scopes_of_children(args) set_parent_of_children_scope(scope, children_scopes) set_children_of_parent_scope(scope, children_scopes) decls = [args[0]] for decl in args[1]['decls']: decls.append(decl) for decl in decls: scope.decls[decl['id']] = decl return {'scopes': [scope], 'decls': decls}
def testBreak(self): import Globals g = Globals.copy_globals() g['Break'] = Break scope = Scope() scope.variables = g self.loop.add_script(Script('if y == 3: raise Break()')) self.loop.afterscript = Script('assert x == 3; assert y == 3') self.loop.play(scope) self.assertEqual(scope.lookup('x'), 3) self.assertEqual(scope.lookup('y'), 3)
def __init__(self): self.scope = Scope("GLOBAL") self.symbolTables = [self.scope] self.blockCt = 0 self.currVarType = None self.writeVar = True self.writeFlag = False self.readFlag = False self.registers = [] self.register_counter = 0 self.labelStack = [] self.assembly_code = []
def enterElse_part(self, ctx: TinyParser.Else_partContext): self.scope = self.scope.parent #self.assembly_code.append() if len(ctx.getText()) > 0: parent = self.scope.parent self.blockCt += 1 self.scope = Scope("BLOCK %d" % self.blockCt, parent) self.symbolTables.append(self.scope) # Labels for control statements label = self.labelStack.pop() self.assembly_code.append(["jmp %s" % (self.labelStack[-1])]) self.assembly_code.append(["label %s" % (label)])
def enterIf_stmt(self, ctx: TinyParser.If_stmtContext): self.blockCt += 1 self.scope = Scope("BLOCK %d" % self.blockCt, self.scope) self.symbolTables.append(self.scope) # Labels for control statements if len(ctx.else_part().getText()) > 0: elselbl = "else%d" % self.blockCt outlbl = "out%d" % (self.blockCt) self.labelStack.append(outlbl) self.labelStack.append(elselbl) else: outlbl = "out%d" % (self.blockCt) self.labelStack.append(outlbl)
def __init__(self): self.trees = [] self.smallest_error = 9999999999999999999999999999999999999999999999999999 for i in range(0, 10): scope = Scope(ScopeHandler()) scope.add_var(Variable("arg1", Type.INT)) scope.add_var(Variable("arg2", Type.INT)) scope.add_var(Variable("boolvar", Type.BOOL)) # add initial variables to scope. tree = Block(None, scope) self.trees.append(tree) self.best_tree = None
def interface_decl_f(self, args): scope = Scope('interface') children_scopes = get_scopes_of_children(args) set_parent_of_children_scope(scope, children_scopes) set_children_of_parent_scope(scope, children_scopes) for prototype in args[1]['prototypes']: # TODO is it an error? (it seems it is) if scope.does_decl_id_exist(prototype['id']): raise SemErr(f'duplicate id for prototypes') scope.decls[prototype['id']] = prototype return { 'scopes': [scope], 'id': args[0]['value'], 'prototypes': args[1]['prototypes'] }
def class_decl_f(self, args): scope = Scope('class') children_scopes = get_scopes_of_children(args) set_parent_of_children_scope(scope, children_scopes) set_children_of_parent_scope(scope, children_scopes) fields = args[3]['fields'] for field in fields: decl = field['declaration'] decl['access_mode'] = field_access_mode if decl['decl_type'] == 'function': scope.decls[decl['id']] = decl decl['scope'].parent = scope decl['parent'] = args[0][ 'value'] # set parent of field function to class id for variable in decl['formals']: variable['fp_offset'] += 4 this_type = { 'scopes': [None], 'dim': 0, 'type': 'Object', 'class': args[0]['value'] } this_variable = { 'scopes': [None], 'fp_offset': 4, 'decl_type': 'variable', 'type': this_type } decl['formals'].insert(0, this_variable) elif decl['decl_type'] == 'variable': if scope.does_decl_id_exist(decl['id']): raise SemErr( f'duplicate id \'{decl["id"]}\' in class \'{args[0]["value"]}\'' ) scope.decls[decl['id']] = decl else: assert 1 == 2 # decl_type must be 'function' or 'variable', but it wasn't return { 'scopes': [scope], 'id': args[0]['value'], 'parent_class': args[1]['parent_class'], 'interfaces': args[2]['interfaces'], 'fields': args[3]['fields'] }
def play_in_single_thread(self, scope=None): g = self.global_factory.create() users = [] scope = Scope(scope) scope['_USER_COUNT_'] = self.user_count scope['_ITERATION_COUNT_'] = self.iteration_count scope['_PLAYER_'] = self.player if self.reporter: scope['global_reporter'] = self.reporter g.before(scope) for i in range(self.user_count): user = self.user_factory.create() user.player = self.player user.iteration_count = self.iteration_count user.iteration_factory = self.iteration_factory user.user_index = i users.append(user) user.play(scope) g.after(scope)
def stmt_block_f(self, args): scope = Scope('stmt_block') children_scopes = get_scopes_of_children(args) set_parent_of_children_scope(scope, children_scopes) set_children_of_parent_scope(scope, children_scopes) for variable_decl in args[0]['variable_decls']: if scope.does_decl_id_exist(variable_decl['id']): raise SemErr( f'duplicate id \'{variable_decl["id"]}\' declared many times as a variable' ) scope.decls[variable_decl['id']] = variable_decl variable_decl_count = len(args[0]['variable_decls']) # for stmt in args[1]['stmts']: # stmt['base_fp_offset'] = variable_decl_count * 4 return { 'scopes': [scope], 'variable_decls': args[0]['variable_decls'], 'stmts': args[1]['stmts'] }
def function_decl_f(self, args): scope = Scope('function') children_scopes = get_scopes_of_children(args) set_parent_of_children_scope(scope, children_scopes) set_children_of_parent_scope(scope, children_scopes) type_ = None id_ = None formal_variables = None stmt_block = None # if declared function returns type if len(args) == 4: type_ = args[0] id_ = args[1]['value'] formal_variables = args[2]['variables'] stmt_block = args[3] # if declared function returns void else: type_ = {'dim': 0, 'class': 'primitive', 'type': 'void'} id_ = args[0]['value'] formal_variables = args[1]['variables'] stmt_block = args[2] fp_offset = 4 for variable in formal_variables: variable['decl_type'] = 'variable' variable['fp_offset'] = fp_offset fp_offset += 4 if scope.does_decl_id_exist(variable['id']): raise SemErr( f'duplicate id \'{variable["id"]}\' in formals of function \'{args[1]["value"]}\'' ) scope.decls[variable['id']] = variable # stmt_block['base_fp_offset'] = -8 return { 'parent': 'GLOBAL', 'scopes': [scope], 'decl_type': 'function', 'type': type_, 'id': id_, 'formals': formal_variables, 'stmt_block': stmt_block }
def testBasic(self): scope = Scope() self.loop.play(scope) self.assertEqual(scope.lookup('x'), 10) self.assertEqual(scope.lookup('y'), 10)
def interpreter(input_path="exampleInput.c",debugging=False): ### STEP 0:declaration of (global) variables and preprocessing ### # Declarate variables global func_table,main_flow,current_scope,flow_stack,jump_to_new_func, ret_val,current_scope, memory, isError, debug program_end = False # Set debugging mode if debugging: debug=True # Make AST with open(input_path,'r') as outfile: result=cparse().parse( input=outfile.read(), lexer=clex(), tracking=True ) if debug: print(result) # in case of Syntax error -> end program if result==None: isError=True return # Make function table for i in range(len(result)): if result[i][0] == "func": ast = result[i] if len(ast[3]) == 1 and ast[3][0] == "void": func_table[ast[2]] = {'ret_type':ast[1], 'param_num': 0, 'param_list': [], 'flow_graph': None} else: func_table[ast[2]] = {'name':ast[2], 'ret_type':ast[1], 'param_num': len(ast[3]), 'param_list': ast[3], 'flow_graph':None} # make symbol table # sub 1: Convert scope list to Scope objects Scope_list=list(map(lambda x: Scope(x),scope_list_ext(input_path=input_path))) # sub 2: Find parent scope for each scopes # note: Scope_list[0] is always global scope(see scope_list_ext) for i in range(1,len(Scope_list)): for j in range(i): if (Scope_list[j].start_line <= Scope_list[i].start_line and Scope_list[j].end_line >= Scope_list[i].end_line): Scope_list[i].parent_scope = Scope_list[j] current_scope = Scope_list[0] scope_start_line = [] scope_end_line = [] for output in Scope_list: scope_start_line.append(output.start_line) scope_end_line.append(output.end_line) scope_start_line.reverse() scope_end_line.reverse() Scope_list.reverse() # Print Scope (for debugging) if debug: print("** SCOPE LIST **") for output in Scope_list: print(output) print(scope_start_line) print("** FUNCTION TABLE: dictionary of dictionaries **") print(func_table) # make flow graph for each functions for i in range(len(result)): if result[i][0] == 'func': ast = result[i] ast_scope = ast[5] statement_list = ast[4] func_flow = make_flow(ast, ast_scope, statement_list) if ast[2] in func_table.keys(): func_table[ast[2]]['flow_graph'] = func_flow if ast[2] == 'main': main_flow = func_flow # Make memory structure compute_static_allocation(result) memory = Memory() ### STEP 1:main loop ### syntax=re.compile(r"(\Anext( (0|[1-9]\d*))?\Z)|(\Aprint [A-Za-z_]\w*(\[\d*\])?\Z)|(\Atrace [A-Za-z_]\w*\Z)|(\Aquit\Z)|(\Amem\Z)") while True: global current_address cmd = input(">> ").strip() #Catch incorrect syntax if syntax.match(cmd) is None: if (cmd[0:4] == "next"): print("Incorrect command usage: try 'next [lines]'") elif (cmd[0:5] == "print") or (cmd[0:5] == "trace"): print("Invalid typing of the variable name") else: print("Wrong expression!!\n <code syntax>\n") print((" next\n" " next <integer>\n" " print <ID>\n" " trace <ID>\n" " quit\n")) continue #instruction handler if (cmd[0:4] == "next"): if (len(cmd) == 4): line_num = 1 else: line_num = int(cmd[5:]) for i in range(line_num): if program_end: break if debug: print("line", main_flow.lineno, main_flow.statement) try: if (main_flow.statement is None): prev_scope = None if main_flow.lineno in scope_start_line: scope_copy = copy.deepcopy(Scope_list[scope_start_line.index(main_flow.lineno)]) prev_scope = current_scope current_scope = scope_copy if debug: print("Change scope to", current_scope) if jump_to_new_func: # save parameter to new symbol_table params = func_table[new_func]['param_list'] for k in range(func_table[new_func]['param_num']): if type(params[k][1]) is tuple: current_scope.symbol_table[params[k][1][1]] = {'address': current_address, 'type': params[k][0]+"arr", 'value':[param_pass[k]], 'history':[(main_flow.lineno, param_pass_addr.pop(0))]} current_address += 4 else: current_scope.symbol_table[params[k][1]] = {'address': current_address, 'type':params[k][0] , 'value':[param_pass[k]], 'history':[(main_flow.lineno, param_pass[k])]} current_address += 4 if debug: current_scope.print_symboltable() jump_to_new_func = False else: current_scope.parent_scope = prev_scope elif main_flow.lineno in scope_end_line: prev_scope = current_scope current_scope = current_scope.parent_scope if debug: print("Change scope to", current_scope) main_flow = main_flow.next_node if (main_flow is None): current_scope = prev_scope print("End of program") program_end = True elif main_flow.statement[0] == 'declare': for j in range(len(main_flow.statement[2])): if type(main_flow.statement[2][j]) is tuple: if (main_flow.statement[2][j][0] == 'TIMES'): # declaration of pointer current_scope.symbol_table[main_flow.statement[2][j][1]] = {"address": current_address, "type":main_flow.statement[1]+"ptr", "value":['N/A'], "size":0, "history": [(main_flow.statement[-1], 'N/A')]} current_address += 4 else: # declaration of array current_scope.symbol_table[main_flow.statement[2][j][0]] = {"address": current_address, "type":main_flow.statement[1]+"arr", "size":int(main_flow.statement[2][j][1]), "value":[['N/A' for k in range(int(main_flow.statement[2][j][1]))]], "history": [(main_flow.statement[-1], current_address)]} current_address += 4 * int(main_flow.statement[2][j][1]) else: current_scope.symbol_table[main_flow.statement[2][j]] = {"address": current_address, "type":main_flow.statement[1], "value":['N/A'], "history": [(main_flow.statement[-1], 'N/A')]} current_address += 4 if debug: current_scope.print_symboltable() main_flow = main_flow.next_node elif main_flow.statement[0] == 'assign': assign_value(main_flow.statement[1], main_flow.statement[3], current_scope, main_flow.statement[-1]) if debug: current_scope.print_symboltable() current_scope.parent_scope.print_symboltable() if jump_to_new_func == False: main_flow = main_flow.next_node elif main_flow.statement[0] == 'FOR': if main_flow.visited: if main_flow.statement[4][0] in current_scope.symbol_table.keys(): if main_flow.statement[4][1] == '++': assign_value(main_flow.statement[4][0], get_value(main_flow.statement[4][0],current_scope)+1, current_scope, main_flow.statement[4][2]) elif main_flow.statement[4][1] == '--': assign_value(main_flow.statement[4][0], get_value(main_flow.statement[4][0],current_scope)-1, current_scope, main_flow.statement[4][2]) if (get_value(main_flow.statement[3][0], current_scope) < get_value(main_flow.statement[3][2],current_scope)): main_flow = main_flow.next_node_branch else: main_flow.visited = False main_flow = main_flow.next_node else: assign_value(main_flow.statement[2][1], main_flow.statement[2][3], current_scope, main_flow.statement[2][-1]) main_flow.visited = True if (calc_value(main_flow.statement[3], current_scope)): main_flow = main_flow.next_node_branch else: main_flow = main_flow.next_node if debug: current_scope.print_symboltable() elif main_flow.statement[0] == 'IF': if main_flow.visited: main_flow.visited = False main_flow = main_flow.next_node else: main_flow.visited = True if calc_value(main_flow.statement[2], current_scope): main_flow = main_flow.next_node_branch else: if main_flow.next_node_branch2 is not None: main_flow = main_flow.next_node_branch2 else: main_flow.visited = False main_flow = main_flow.next_node elif main_flow.statement[0] == 'WHILE': if calc_value(main_flow.statement[2], current_scope): main_flow = main_flow.next_node_branch else: main_flow = main_flow.next_node elif main_flow.statement[0] == 'RETURN': if len(main_flow.statement) > 2: # if there is a return value ret_val = calc_value(main_flow.statement[1], current_scope) if debug: print("Return value: ", ret_val) if len(flow_stack) != 0: ret_addr = flow_stack.pop() main_flow = ret_addr[0] current_scope = ret_addr[1] else: print("End of program") program_end = True elif main_flow.statement[0] == 'printf': print_string = None if "%f" in main_flow.statement[1][0]: print_string = main_flow.statement[1][0][1:-1].replace('%f', str(calc_value(main_flow.statement[1][1], current_scope))) elif "%d" in main_flow.statement[1][0]: print_string = main_flow.statement[1][0][1:-1].replace('%d', str(calc_value(main_flow.statement[1][1], current_scope))) else: # printf(const char*) print_string = main_flow.statement[1][0][1:-1] print(print_string.replace(r'\n', '\n'), end="") main_flow = main_flow.next_node elif main_flow.statement[0] == 'free': target_scope = memory.free(int(current_scope.symbol_table[main_flow.statement[1][0]]['history'][-1][1])) target_scope.symbol_table[main_flow.statement[1][0]]['history'].append((main_flow.lineno, 'N/A')) main_flow = main_flow.next_node elif main_flow.statement[0] in current_scope.symbol_table.keys(): if main_flow.statement[1] == '++': assign_value(main_flow.statement[0], get_value(main_flow.statement[0],current_scope)+1, current_scope, main_flow.statement[2]) elif main_flow.statement[1] == '--': assign_value(main_flow.statement[0], get_value(main_flow.statement[0],current_scope)-1, current_scope, main_flow.statement[2]) main_flow = main_flow.next_node except: print("Run-time error: line", main_flow.lineno) isError=True break if isError: break elif (cmd[0:5] == "trace"): if len(cmd) == 5: # No parameter pass else: print_trace(cmd[6:], current_scope) elif (cmd[0:5] == "print"): if len(cmd) == 5: # No parameter pass else: print_value(cmd[6:], current_scope) elif (cmd[0:4] == "quit"): break elif (cmd[0:3] == "mem"): print("Dynamic allocation : {}, {}".format(memory.num_used_fragment, memory.total_memory - memory.free_memory)) else: print("Exception!") if isError: break
## start with python -i scope_ex1.py from Scope import Scope ## Create a scope object with the channel you are using s = Scope(2) s.setup() ## Apply the signal and then adjust vertical scale so that signal ## just fills scope display. ## ## Keep horizontal timebase so that sampling rate is 500 MSa/s ## Read capture data ## Sometimes this locks up and you have to do ctrl-c and try again ## cd = s.read() ## You can turn off the signal source once the scope is in the stop state ## Save capture data to file ## cd.save("filename") ## repeat for various measurments ## ctrl-d to exit
def play(self, basescope=None): if basescope == None: basescope = Scope() self.before(basescope) self.playmain(basescope) self.after(basescope)
def execute(self, scope=None): if scope == None: scope = Scope() scope.execute(self.script)
def execute_child(self, child, base=None): assert isinstance(child, Playable) if base == None: base = Scope() child.play(Scope(base))
def execute_here(self, child, scope=None): assert isinstance(child, Playable) if scope == None: scope = Scope() child.play(scope)
def execute_script(self, script, base=None): assert isinstance(script, Script) if base == None: base = Scope() script.execute(base)
def eval(self, scope=None): if scope == None: scope = Scope() return scope.eval(self.script)
class Constants: varx = Variable('x') vary = Variable('y') varz = Variable('z') varo = Variable('o') emptyList = [] list123 = [Num(1), Num(2), Num(3)] listadd123 = [FuncApplication(Variable('+'), list123), Num(-3)] list12True = [Num(1), Num(2), Boolean(True)] listaddsubtract123 = [ FuncApplication(Variable('-'), list123), FuncApplication('+', list123) ] listmultiply123 = [FuncApplication(Variable('*'), list123)] list84 = [Num(8), Num(4)] listdivide84 = [FuncApplication(Variable('/'), list84)] listx23 = [varx, Num(2), Num(3)] listy3 = [vary, Num(3)] list43 = [Num(4), Num(3)] list403 = [Num(4), Num(0), Num(3)] expradd1 = FuncApplication(Variable('+'), [Num(1)]) expradd123 = FuncApplication(Variable('+'), list123) expradd43 = FuncApplication(Variable('+'), list43) expradderror = FuncApplication(Variable('+'), list12True) exprsub1 = FuncApplication(Variable('-'), [Num(1)]) exprsub123 = FuncApplication(Variable('-'), list123) exprsub_add123_add123 = FuncApplication(Variable('-'), [expradd123, expradd43]) exprdiv1 = FuncApplication(Variable('/'), [Num(1)]) exprdiv84 = FuncApplication(Variable('/'), list84) exprdiv403 = FuncApplication(Variable('/'), list403) exprmul1 = FuncApplication(Variable('*'), [Num(1)]) exprmul84 = FuncApplication(Variable('*'), list84) expradd_expradd123_exprdiv84 = FuncApplication(Variable('+'), [expradd123, exprdiv84]) expraddx23 = FuncApplication(Variable('+'), listx23) expraddy3 = FuncApplication(Variable('+'), listy3) expsub_expraddx23_expradd3 = FuncApplication(Variable('-'), [expraddx23, expraddy3]) #functions func_def_varx = FuncDef("f", LambdaExpr(["x"], Variable("x"))) func_app_varx = FuncApplication(Variable('f'), [Num(4)]) list_func_app_varx = [func_app_varx, Num(2)] expradd_func_app_varx = FuncApplication(Variable('+'), list_func_app_varx) funcDef2 = FuncDef('g', LambdaExpr([], expradd_func_app_varx)) func_app_emptylist = FuncApplication(Variable('g'), []) ############### expradd_varx_vary = FuncApplication(Variable('+'), [varx, vary]) func_def_add_varx_vary = FuncDef('z', LambdaExpr(['x', 'y'], expradd_varx_vary)) func_app_varx_vary = FuncApplication(Variable('z'), [Num(7), Num(7)]) func_app_error_777 = FuncApplication( Variable('z'), [Num(7), Num(7), Num(7)]) func_app_100 = FuncApplication(Variable('d'), [Num(100)]) defs1 = Scope(()).add_definitions() defs1 = defs1.extend('x', Num(1)).extend('y', Num(4)) #set the scope by mutating to second arg of the tuple defs1 = func_def_varx.eval(defs1)[1] defs1 = funcDef2.eval(defs1)[1] defs1 = func_def_add_varx_vary.eval(defs1)[1] #structs posn_def = StructDef('posn', ['x', 'y']) defs1 = posn_def.update(defs1) zeina_def = StructDef('zeina', ['x', 'y']) defs1 = zeina_def.update(defs1) make_zeina = FuncApplication(Variable('make-posn'), [Num(10), Num(20)]) select_zeina_x = FuncApplication(Variable('zeina-x'), [make_zeina]) make_posn = FuncApplication(Variable('make-posn'), [Num(1), Num(2)]) make_posn_comp = FuncApplication(Variable('make-posn'), [make_posn, Num(2)]) is_posn = FuncApplication(Variable('posn?'), [make_posn]) is_not_posn = FuncApplication(Variable('posn?'), [Num(3)]) select_posn_x = FuncApplication(Variable('posn-x'), [make_posn]) select_posn_y = FuncApplication(Variable('posn-y'), [make_posn]) select_posn_x_comp = FuncApplication(Variable('posn-x'), [make_posn_comp]) select_posn_y_comp = FuncApplication(Variable('posn-y'), [make_posn_comp]) value_posn = Structure('posn', [('x', Num(1)), ('y', Num(2))]) value_posn_comp = Structure('posn', [('x', value_posn), ('y', Num(2))]) #functions using struct make_posn_func = FuncApplication(Variable('make-posn'), [func_app_varx, Num(1)]) func_app_varx_1 = FuncApplication(Variable('f'), [make_posn_func]) value_posn_func = Structure('posn', [('x', Num(4)), ('y', Num(1))]) posn_x_func_app_varx_1 = FuncApplication(Variable('posn-x'), [func_app_varx_1]) select_posn_x_error = FuncApplication(Variable('posn-x'), [Num(3)]) ex1 = '(ex*' ex_abc = 'abc' ex_1 = '1' exx1 = ')' exx2 = ex_abc + exx1 #And and1 = And([Boolean(True), Boolean(False)]) and2 = And( [Boolean(False), FuncApplication(Variable('/'), [Num(1), Num(0)])]) and3 = And( [Boolean(True), FuncApplication(Variable('/'), [Num(1), Num(1)])]) #equals equals34 = FuncApplication(Variable('='), [Num(3), Num(4)]) equals33 = FuncApplication(Variable('='), [Num(3), Num(3)]) equals_3_true = FuncApplication(Variable('='), [Num(3), Boolean(False)]) #bigger and less than biggerthan34 = FuncApplication(Variable('>'), [Num(3), Num(4)]) lessthan34 = FuncApplication(Variable('<'), [Num(3), Num(4)]) lessthan_error = FuncApplication(Variable('>'), [Variable('xyz'), Num(4)]) #if. if_1 = If([equals34, Num(3), Num(4)]) if_2 = If([equals33, Num(3), Num(4)])