Exemplo n.º 1
0
def block_while(deep_act,
                n_statements_min=10,
                n_statements_max=20,
                n_guard_statements_min=1,
                n_guard_statements_max=5,
                n_else_if_min=1,
                n_else_if_max=5,
                deep_max=5,
                case_values_min=-1000,
                case_values_max=1000):
    # Generalizar bucles while con más de una condición en la guarda, incrementos variables y variabilidad en la actualización de variables (incrementar parte derecha = decrementar parte izquierda) #
    var_one, val_one = variable(), integer()
    var_two, val_two = variable(), integer()
    declarations    = Utils.generate_random_declarator() + var_one + " = " + val_one + "\n" +\
        Utils.generate_random_declarator() + var_two + " = " + val_two + "\n"
    rel_op = choice([">", "<", ">=", "<=", "="])  #relational_operation()
    res             = Utils.low_up_string(" While ")+var_one+rel_op+var_two+"\n"+ \
        block(deep_act+1,n_statements_min,n_statements_max,n_guard_statements_min,
       n_guard_statements_max,n_else_if_min,n_else_if_max,deep_max,case_values_min,
       case_values_max)+"\n"

    if rel_op == ">": res += var_one + " -= 1\n"
    elif rel_op == "<": res += var_one + " += 1\n"
    elif rel_op == ">=": res += var_one + " -= 1\n"
    elif rel_op == "<=": res += var_one + " += 1\n"
    elif rel_op == "=": res += var_one + " += 1\n"
    elif rel_op == "<>":
        v_max = max(val_one, val_two)
        if v_max == val_one: res += var_one + " -= 1\n"
        else: res += var_two + " -= 1\n"
    res += Utils.low_up_string("\nWEnd\n")
    return declarations + res
Exemplo n.º 2
0
def block_func(arity_min=1,
               arity_max=4,
               identifiers_length_min=5,
               identifiers_length_max=10,
               n_statements_min=10,
               n_statements_max=20,
               n_guard_statements_min=1,
               n_guard_statements_max=5,
               n_else_if_min=1,
               n_else_if_max=5,
               deep_max=5,
               case_values_min=-1000,
               case_values_max=1000):
    id_func, arity = Utils.generate_identifier(
        identifiers_length_min,
        identifiers_length_max), randint(min(arity_min, arity_max),
                                         max(arity_min, arity_max))
    Config.TDS_FUNCTIONS[id_func] = arity  # ¿Sobra?
    res = Utils.low_up_string("Func ") + id_func + "("
    for i in xrange(arity):
        if i < arity - 1: res += variable() + ","
        else: res += variable()
    res += ")\n\n\n" + block(
        0, n_statements_min, n_statements_max, n_guard_statements_min,
        n_guard_statements_max, n_else_if_min, n_else_if_max, deep_max,
        case_values_min, case_values_max) + Utils.low_up_string("\n EndFunc\n")
    Globals.arity_new_functions.append(arity)
    return res
Exemplo n.º 3
0
def simple_block(n_statements_min=10,n_statements_max=20): 
    n_statements = randint(min(n_statements_min,n_statements_max),max(n_statements_min,n_statements_max))
    variables    = [variable() for i in xrange(n_statements)]
    values       = [value() for i in xrange(n_statements)]
    res = ""
    for i in xrange(n_statements): res += assign(variables[i],values[i])+"\n"
    #res += enum(1,3,5,10) + "\n"
    #elif rnd==2: res += ternary_operation(1,3)
    for i in xrange(n_statements/2):
	""" -3 -> ternary
	    -2 -> enum
	    -1 -> arithmetic assign
	    0  -> f arity 0
	    1  -> f arity 1
	    2  -> f arity 2
	"""
	arity = randint(-1,2)
	if arity==-1:   
	    r,rp  = randint(0,len(variables)-1),randint(0,len(variables)-1)
	    res  += variables[r]+" "+arithmetic_assign()+" "+variables[rp]+"\n"
	elif arity==0:  res  += Utils.low_up_string(choice(Config.FUNCTIONS_ZERO_ARITY)) + "()\n"
	elif arity==1:  
	    r,rf,rp  = randint(0,len(variables)-1),randint(0,len(Config.FUNCTIONS_ONE_ARITY)-1),randint(0,len(variables)-1)
	    res  += variables[r]+" "+arithmetic_assign()+" "+Utils.low_up_string(Config.FUNCTIONS_ONE_ARITY[rf])+"("+variables[rp]+")\n"
	elif arity==2:
	    r,rf,rp,rt = randint(0,len(variables)-1),randint(0,len(Config.FUNCTIONS_TWO_ARITY)-1),randint(0,len(variables)-1),randint(0,len(variables)-1)
	    res  += variables[r]+" "+arithmetic_assign()+" "+Utils.low_up_string(Config.FUNCTIONS_TWO_ARITY[rf])+"("+variables[rp]+","+variables[rt]+")\n"
    return res
