-
Notifications
You must be signed in to change notification settings - Fork 0
/
PythonNode.py
36 lines (29 loc) · 869 Bytes
/
PythonNode.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
# PythonNode.py
from TreeNode import TreeNode
from PLLParser import parsePLL
class PythonNode(TreeNode):
def __init__(self, label, lHereDoc=None):
TreeNode.__init__(self, label, lHereDoc)
def append(self, text):
(node, hSubTrees) = parsePLL(text, PythonNode)
self.appendNode(node)
return self # allow chaining
def appendChild(self, text):
(node, hSubTrees) = parsePLL(text, PythonNode)
self.appendChildNode(node)
return self # allow chaining
def execute(self, hGlobals=None, hLocals=None, debug=False):
programText = self.asString()
if debug:
self.printProgram(programText)
exec(programText, hGlobals, hLocals)
return programText
def printProgram(self, text=None):
if not text:
text = self.asString()
print()
print('='*48)
print('-'*15 + ' Python Program ' + '-'*15)
print('='*48)
print(text)
print('='*48)