Added correct comparisons and implemented all basic types
Took 27 minutes
This commit is contained in:
parent
09010a4789
commit
4d8609c38e
|
@ -332,6 +332,11 @@ class AstGenerator:
|
||||||
self.generate_unary(op, random.choice(expr_type))
|
self.generate_unary(op, random.choice(expr_type))
|
||||||
elif op == GAZ_BRACKET_TAG:
|
elif op == GAZ_BRACKET_TAG:
|
||||||
self.generate_bracket(random.choice(expr_type))
|
self.generate_bracket(random.choice(expr_type))
|
||||||
|
elif comparison:
|
||||||
|
if op in ['equality', 'inequality']:
|
||||||
|
self.generate_binary(op, random.choice([GAZ_INT_KEY, GAZ_FLOAT_KEY, GAZ_CHAR_KEY]))
|
||||||
|
else:
|
||||||
|
self.generate_binary(op, random.choice([GAZ_INT_KEY, GAZ_FLOAT_KEY]))
|
||||||
else:
|
else:
|
||||||
self.generate_binary(op, random.choice(expr_type))
|
self.generate_binary(op, random.choice(expr_type))
|
||||||
|
|
||||||
|
@ -532,7 +537,12 @@ class AstGenerator:
|
||||||
if expr_type == GAZ_INT_KEY or expr_type == GAZ_FLOAT_KEY:
|
if expr_type == GAZ_INT_KEY or expr_type == GAZ_FLOAT_KEY:
|
||||||
self.generate_int_expr()
|
self.generate_int_expr()
|
||||||
elif expr_type == GAZ_BOOL_KEY:
|
elif expr_type == GAZ_BOOL_KEY:
|
||||||
self.generate_bool_expr()
|
if random.random() < 0.5:
|
||||||
|
self.generate_bool_expr()
|
||||||
|
else:
|
||||||
|
self.generate_comp_expr()
|
||||||
|
elif expr_type == GAZ_CHAR_KEY:
|
||||||
|
self.generate_char_expr()
|
||||||
elif expr_type == ANY_TYPE: # TODO implement the choice of any type
|
elif expr_type == ANY_TYPE: # TODO implement the choice of any type
|
||||||
self.generate_int_expr()
|
self.generate_int_expr()
|
||||||
else:
|
else:
|
||||||
|
@ -603,6 +613,8 @@ class AstGenerator:
|
||||||
return random.uniform(-1000, 1000)
|
return random.uniform(-1000, 1000)
|
||||||
elif type == GAZ_BOOL_KEY:
|
elif type == GAZ_BOOL_KEY:
|
||||||
return random.choice([True, False])
|
return random.choice([True, False])
|
||||||
|
elif type == GAZ_CHAR_KEY:
|
||||||
|
return "'" + random.choice(string.ascii_letters) + "'"
|
||||||
else:
|
else:
|
||||||
raise TypeError("Unimplemented generator for type: " + type)
|
raise TypeError("Unimplemented generator for type: " + type)
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ def to_gaz_value(val):
|
||||||
def to_gaz_op(param):
|
def to_gaz_op(param):
|
||||||
if param == "negation" or param == "subtraction":
|
if param == "negation" or param == "subtraction":
|
||||||
return "-"
|
return "-"
|
||||||
elif param == "addition":
|
elif param == "addition" or param == "noop":
|
||||||
return "+"
|
return "+"
|
||||||
elif param == "multiplication":
|
elif param == "multiplication":
|
||||||
return "*"
|
return "*"
|
||||||
|
|
|
@ -5,6 +5,7 @@ generation-options:
|
||||||
max-conditionals-loops: 5 # maximum number of loops/conditionals per routine
|
max-conditionals-loops: 5 # maximum number of loops/conditionals per routine
|
||||||
max-number-of-routines: 5 # maximum number of routines (main will always be generated)
|
max-number-of-routines: 5 # maximum number of routines (main will always be generated)
|
||||||
generate-dead-code: True # generate dead code
|
generate-dead-code: True # generate dead code
|
||||||
|
max-loop-iterations: 100 # maximum number of iterations in a loop
|
||||||
properties:
|
properties:
|
||||||
max-range-length: 5 # maximum length of ranges, vectors and tuples, (AxA matrices can exist)
|
max-range-length: 5 # maximum length of ranges, vectors and tuples, (AxA matrices can exist)
|
||||||
use-english-words: True # use english words instead of random names (this may limit the maximum number of names)
|
use-english-words: True # use english words instead of random names (this may limit the maximum number of names)
|
||||||
|
|
Loading…
Reference in a new issue