def while_denning(iteration, called_by_fun, fun_global, while_str, PC): # debug print "printing while_str",while_str[6:10] compare = "()" if while_str[6:10] == "Name": tmp = parse_parenthesis(10, while_str) compare = tmp[0] i = tmp[1] elif while_str[6:10] == "Comp": tmp = parse_parenthesis(13, while_str) compare = tmp[0] i = tmp[1] pc_update(PC, parse_variables(compare)) # body processing body_onward_str = while_str[ i:] ### Asumption : Compare string always followed by body=[...] imediatly # setting i to location of [ in body_str: ,body=[.. i = body_onward_str.find("[") body_str = parse_square_br(i, body_onward_str)[0] memo = {} memo2 = {} PC1 = copy._deepcopy_list(PC, memo) PC2 = copy._deepcopy_list(PC, memo2) PCB = list( continuous_parse([], called_by_fun, fun_global, body_str, PC2[:])) return PC1 + PCB
def if_denning(G, called_by_fun, fun_global, if_str, rest, PC): # type: (list, list, string, dict, string) -> print rules #pdb.set_trace() #print "begin IF",PC if "orelse=" not in if_str: # print "termination",if_str if if_str[0:2] == "[]": # absence of else part return [] else: # handling else part else_str = if_str continuous_parse(G, [], ccalled_by_fun, fun_global, else_str, PC[:]) return [] tmp = split_through_orelse(if_str) if_half = tmp[0] ladder = tmp[1] if if_str[1:5] != "test": print "Error test not found in if" """extract test=...() from if_half""" i = if_half.find("(") tmp = parse_parenthesis(i, if_half) test_str = tmp[0] #parent_list += parse_variables(test_str) i = tmp[1] pc_update(PC, parse_variables(test_str)) """then extract body part and process like normal AST text """ # body processing body_onward_str = if_half[ i:] ### Asumption : Compare string always followed by body=[...] imediatly # setting i to location of [ in body_str: ,body=[.. i = body_onward_str.find("[") body_str = parse_square_br(i, body_onward_str)[0] memo = {} memo2 = {} PC1 = copy._deepcopy_list(PC, memo) PC2 = copy._deepcopy_list(PC, memo2) PCA = list( continuous_parse(G, [], called_by_fun, fun_global, body_str, PC1[:])) PCB = list( continuous_parse(G, [], called_by_fun, fun_global, ladder, PC2[:])) #debugPrint(PCA) #debugPrint(PCB) #print "end IF",PCB + PCA return PCB + PCA
def save_state(self, state): self.last_playing_order = list( map(lambda x: x.index, state.get_playing_order())).index(self.index) #self.last_score = copy.copy(state.scores[self.index]) self.last_board = copy.copy(state.board) self.last_hand = copy._deepcopy_list(self.hand, memo={}) self.num_players = len(state.players) self.last_legal_actions = self.getLegalActions(state) self.last_lead_card = state.get_lead_card()
def update_event(self, inp=-1): self.set_output_val(0, copy._deepcopy_list(self.input(0), self.input(1), self.input(2)))
def continuous_parse(funPC, called_by_fun, fun_global, data, PC): #pdb.set_trace() # type: (object, object) -> object global recCount length = len(data) i = 0 recCount += 1 debugPrint(recCount) debugPrint("Continuous_parse before loop:") while i < length - 1: #checking for keyword if parse_keyword( i, data) == "FunctionDef": #skipping all function definition tmp = parse_parenthesis(i + 11, data) i = tmp[1] if parse_keyword( i, data ) == "thread_fun_call": #parsing function call used in threads tmp = parse_parenthesis(i + 4, data) i = tmp[1] if 'start_new_thread' in tmp[0]: #print "got thread call" fi = tmp[0].find("args=[") funName = extract_variavle_name( fi + 15, tmp[0]) #len(args=[Name(id=') = 15 if funName in fun_hash: findex = fun_hash[funName] else: print "Function not found but prgram called function" findex += 11 tmp = parse_parenthesis(findex, data) fun_str = tmp[0] tmp = fun_denning(fun_str, [[]]) memo = {} ls = duplicateRemoval(tmp) PC = copy._deepcopy_list(ls, memo) if parse_keyword(i, data) == "fun_call": #parsing functioncalls tmp = parse_parenthesis(i + 4, data) #print "got fun call" funName = extract_variavle_name( i + len("Expr(value=Call(func=Name(id='"), data) i = tmp[1] if funName in fun_hash: findex = fun_hash[funName] else: print "Function not found but prgram called function" findex += 11 tmp = parse_parenthesis(findex, data) fun_str = tmp[0] tmp = fun_denning(fun_str, PC) memo = {} ls = duplicateRemoval(tmp) PC = copy._deepcopy_list(ls, memo) if parse_keyword(i, data) == "Return": debugPrint("Return stmt:") funPC += PC if parse_keyword(i, data) == "set_clear_wait": i += 4 tmp = parse_parenthesis(i, data) expr_str = tmp[0] if expr_str.find("'set'") != -1 or expr_str.find( "'clear'") != -1 or expr_str.find("'wait'") != -1: i = tmp[1] set_clear_denning(called_by_fun, fun_global, expr_str, PC) if parse_keyword(i, data) == "AugAssign": i += 9 tmp = parse_parenthesis(i, data) augAssign_str = tmp[0] i = tmp[1] tmp = augAssign_denning(parent_list[:], global_while_list, called_by_fun, fun_global, augAssign_str, PC[:]) memo = {} ls = duplicateRemoval(tmp) PC = copy._deepcopy_list(ls, memo) if parse_keyword(i, data) == "Assign": global ww ww += 1 i += 6 tmp = parse_parenthesis(i, data) assign_str = tmp[0] i = tmp[1] if "value=Name(id='threading'" in assign_str: continue tmp = assign_denning(assign_str, PC[:]) memo = {} ls = duplicateRemoval(tmp) PC = copy._deepcopy_list(ls, memo) elif parse_keyword(i, data) == "If": debugPrint("If stmt:") global ww1 ww1 += 1 i += 2 tmp = parse_if(i, data) if_str = tmp[0] i = tmp[1] rest = tmp[2] tmp = if_denning(called_by_fun, fun_global, if_str, rest, PC[:]) ls = duplicateRemoval(tmp) memo = {} PC = copy._deepcopy_list(ls, memo) elif parse_keyword(i, data) == "While": debugPrint("while stmt:") global ww2 ww2 += 1 i += 5 tmp = parse_parenthesis(i, data) while_str = tmp[0] i = tmp[1] it = 1 while (it <= iteration): memo = {} lastPC = copy._deepcopy_list(PC, memo) tmp = duplicateRemoval(PC) memo = {} PC = copy._deepcopy_list(tmp, memo) #print "### While Iteration:",it tmp = while_denning(it, called_by_fun, fun_global, while_str, PC[:]) ls = duplicateRemoval(tmp) memo = {} PC = copy._deepcopy_list(ls, memo) #print lastPC,"|--|", PC #print "-> PC:",PC if lastPC == PC: #print "Saturation point of loop!" break it += 1 i += 1 debugPrint(recCount) recCount -= 1 debugPrint("END continuous parse:") return PC[:]