From deda0fc4681a4d05161bede9cb5bc190b941a8a5 Mon Sep 17 00:00:00 2001 From: Schmouk Date: Thu, 14 Feb 2019 14:58:00 +0100 Subject: [PATCH 1/2] #77-Syntaxic Intermediate Code implementation Augmented doucmentation comment in module `fe_ictree.py`. --- src/FrontEnd/IntermediateCode/fe_ictree.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/FrontEnd/IntermediateCode/fe_ictree.py b/src/FrontEnd/IntermediateCode/fe_ictree.py index ac370b8..591720c 100644 --- a/src/FrontEnd/IntermediateCode/fe_ictree.py +++ b/src/FrontEnd/IntermediateCode/fe_ictree.py @@ -30,5 +30,7 @@ FEICTree = FEICBlock """ The class of Intermediate Code Trees. +Well, Intermediate Code trees are only defined by their `root`. """ + #===== end of FrontEnd.IntermediateCode.fe_ictree =====# From 7f3d83fc95e1924c30e4fb424e31c3d9d1ad4ae5 Mon Sep 17 00:00:00 2001 From: Schmouk Date: Thu, 14 Feb 2019 15:56:52 +0100 Subject: [PATCH 2/2] #77-Syntaxic Intermediate Code implementation Corrected module `FrontEnd/IntermediateCode/fe_ictree.py`. --- src/FrontEnd/IntermediateCode/fe_icblock.py | 1 - src/FrontEnd/IntermediateCode/fe_icleaf.py | 7 ++++ src/FrontEnd/IntermediateCode/fe_icnode.py | 9 ++++- src/FrontEnd/IntermediateCode/fe_ictree.py | 43 ++++++++++++++++++--- 4 files changed, 53 insertions(+), 7 deletions(-) diff --git a/src/FrontEnd/IntermediateCode/fe_icblock.py b/src/FrontEnd/IntermediateCode/fe_icblock.py index 5d7f5c7..9f8c282 100644 --- a/src/FrontEnd/IntermediateCode/fe_icblock.py +++ b/src/FrontEnd/IntermediateCode/fe_icblock.py @@ -31,7 +31,6 @@ class FEICBlock( FEICNode ): def __init__(self, parent:FEICNode=None): ''' Constructor. - ''' super().__init__( [] ) ## content is an empty list (of FEICNode-s) self.parent = parent diff --git a/src/FrontEnd/IntermediateCode/fe_icleaf.py b/src/FrontEnd/IntermediateCode/fe_icleaf.py index 3dce388..fa1303a 100644 --- a/src/FrontEnd/IntermediateCode/fe_icleaf.py +++ b/src/FrontEnd/IntermediateCode/fe_icleaf.py @@ -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 walk(self) -> FEICNode: diff --git a/src/FrontEnd/IntermediateCode/fe_icnode.py b/src/FrontEnd/IntermediateCode/fe_icnode.py index 2daa75b..49e95e1 100644 --- a/src/FrontEnd/IntermediateCode/fe_icnode.py +++ b/src/FrontEnd/IntermediateCode/fe_icnode.py @@ -40,7 +40,14 @@ def __init__(self, content=None): self.content = content #------------------------------------------------------------------------- - def walk(self) -> FEICNodeI: + def set_parent(self, parent:FEICNode): + ''' + Sets the parent of this node. + ''' + self.parent = parent + + #------------------------------------------------------------------------- + def walk(self) -> FEICNode: ''' Walks through the list of nodes contained within this block. Walk-through is depth-first implemented. diff --git a/src/FrontEnd/IntermediateCode/fe_ictree.py b/src/FrontEnd/IntermediateCode/fe_ictree.py index 591720c..1583dda 100644 --- a/src/FrontEnd/IntermediateCode/fe_ictree.py +++ b/src/FrontEnd/IntermediateCode/fe_ictree.py @@ -24,13 +24,46 @@ #============================================================================= from FrontEnd.IntermediateCode.fe_icblock import FEICBlock +from FrontEnd.IntermediateCode.fe_icnode import FEICNode #============================================================================= -FEICTree = FEICBlock -""" -The class of Intermediate Code Trees. -Well, Intermediate Code trees are only defined by their `root`. -""" +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 =====#