Exemplo n.º 4
0
def block_for(deep_act,
              n_statements_min=10,
              n_statements_max=20,
              n_guard_statements_min=1,
              n_guard_statements_max=5,
              n_else_if_min=1,
              n_else_if_max=5,
              deep_max=5,
              case_values_min=-1000,
              case_values_max=1000):
    a, b = integer(), integer()
    a, b = min(a, b), max(a, b)
    v = variable()
    declaration = Utils.generate_random_declarator() + assign_by_var_name(
        v) + "\n\n"
    res = Utils.low_up_string("For ") + assign_full(
        v, a) + Utils.low_up_string(" To ") + b
    rnd_step = randint(0, 1)
    if rnd_step == 1:
        res += Utils.low_up_string(" Step ") + str(randint(1, 10)) + " \n"
    else:
        res += "\n"
    res += block(deep_act + 1, n_statements_min, n_statements_max,
                 n_guard_statements_min, n_guard_statements_max, n_else_if_min,
                 n_else_if_max, deep_max, case_values_min,
                 case_values_max) + Utils.low_up_string("\n Next\n")
    return declaration + res
Exemplo n.º 5
0
def block_switch(deep_act,
                 n_statements_min=10,
                 n_statements_max=20,
                 n_guard_statements_min=1,
                 n_guard_statements_max=5,
                 n_else_if_min=1,
                 n_else_if_max=5,
                 deep_max=5,
                 case_values_min=-1000,
                 case_values_max=1000):
    v = variable()
    declaration = Utils.generate_random_declarator() + assign_by_var_name(
        v) + "\n"
    n_cases = randint(min(n_else_if_min, n_else_if_max),
                      max(n_else_if_min, n_else_if_max))
    res = Utils.low_up_string("Switch ") + v + "\n"
    for i in xrange(n_cases):
        a, b = integer(min(case_values_min, case_values_max),
                       max(case_values_min, case_values_max)), integer(
                           min(case_values_min, case_values_max),
                           max(case_values_min, case_values_max))
        a, b = min(a, b), max(a, b)
        res += Utils.low_up_string(
            "Case ") + a + Utils.low_up_string(" To ") + b + "\n" + block(
                deep_act, n_statements_min, n_statements_max,
                n_guard_statements_min, n_guard_statements_max, n_else_if_min,
                n_else_if_max, deep_max, case_values_min, case_values_max)
        res += "\nCase Else\n" + block(
            deep_act, n_statements_min, n_statements_max,
            n_guard_statements_min, n_guard_statements_max, n_else_if_min,
            n_else_if_max, deep_max, case_values_min, case_values_max)
    res += Utils.low_up_string("\nEndSwitch\n")
    return declaration + res
Exemplo n.º 6
0
def block_with(deep_act,n_statements_min=10,n_statements_max=20,n_guard_statements_min=1,n_guard_statements_max=5,n_else_if_min=1,n_else_if_max=5,deep_max=5,case_values_min=-1000,case_values_max=1000):
    v           = variable()
    declaration = Utils.generate_random_declarator()+v+' = ObjCreate("shell.application") \n'
    res 	= Utils.low_up_string(" With ") + v + "\n" + \
		  block(deep_act+1,n_statements_min,n_statements_max,n_guard_statements_min,
			n_guard_statements_max,n_else_if_min,n_else_if_max,deep_max,case_values_min,
			case_values_max)+Utils.low_up_string("\n EndWith\n")
    return declaration+res
