-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathobjgen.py
43 lines (31 loc) · 1.47 KB
/
objgen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from Objects.varObject import VariableObject
from Objects.conditionObject import ConditionObject
from Objects.builtinObject import BuiltInFunctionObject
from Objects.commentObject import CommentObject
from Objects.loopObject import LoopObject
class ObjectGenerator():
def __init__(self, source_ast):
self.source_ast = source_ast['main_scope']
self.exec_string = ""
def object_definer(self, isGettingBody):
for ast in self.source_ast:
if self.check_ast('VariableDecleration', ast):
gen_var = VariableObject(ast)
self.exec_string += gen_var.transpile() + '\n'
if self.check_ast('ConditionalStatement', ast):
gen_condition = ConditionObject(ast, 1)
self.exec_string += gen_condition.transpile() + '\n'
if self.check_ast('PrebuiltFunction', ast):
gen_builtin = BuiltInFunctionObject(ast)
self.exec_string += gen_builtin.transpile() + "\n"
if self.check_ast('Comment', ast):
gen_comment = CommentObject(ast)
self.exec_string += gen_comment.transpile() + "\n"
if self.check_ast('ForLoop', ast):
gen_loop = LoopObject(ast, 1)
self.exec_string += gen_loop.transpile() + "\n"
return self.exec_string
def check_ast(self, astName, ast):
try:
if ast[astName]: return True
except: return False