I have an expression as follow: ( root (AA ( CC) (DD) ) (BB (CC) (DD) ) )
I want to parse this expression using recursion and I created a tree class but I'm stuck after this man.
This looks this the following tree.
root
|
____________
AA BB
| |
__________ ___________
CC DD CC DD
The output should look like this:
Root -> AA BB
AA -> CC DD
BB -> CC DD
My tree class look like the following:
class tree_parsing(object):
def __init__(self, element=None):
self.element = element
self.children = []
Basically I want to store the children in a list member variable of the class. Can someone help figure this problem out? Thank You.