Exemplo n.º 7
0
def simple_block(n_statements_min=10, n_statements_max=20):
    n_statements = randint(min(n_statements_min, n_statements_max),
                           max(n_statements_min, n_statements_max))
    variables = [variable() for i in xrange(n_statements)]
    values = [value() for i in xrange(n_statements)]
    res = ""
    for i in xrange(n_statements):
        res += assign(variables[i], values[i]) + "\n"
    #res += enum(1,3,5,10) + "\n"
    #elif rnd==2: res += ternary_operation(1,3)
    for i in xrange(n_statements / 2):
        """ -3 -> ternary
	    -2 -> enum
	    -1 -> arithmetic assign
	    0  -> f arity 0
	    1  -> f arity 1
	    2  -> f arity 2
	"""
        arity = randint(-1, 2)
        if arity == -1:
            r, rp = randint(0,
                            len(variables) - 1), randint(
                                0,
                                len(variables) - 1)
            res += variables[r] + " " + arithmetic_assign(
            ) + " " + variables[rp] + "\n"
        elif arity == 0:
            res += Utils.low_up_string(choice(
                Config.FUNCTIONS_ZERO_ARITY)) + "()\n"
        elif arity == 1:
            r, rf, rp = randint(0,
                                len(variables) - 1), randint(
                                    0,
                                    len(Config.FUNCTIONS_ONE_ARITY) -
                                    1), randint(0,
                                                len(variables) - 1)
            res += variables[r] + " " + arithmetic_assign(
            ) + " " + Utils.low_up_string(
                Config.FUNCTIONS_ONE_ARITY[rf]) + "(" + variables[rp] + ")\n"
        elif arity == 2:
            r, rf, rp, rt = randint(
                0,
                len(variables) - 1), randint(
                    0,
                    len(Config.FUNCTIONS_TWO_ARITY) - 1), randint(
                        0,
                        len(variables) - 1), randint(0,
                                                     len(variables) - 1)
            res += variables[r] + " " + arithmetic_assign(
            ) + " " + Utils.low_up_string(
                Config.FUNCTIONS_TWO_ARITY[rf]
            ) + "(" + variables[rp] + "," + variables[rt] + ")\n"
    return res
Exemplo n.º 8
0
def enum(n_enumeration_min=1,n_enumeration_max=3,length_min=5,length_max=10):
    rnd_enum = randint(n_enumeration_min,n_enumeration_max)
    r        = Utils.low_up_string("Local Enum ")
    rnd_step = randint(0,1)
    if rnd_step==1:       r   += Utils.low_up_string("Step ")+enum_stepval()+" "
    for i in xrange(rnd_enum):
	var = variable(length_min,length_max)
	val = value()
	r  += var_definition(var,val)
	if i != rnd_enum-1: r += ", "
	else:               r += " "
    return r
Exemplo n.º 9
0
def block_switch(deep_act,n_statements_min=10,n_statements_max=20,n_guard_statements_min=1,n_guard_statements_max=5,n_else_if_min=1,n_else_if_max=5,deep_max=5,case_values_min=-1000,case_values_max=1000): 
    v = variable()
    declaration = Utils.generate_random_declarator()+assign_by_var_name(v)+"\n"
    n_cases = randint(min(n_else_if_min,n_else_if_max),max(n_else_if_min,n_else_if_max))
    res = Utils.low_up_string("Switch ")+v+"\n" 
    for i in xrange(n_cases):
	a,b = integer(min(case_values_min,case_values_max),max(case_values_min,case_values_max)),integer(min(case_values_min,case_values_max),max(case_values_min,case_values_max))
	a,b = min(a,b),max(a,b)
	res += Utils.low_up_string("Case ")+a+Utils.low_up_string(" To ")+b+"\n"+block(deep_act,n_statements_min,n_statements_max,n_guard_statements_min,n_guard_statements_max,n_else_if_min,n_else_if_max,deep_max,case_values_min,case_values_max)
	res += "\nCase Else\n"+block(deep_act,n_statements_min,n_statements_max,n_guard_statements_min,n_guard_statements_max,n_else_if_min,n_else_if_max,deep_max,case_values_min,case_values_max)
    res += Utils.low_up_string("\nEndSwitch\n")
    return declaration+res
