Exemplo n.º 1
0
 def _evaluateExprTree(self, root, variableMap):
     '''
        This function evaulates the expression using expression 
        tree
        Some optimization over postfix evaluation using expression 
        tree
     '''
     if root:
         value = root.data
         if isOperand(value):
             return variableMap[value]
         left = self._evaluateExprTree(root.left, variableMap)
         if value == '!': 
              return not left
         elif value == '&' and not left:
              return False
         elif value == '|' and left:
              return True
         right = self._evaluateExprTree(root.right, variableMap)
         if value == '&':
              return left and right
         elif value == '|':
              return left or right
         return True
     return True
Exemplo n.º 2
0
 def _evaluateExprTree(self, root, variableMap):
     '''
        This function evaulates the expression using expression 
        tree
        Some optimization over postfix evaluation using expression 
        tree
     '''
     if root:
         value = root.data
         if isOperand(value):
             return variableMap[value]
         left = self._evaluateExprTree(root.left, variableMap)
         if value == '!':
             return not left
         elif value == '&' and not left:
             return False
         elif value == '|' and left:
             return True
         right = self._evaluateExprTree(root.right, variableMap)
         if value == '&':
             return left and right
         elif value == '|':
             return left or right
         return True
     return True
Exemplo n.º 3
0
 def _getVariableMap(self, statement):
     logging.debug (statement)
     variableMap = {}
     uniqueVaraibles = True
     for e in statement:
       if isOperand(e):
         if e in variableMap:
             uniqueVaraibles = False
         else:
             variableMap[e] = 0
     return (variableMap, uniqueVaraibles)
Exemplo n.º 4
0
 def _getVariableMap(self, statement):
     logging.debug(statement)
     variableMap = {}
     uniqueVaraibles = True
     for e in statement:
         if isOperand(e):
             if e in variableMap:
                 uniqueVaraibles = False
             else:
                 variableMap[e] = 0
     return (variableMap, uniqueVaraibles)