Logo Search packages:      
Sourcecode: relational version File versions  Download package

def relational::parser::node::__init__ (   self,
  expression = None 
)

Generates the tree from the tokenized expression
If no expression is specified then it will create an empty node

Definition at line 44 of file parser.py.

00044                                       :
        '''Generates the tree from the tokenized expression
        If no expression is specified then it will create an empty node'''
        if expression==None or len(expression)==0:
            return
        
        #If the list contains only a list, it will consider the lower level list.
        #This will allow things like ((((((a))))) to work
        while len(expression)==1 and isinstance(expression[0],list): 
                expression=expression[0]
        
        #The list contains only 1 string. Means it is the name of a relation
        if len(expression)==1 and isinstance(expression[0],str): 
            self.kind=RELATION
            self.name=expression[0]
            return
            
        '''Expression from right to left, searching for binary operators
        this means that binary operators have lesser priority than
        unary operators.
        It find the operator with lesser priority, uses it as root of this
        (sub)tree using everything on its left as left parameter (so building
        a left subtree with the part of the list located on left) and doing 
        the same on right.
        Since it searches for strings, and expressions into parenthesis are
        within sub-lists, they won't be found here, ensuring that they will
        have highest priority.'''
        for i in range(len(expression)-1,-1,-1): 
            if expression[i] in b_operators: #Binary operator              
                self.kind=BINARY
                self.name=expression[i]
                self.left=node(expression[:i]) 
                self.right=node(expression[i+1:])
                return
        '''Searches for unary operators, parsing from right to left'''
        for i in range(len(expression)-1,-1,-1):
            if expression[i] in u_operators: #Unary operator
                self.kind=UNARY
                self.name=expression[i]
                self.prop=expression[1+i].strip()
                self.child=node(expression[2+i])
                
                return       
        pass
    def toPython(self):


Generated by  Doxygen 1.6.0   Back to index