Exemplo n.º 10
0
def add_true_guard_statements_while(line,n_guard_statements_left,true_guard_statements_left,
			         n_guard_statements_right,true_guard_statements_right):
				     				     
    line = line.strip()
    if line[-1]!="_":
	splitted = split("\s",line)
	line = splitted[0] + " "
	if n_guard_statements_left>0:
	    line += Utils.low_up_string(" And ").join(true_guard_statements_left) + Utils.low_up_string(" And ")
	line += " ".join(splitted[1:])
	if n_guard_statements_right>0:
	    line += Utils.low_up_string(" And ") + Utils.low_up_string(" And ").join(true_guard_statements_right)
    return line
Exemplo n.º 11
0
def block_for(deep_act,n_statements_min=10,n_statements_max=20,n_guard_statements_min=1,n_guard_statements_max=5,n_else_if_min=1,n_else_if_max=5,deep_max=5,case_values_min=-1000,case_values_max=1000): 
    a,b = integer(),integer()
    a,b = min(a,b),max(a,b)
    v   = variable()
    declaration = Utils.generate_random_declarator()+assign_by_var_name(v)+"\n\n"
    res = Utils.low_up_string("For ")+assign_full(v,a)+Utils.low_up_string(" To ")+b
    rnd_step = randint(0,1)
    if rnd_step==1:    
	res += Utils.low_up_string(" Step ")+str(randint(1,10))+" \n"
    else:              res += "\n"
    res += block(deep_act+1,n_statements_min,n_statements_max,n_guard_statements_min,
	         n_guard_statements_max,n_else_if_min,n_else_if_max,deep_max,case_values_min,
	         case_values_max)+Utils.low_up_string("\n Next\n")
    return declaration+res
Exemplo n.º 12
0
def enum(n_enumeration_min=1,
         n_enumeration_max=3,
         length_min=5,
         length_max=10):
    rnd_enum = randint(n_enumeration_min, n_enumeration_max)
    r = Utils.low_up_string("Local Enum ")
    rnd_step = randint(0, 1)
    if rnd_step == 1: r += Utils.low_up_string("Step ") + enum_stepval() + " "
    for i in xrange(rnd_enum):
        var = variable(length_min, length_max)
        val = value()
        r += var_definition(var, val)
        if i != rnd_enum - 1: r += ", "
        else: r += " "
    return r
