Skip to content

Commit

Permalink
Merge pull request #198 from Typee-Language/#77-Syntaxic-Intermediate…
Browse files Browse the repository at this point in the history
…-Code-implementation

#77 syntaxic intermediate code implementation
  • Loading branch information
schmouk authored Feb 14, 2019
2 parents d2157eb + 5007478 commit b1cd08e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/FrontEnd/IntermediateCode/fe_icblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class FEICBlock( FEICNode ):
def __init__(self, parent:FEICNode=None):
'''
Constructor.
'''
super().__init__( [] ) ## content is an empty list (of FEICNode-s)
self.parent = parent
Expand Down
7 changes: 7 additions & 0 deletions src/FrontEnd/IntermediateCode/fe_icleaf.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ def __init__(self, content):
content: a reference to the content opf this leaf
'''
super().__init__( content )

#-------------------------------------------------------------------------
def set_parent(self, parent:FEICNode):
'''
Sets the parent of this node.
'''
pass

#-------------------------------------------------------------------------
def __iter__(self):
Expand Down
7 changes: 7 additions & 0 deletions src/FrontEnd/IntermediateCode/fe_icnode.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ def __init__(self, content=None):
'''
self.content = content

#-------------------------------------------------------------------------
def set_parent(self, parent:FEICNode):
'''
Sets the parent of this node.
'''
self.parent = parent

#-------------------------------------------------------------------------
def walk(self):
'''
Expand Down
43 changes: 39 additions & 4 deletions src/FrontEnd/IntermediateCode/fe_ictree.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,46 @@

#=============================================================================
from FrontEnd.IntermediateCode.fe_icblock import FEICBlock
from FrontEnd.IntermediateCode.fe_icnode import FEICNode


#=============================================================================
FEICTree = FEICBlock
"""
The class of Intermediate Code Trees.
"""
class FEICTree:
"""
The class of Intermediate Code trees.
"""

#-------------------------------------------------------------------------
def __init__(self):
'''
Constructor.
'''
self._root = FEICBlock()
self._current = self._root

#-------------------------------------------------------------------------
def __iadd__(self, ic_node:(FEICBlock,FEICNode)):
'''
Appends a new node into this block.
'''
ic_node.set_parent( self._current )
self._current += ic_node
if isinstance( ic_node, FEICBlock ):
self._current = ic_node

#-------------------------------------------------------------------------
def up(self):
'''
Goes back to parent block in IC Tree.
'''
self._current = self._current.parent

#-------------------------------------------------------------------------
def walk(self):
'''
Walks through this Intermediate Code tree.
Walk-through is depth-first implemented.
'''
self._root.walk()

#===== end of FrontEnd.IntermediateCode.fe_ictree =====#

0 comments on commit b1cd08e

Please sign in to comment.