本文整理汇总了Python中Kernel.Utils.generate_random_declarator方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.generate_random_declarator方法的具体用法?Python Utils.generate_random_declarator怎么用?Python Utils.generate_random_declarator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Kernel.Utils
的用法示例。
在下文中一共展示了Utils.generate_random_declarator方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ternary_operation
# 需要导入模块: from Kernel import Utils [as 别名]
# 或者: from Kernel.Utils import generate_random_declarator [as 别名]
def ternary_operation(n_guard_statements_min=1,n_guard_statements_max=3):
res = ""
declarations = ""
var = variable()
n_guard_statements = randint(min(n_guard_statements_min,n_guard_statements_max),
min(n_guard_statements_min,n_guard_statements_max))
log_statements = logical_statements(n_guard_statements)
logic_variables = ExtractKeywords.extract_variables(log_statements)
res += Utils.generate_random_declarator()+var+"\n"
for i in logic_variables: declarations += Utils.generate_random_declarator()+assign_by_var_name(i)+"\n"
res += var+" = (" + log_statements + ") ? " + value() + " : " + value()
return declarations+res+"\n"
示例2: block_while
# 需要导入模块: from Kernel import Utils [as 别名]
# 或者: from Kernel.Utils import generate_random_declarator [as 别名]
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
示例3: block_with
# 需要导入模块: from Kernel import Utils [as 别名]
# 或者: from Kernel.Utils import generate_random_declarator [as 别名]
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
示例4: block_if
# 需要导入模块: from Kernel import Utils [as 别名]
# 或者: from Kernel.Utils import generate_random_declarator [as 别名]
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
示例5: block_switch
# 需要导入模块: from Kernel import Utils [as 别名]
# 或者: from Kernel.Utils import generate_random_declarator [as 别名]
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
示例6: block_for
# 需要导入模块: from Kernel import Utils [as 别名]
# 或者: from Kernel.Utils import generate_random_declarator [as 别名]
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
示例7: add_hardcoded_funcs
# 需要导入模块: from Kernel import Utils [as 别名]
# 或者: from Kernel.Utils import generate_random_declarator [as 别名]
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
示例8: assign
# 需要导入模块: from Kernel import Utils [as 别名]
# 或者: from Kernel.Utils import generate_random_declarator [as 别名]
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"