Exemplo n.º 13
0
def block_while(deep_act,n_statements_min=10,n_statements_max=20,n_guard_statements_min=1,n_guard_statements_max=5,n_else_if_min=1,n_else_if_max=5,deep_max=5,case_values_min=-1000,case_values_max=1000): 
    n_guard_statements = randint(min(n_guard_statements_min,n_guard_statements_max),
			        max(n_guard_statements_min,n_guard_statements_max))
    vars_one = []
    vars_two = []
    vals_one = []
    vals_two = []
    rel_ops  = []
    declarations = []
    for i in xrange(n_guard_statements):
	vars_one.append(variable())
	vars_two.append(variable())
	vals_one.append(integer(100,1000))
	vals_two.append(integer(100,1000))
	rel_ops.append(choice([">","<",">=","<=","="]))
	declarations.append(Utils.generate_random_declarator() + vars_one[i] + " = " + vals_one[i])
	declarations.append(Utils.generate_random_declarator() + vars_two[i] + " = " + vals_two[i])
    
    res      = Utils.low_up_string(" While ")
   
    for i in xrange(n_guard_statements):
	res += vars_one[i] + " " + rel_ops[i] + " "+ vars_two[i]
	if i<n_guard_statements-1: res += Utils.low_up_string(" Or ")
    
    res += "\n"
    
    res += block(deep_act+1,n_statements_min,n_statements_max,n_guard_statements_min,
			    n_guard_statements_max,n_else_if_min,n_else_if_max,deep_max,case_values_min,
			    case_values_max)+"\n"
			    
    
    for i in xrange(n_guard_statements):
	if rel_ops[i]==">":
	    if vals_one[i]>vals_two[i]: 
		res += choice([vars_one[i] + " -= 1\n", vars_two[i] + " += 1\n"])
	elif rel_ops[i]=="<":
	    if vals_one[i]<vals_two[i]:  res += choice([vars_one[i] + " += 1\n",vars_two[i] + " -= 1\n"])
	elif rel_ops[i]==">=":
	    if vals_one[i]>=vals_two[i]: 
		res += choice([vars_one[i] + " -= 1\n", vars_two[i] + " += 1\n"])
	elif rel_ops[i]=="<=":
	     if vals_one[i]<=vals_two[i]: res += choice([vars_one[i] + " += 1\n",vars_two[i] + " -= 1\n"])
	elif rel_ops[i]=="=":
	    if vals_one[i]==vals_two[i]: res += choice([vars_one[i] + " += 1\n",vars_two[i] + " -= 1\n" , 
							vars_one[i] + " -= 1\n",vars_two[i] + " += 1\n"])
			
    res += Utils.low_up_string("\nWEnd\n")
    return "\n".join(declarations)+"\n"+res
Exemplo n.º 14
0
def assign(var, val):
    rnd = randint(0, 1)
    if rnd == 0:
        return Utils.generate_random_declarator() + var + " = " + val + "\n"
    else:
        return Utils.generate_random_declarator(
        ) + var + " = 0\n" + Utils.low_up_string(
            "Assign") + "('" + var + "','" + val.replace('"', "").replace(
                "'", "") + "')\n"
Exemplo n.º 15
0
def block_with(deep_act,
               n_statements_min=10,
               n_statements_max=20,
               n_guard_statements_min=1,
               n_guard_statements_max=5,
               n_else_if_min=1,
               n_else_if_max=5,
               deep_max=5,
               case_values_min=-1000,
               case_values_max=1000):
    v = variable()
    declaration = Utils.generate_random_declarator(
    ) + v + ' = ObjCreate("shell.application") \n'
    res  = Utils.low_up_string(" With ") + v + "\n" + \
    block(deep_act+1,n_statements_min,n_statements_max,n_guard_statements_min,
    n_guard_statements_max,n_else_if_min,n_else_if_max,deep_max,case_values_min,
    case_values_max)+Utils.low_up_string("\n EndWith\n")
    return declaration + res
Exemplo n.º 16
0
def block_func(arity_min=1,arity_max=4,identifiers_length_min=5,identifiers_length_max=10,n_statements_min=10,n_statements_max=20,n_guard_statements_min=1,n_guard_statements_max=5,n_else_if_min=1,n_else_if_max=5,deep_max=5,case_values_min=-1000,case_values_max=1000):
    id_func,arity = Utils.generate_identifier(identifiers_length_min,identifiers_length_max),randint(min(arity_min,arity_max),max(arity_min,arity_max))
    Config.TDS_FUNCTIONS[id_func]=arity # ¿Sobra?
    res = Utils.low_up_string("Func ")+id_func+"("
    for i in xrange(arity):
	if i<arity-1:  res += variable()+","
	else:          res += variable()
    res += ")\n\n\n"+block(0,n_statements_min,n_statements_max,n_guard_statements_min,n_guard_statements_max,n_else_if_min,n_else_if_max,deep_max,case_values_min,case_values_max)+Utils.low_up_string("\n EndFunc\n")
    Globals.arity_new_functions.append(arity)
    return res
