Skip to content

Commit

Permalink
#274-Intermediate Code - Abstract Syntaxic Tree
Browse files Browse the repository at this point in the history
Started coding some stuff, finally to be replaced later.
  • Loading branch information
schmouk committed Jun 21, 2020
1 parent 9b0c48e commit e3c67ba
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Commons/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(self) -> None:
self.append( self._DEFAULT )

#-------------------------------------------------------------------------
def add_level(self, access_qualif: Access = None):
def add_level(self, access_qualif: Access = None) -> None:
self._current_level += 1
try:
self[ self._current_level ] = access_qualif or self._DEFAULT
Expand Down
8 changes: 4 additions & 4 deletions src/IntermediateCode/ic_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ class ICAst( UTTree ):
"""
The class of Abstract Syntaxic Trees.
Those trees are created by the Front-End Parser.
They are used by the Front-End Elaborator, when elaborating symbols
and types for instance.
They are used also by the types checker.
FInally, they are used by the Back-End Programming-Language Translators.
They are used by the Front-End Elaborator, when elaborating symbols and
types for instance.
They are used also by the types checker - i.e. the Elaborator.
Finally, they are used by the Back-End Programming-Language Translators.
"""
#-------------------------------------------------------------------------
def __init__(self) -> None:
Expand Down
12 changes: 11 additions & 1 deletion src/Utils/Trees/ut_tree_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,26 @@ def __init__(self, parent: UTTreeNodeBase = None, children: list = None) -> None
'''
super().__init__( parent, children or [] )

#-------------------------------------------------------------------------
def __add__(self, new_child: UTTreeNodeBase) -> UTTreeNodeBase:
'''
Appends a new child to the list of children of this tree node.
Implementation of operator '+'.
'''
self.content.append( new_child )
return self

#-------------------------------------------------------------------------
def __iadd__(self, new_child: UTTreeNodeBase) -> UTTreeNodeBase:
'''
Appends a new child to the list of children of this tree node.
Implementation of operator '+='.
'''
self.content.append( new_child )
return self

#-------------------------------------------------------------------------
def walk(self):
def walk(self) -> UTTreeNodeBase:
'''
Walks through the tree passing through this node.
Walk-through is depth-first implemented.
Expand Down
7 changes: 6 additions & 1 deletion src/Utils/Trees/ut_tree_node_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ def __init__(self, parent=None, content=None) -> None:
A reference to the content to be associated with this tree node.
'''
self.parent = parent
self.content = content
if content is None:
self.content = []
elif isinstance( content, list ):
self.content = content
else:
self.content = [ content ]

#-------------------------------------------------------------------------
def walk(self) -> None:
Expand Down

0 comments on commit e3c67ba

Please sign in to comment.