示例#1
0
def generate_graph(obj):
    obj = [obj[i] for i in xrange(len(obj)) if not not obj[i].strip()]
    flags = [
        0, 0, 0, 0, 0, 0, 0, 0, 0
    ]  # while_,do_while_,for_TO,for_IN,func_,if_,select_,switch_,with_
    for line in obj:
        print line
        # Ajustar con Kernel.ExtractKeywords // Cuidado con el orden -> Do While antes de While y demás ..#
        if ex.is_do_while(line): flags[1] = 1
        if ex.is_while(line): flags[0] = 1
        if ex.is_for_to(line): flags[2] = 1
        if ex.is_for_in(line): flags[3] = 1
        if ex.is_func(line): flags[4] = 1
        if ex.is_if(line): flags[5] = 1
        if ex.is_select(line): flags[6] = 1
        if ex.is_switch(line): flags[7] = 1
        if ex.is_with(line): flags[8] = 1

        if ex.is_end_while(line): flags[0] = 0
        if ex.is_until(line): flags[1] = 0
        if ex.is_next(line):
            if flags[2] == 1: flags[2] = 0  # Si es TO #
            else: flags[3] = 0  # Si es IN #
        if ex.is_end_func(line): flags[4] = 0
        if ex.is_end_if(line): flags[5] = 0
        if ex.is_end_select(line): flags[6] = 0
        if ex.is_end_switch(line): flags[7] = 0
        if ex.is_end_with(line): flags[8] = 0
        raw_input()
        print flags
示例#2
0
def generate_graph(obj):
    obj   = [obj[i] for i in xrange(len(obj)) if not not obj[i].strip()]
    flags = [0,0,0,0,0,0,0,0,0] # while_,do_while_,for_TO,for_IN,func_,if_,select_,switch_,with_
    for line in obj:
	print line
	# Ajustar con Kernel.ExtractKeywords // Cuidado con el orden -> Do While antes de While y demás ..#
	if ex.is_do_while(line): flags[1] = 1
	if ex.is_while(line): flags[0] = 1
	if ex.is_for_to(line): flags[2] = 1
	if ex.is_for_in(line): flags[3] = 1
	if ex.is_func(line): flags[4] = 1
	if ex.is_if(line): flags[5] = 1
	if ex.is_select(line): flags[6] = 1
	if ex.is_switch(line): flags[7] = 1
	if ex.is_with(line): flags[8] = 1
	
	
	
	if ex.is_end_while(line): flags[0] = 0
	if ex.is_until(line): flags[1] = 0
	if ex.is_next(line):
	    if flags[2]==1: flags[2] = 0 # Si es TO #
	    else:           flags[3] = 0 # Si es IN #
	if ex.is_end_func(line): flags[4] = 0
	if ex.is_end_if(line): flags[5] = 0
	if ex.is_end_select(line): flags[6] = 0
	if ex.is_end_switch(line): flags[7] = 0
	if ex.is_end_with(line): flags[8] = 0
	raw_input()
	print flags
def add_true_guard_statements(obj,n_true_guard_statements_min_left=1,n_true_guard_statements_max_left=2,
			      n_true_guard_statements_min_right=1,n_true_guard_statements_max_right=2):
    for i in xrange(len(obj)):
	n_guard_statements_left = randint(min(n_true_guard_statements_min_left,n_true_guard_statements_max_left),
				     max(n_true_guard_statements_min_left,n_true_guard_statements_max_left))
	
	n_guard_statements_right = randint(min(n_true_guard_statements_min_right,n_true_guard_statements_max_right),
				     max(n_true_guard_statements_min_right,n_true_guard_statements_max_right))
	
	is_if       = ex.is_if(obj[i])
	is_else_if  = ex.is_else_if(obj[i])
	is_while    = ex.is_while(obj[i])
	is_until    = ex.is_until(obj[i])
	
	if is_if or is_else_if or is_while or is_until:
	    
	    true_guard_statements_left     = [Utils.generate_true_statement(n_min_value=100,n_max_value=300) for j in xrange(n_guard_statements_left)]
	    true_guard_statements_right    = [Utils.generate_true_statement(n_min_value=100,n_max_value=300) for j in xrange(n_guard_statements_right)]
		
	    if is_if or is_else_if: obj[i] = add_true_guard_statements_if(obj[i],n_guard_statements_left,
									  true_guard_statements_left,
									  n_guard_statements_right,
									  true_guard_statements_right)
									  
	    if is_while or is_until: obj[i] = add_true_guard_statements_while(obj[i],n_guard_statements_left,
									  true_guard_statements_left,
									  n_guard_statements_right,
									  true_guard_statements_right)
		
    return obj