Exemplo n.º 17
0
def add_true_guard_statements_if(line,n_guard_statements_left,true_guard_statements_left,
			         n_guard_statements_right,true_guard_statements_right):
    line = line.strip()
    if line[-1]!="_": 
	aux    = line.title()
	splitted_aux = split("\s",aux)
	splitted     = split("\s",line)
	index_then = splitted_aux.index("Then")
		    
	line = splitted[0] + " " 
		    
	if n_guard_statements_left>0:
	    line += Utils.low_up_string(" And ").join(true_guard_statements_left) + Utils.low_up_string(" And ")
			
	line += " ".join(splitted[1:index_then])
		    
	if n_guard_statements_right>0:
	    line += Utils.low_up_string(" And ") + Utils.low_up_string(" And ").join(true_guard_statements_right)
			
	line += " " + " ".join(splitted[index_then:])
    return line
Exemplo n.º 18
0
def add_hardcoded_funcs(obj,add_calls=False,functions=Globals.defined_new_functions,arity=Globals.arity_new_functions,n_funcs_min=3,n_funcs_max=5):
    n_funcs = randint(min(n_funcs_min,n_funcs_max),max(n_funcs_min,n_funcs_max))
    shuffle(hp.HARDCODED_PROGRAMS)
    funcs   = hp.HARDCODED_PROGRAMS[:n_funcs]
    for i in xrange(n_funcs):
	function_code   = funcs[i]()
	obj.insert(0,function_code+"\n\n")
	if add_calls:
	    arity           = Globals.arity_new_functions[-1]
	    identifier      = Globals.defined_new_functions[-1]
	    params          = ",".join([g.value() for i in xrange(arity)])
	    obj.insert(0,Utils.low_up_string(Utils.generate_random_declarator()) + \
		       g.variable() + " = " + identifier + "("+params+")\n\n")
    return obj
Exemplo n.º 19
0
def block_if(deep_act,
             n_statements_min=10,
             n_statements_max=20,
             n_guard_statements_min=1,
             n_guard_statements_max=5,
             n_else_if_min=1,
             n_else_if_max=5,
             deep_max=5,
             case_values_min=-1000,
             case_values_max=1000):
    res = Utils.low_up_string("If ")
    declarations = ""
    n_guard_statements = randint(
        min(n_guard_statements_min, n_guard_statements_max),
        max(n_guard_statements_min, n_guard_statements_max))
    log_statements = logical_statements(
        n_guard_statements) + Utils.low_up_string(" Then") + "\n"
    logic_variables = ExtractKeywords.extract_variables(log_statements)
    for i in logic_variables:
        declarations += Utils.generate_random_declarator(
        ) + assign_by_var_name(i) + "\n"
    res += log_statements
    res += block(deep_act + 1, n_statements_min, n_statements_max,
                 n_guard_statements_min, n_guard_statements_max, n_else_if_min,
                 n_else_if_max, deep_max, case_values_min,
                 case_values_max) + "\n"
    else_type = randint(0, 1)  # 0 -> Else if, 1 -> Else #
    if else_type == 0:
        n_else_if = randint(min(n_else_if_min, n_else_if_max),
                            max(n_else_if_min, n_else_if_max))
        for i in xrange(n_else_if):
            log_statements = logical_statements(
                randint(min(n_guard_statements_min, n_guard_statements_max),
                        max(n_guard_statements_min, n_guard_statements_max)))
            logic_variables = ExtractKeywords.extract_variables(log_statements)
            for i in logic_variables:
                declarations += Utils.generate_random_declarator(
                ) + assign_by_var_name(i) + "\n"
            res += Utils.low_up_string(
                "ElseIf ") + log_statements + Utils.low_up_string(
                    " Then\n") + block(
                        deep_act + 1, n_statements_min, n_statements_max,
                        n_guard_statements_min, n_guard_statements_max,
                        n_else_if_min, n_else_if_max, deep_max,
                        case_values_min, case_values_max) + "\n"
    res += Utils.low_up_string("Else ") + "\n" + block(
        deep_act + 1, n_statements_min, n_statements_max,
        n_guard_statements_min, n_guard_statements_max, n_else_if_min,
        n_else_if_max, deep_max, case_values_min, case_values_max) + "\n"
    res += Utils.low_up_string("EndIf") + "\n"
    return declarations + res
