Skip to content
Snippets Groups Projects

Chloe environment building

Merged Pui Yan Chloe Sham requested to merge chloe-environmentBuilding into master
5 files
+ 97
39
Compare changes
  • Side-by-side
  • Inline
Files
5
+ 16
0
@@ -11,6 +11,7 @@ class ASTNode():
@@ -11,6 +11,7 @@ class ASTNode():
# but we will keep it for easier debugging, since effeciency is not a concern here
# but we will keep it for easier debugging, since effeciency is not a concern here
def __init__(self, parseTree):
def __init__(self, parseTree):
self.parseTree = parseTree
self.parseTree = parseTree
 
self.children = []
# Do certains actions on every node of the AST tree
# Do certains actions on every node of the AST tree
# call the same method in each class and its children recursively
# call the same method in each class and its children recursively
@@ -27,6 +28,21 @@ class ASTNode():
@@ -27,6 +28,21 @@ class ASTNode():
if hasattr(c, 'recurseAction'):
if hasattr(c, 'recurseAction'):
c.recurseAction(actionName, result)
c.recurseAction(actionName, result)
 
# This is a function to recursively build environment
 
# Modified from the function recurseAction above, to handle the proper linking of local variable environments
 
def recurseBuildEnv(self, parentEnv):
 
result = self.buildEnv(parentEnv)
 
preVarDcl = None
 
for c in self.children:
 
if c and hasattr(c, 'recurseBuildEnv'):
 
if preVarDcl:
 
c.recurseBuildEnv(preVarDcl.env)
 
else:
 
c.recurseBuildEnv(result)
 
if c.__class__.__name__ == 'VarDclNode':
 
preVarDcl = c
 
 
def buildEnv(self, parentEnv):
def buildEnv(self, parentEnv):
self.env = parentEnv
self.env = parentEnv
return parentEnv
return parentEnv
Loading