Exemplo n.º 20
0
def block_while(deep_act,
                n_statements_min=10,
                n_statements_max=20,
                n_guard_statements_min=1,
                n_guard_statements_max=5,
                n_else_if_min=1,
                n_else_if_max=5,
                deep_max=5,
                case_values_min=-1000,
                case_values_max=1000):
    n_guard_statements = randint(
        min(n_guard_statements_min, n_guard_statements_max),
        max(n_guard_statements_min, n_guard_statements_max))
    log_statements, declarations = logical_statements(n_guard_statements), ""
    logic_variables = ExtractKeywords.extract_variables(log_statements)
    relational_operators = ExtractKeywords.extract_relational_operators(
        log_statements)
    const_values = ExtractKeywords.extract_integer(log_statements)
    for i in logic_variables:
        declarations += Utils.generate_random_declarator(
        ) + assign_by_var_name(i) + "\n"
    res = declarations + Utils.low_up_string("\nWhile ") + log_statements
    return res  # Acabar #
Exemplo n.º 21
0
def hide_definitions_with_assign(obj):
    for i in xrange(len(obj)):
        obj[i] = obj[i].strip()
        aux = obj[i].lower()
        res = ""
        if len(obj[i]) > 0 and obj[i][-1] != "_" and aux.find(
                "eval(") == -1 and aux.find("assign(") == -1:
            if obj[i][0] == "$":
                assign_expression = ex.extract_assign_expressions(obj[i])
                if len(assign_expression) > 0:
                    assign_expression = assign_expression[0]
                    make = 0 if "'" in assign_expression[
                        2] and '"' in assign_expression[2] else 1
                    if make and ',' not in assign_expression[
                            2] and ';' not in assign_expression[
                                2] and '#' not in assign_expression[2]:
                        if assign_expression[1] == "=":
                            #print assign_expression
                            res += Utils.low_up_string(
                                " Assign('") + assign_expression[0][
                                    1:] + "'," + assign_expression[2] + ")\n"
                            obj[i] = res
    return obj
Exemplo n.º 22
0
def block_if(deep_act,n_statements_min=10,n_statements_max=20,n_guard_statements_min=1,n_guard_statements_max=5,n_else_if_min=1,n_else_if_max=5,deep_max=5,case_values_min=-1000,case_values_max=1000): 
    res = Utils.low_up_string("If ")
    declarations = ""
    n_guard_statements = randint(min(n_guard_statements_min,n_guard_statements_max),max(n_guard_statements_min,n_guard_statements_max))
    log_statements = logical_statements(n_guard_statements) + Utils.low_up_string(" Then")+"\n"
    logic_variables = ExtractKeywords.extract_variables(log_statements)
    for i in logic_variables: declarations += Utils.generate_random_declarator()+assign_by_var_name(i)+"\n"
    res += log_statements
    res += block(deep_act+1,n_statements_min,n_statements_max,n_guard_statements_min,n_guard_statements_max,n_else_if_min,n_else_if_max,deep_max,case_values_min,case_values_max)+"\n"
    else_type = randint(0,1) # 0 -> Else if, 1 -> Else #
    if else_type==0: 
	n_else_if = randint(min(n_else_if_min,n_else_if_max),max(n_else_if_min,n_else_if_max))
	for i in xrange(n_else_if):	    
	    log_statements = logical_statements(randint(min(n_guard_statements_min,n_guard_statements_max),max(n_guard_statements_min,n_guard_statements_max)))
	    logic_variables = ExtractKeywords.extract_variables(log_statements)
	    for i in logic_variables: declarations += Utils.generate_random_declarator()+assign_by_var_name(i)+"\n"
	    res += Utils.low_up_string("ElseIf ")+log_statements+Utils.low_up_string(" Then\n")+block(deep_act+1,n_statements_min,n_statements_max,n_guard_statements_min,n_guard_statements_max,n_else_if_min,n_else_if_max,deep_max,case_values_min,case_values_max)+"\n"
    res += Utils.low_up_string("Else ")+"\n"+block(deep_act+1,n_statements_min,n_statements_max,n_guard_statements_min,n_guard_statements_max,n_else_if_min,n_else_if_max,deep_max,case_values_min,case_values_max)+"\n"
    res += Utils.low_up_string("EndIf")+"\n"
    return declarations+res
Exemplo n.º 23
0
def logical_operation(): return choice([Utils.low_up_string("And"),Utils.low_up_string("Or")])

def logical_statement(spaces_min=1,spaces_max=5): return variable()+" "+relational_operation()+" "+value() # Facilita las cosas un formato estándar #
Exemplo n.º 24
0
def assign(var,val):
    rnd = randint(0,1)
    if rnd==0: return Utils.generate_random_declarator()+var+" = "+val+"\n"
    else:      return Utils.generate_random_declarator()+var+" = 0\n"+Utils.low_up_string("Assign")+"('"+var+"','"+val.replace('"',"").replace("'","")+"')\n"
Exemplo n.º 25
0
def logical_operation():
    return choice([Utils.low_up_string("And"), Utils.low_up_string("Or")])
Exemplo n.º 26
0
def hide_expressions_with_execute(obj):
    for i in xrange(len(obj)):
        obj[i] = obj[i].strip()
        aux = obj[i].lower()
        prob_execute = 0.75
        res = ""
        if len(obj[i]) > 0 and obj[i][-1] != "_" and aux.find(
                "execute(") == -1 and aux.find("eval(") == -1 and aux.find(
                    "assign(") == -1:
            local, dim, glbal = aux.find("local"), aux.find("dim"), aux.find(
                "global")

            if local == 0:
                res += Utils.low_up_string(" Local ")

            elif dim == 0:
                res += Utils.low_up_string(" Dim ")

            elif glbal == 0:
                res += Utils.low_up_string(" Global ")

            r = uniform(0, 1)
            if (local == 0 or dim == 0 or glbal == 0
                    or obj[i][0] == "$") and r <= prob_execute:
                assign_expression = ex.extract_assign_expressions(obj[i])
                if len(assign_expression) > 0:
                    assign_expression = assign_expression[0]
                    make = 0 if "'" in assign_expression[
                        2] and '"' in assign_expression[2] else 1
                    if make and "," not in assign_expression[
                            2] and ',' not in assign_expression[
                                2] and ';' not in assign_expression[
                                    2] and '#' not in assign_expression[
                                        2]:  # Evitar definiciones multiples #
                        if assign_expression[1] == "=":
                            quote = repr(assign_expression[2])[0]
                            res += assign_expression[0] + Utils.low_up_string(
                                " = Execute("
                            ) + quote + assign_expression[2] + quote + ") \n"
                            obj[i] = res
                        elif assign_expression[1] == "+=":
                            quote = repr(assign_expression[2])[0]
                            res += assign_expression[0] + Utils.low_up_string(
                                " = Execute(") + quote + assign_expression[
                                    0] + " + " + assign_expression[
                                        2] + quote + ")\n"
                            obj[i] = res
                        elif assign_expression[1] == "-=":
                            quote = repr(assign_expression[2])[0]
                            res += assign_expression[0] + Utils.low_up_string(
                                " = Execute(") + quote + assign_expression[
                                    0] + " - " + assign_expression[
                                        2] + quote + ")\n"
                            obj[i] = res
                        elif assign_expression[1] == "*=":
                            quote = repr(assign_expression[2])[0]
                            res += assign_expression[0] + Utils.low_up_string(
                                " = Execute(") + quote + assign_expression[
                                    0] + " * " + assign_expression[
                                        2] + quote + ")\n"
                            obj[i] = res
                        elif assign_expression[1] == "/=":
                            quote = repr(assign_expression[2])[0]
                            res += assign_expression[0] + Utils.low_up_string(
                                " = Execute(") + quote + assign_expression[
                                    0] + " / " + assign_expression[
                                        2] + quote + ")\n"
                            obj[i] = res
                        elif assign_expression[1] == "&=":
                            quote = repr(assign_expression[2])[0]
                            res += assign_expression[0] + Utils.low_up_string(
                                " = Execute(") + quote + assign_expression[
                                    0] + " & " + assign_expression[
                                        2] + quote + ")\n"
                            obj[i] = res

    return obj