def visit_ifnode(self, ifNode: IfNode):
     children = [self.resolveParent(ifNode, ifNode.condition.accept(self))]
     expression = self.expressions[ifNode.id]
     if getTypeOfExpression(
             expression["$type"]) != Utils.COMPOSITE_EXPRESSION:
         expression = self.resolve_name_expr(expression, False)
         if not expression["Token"] in self.rowExpressionValues:
             isConditionTrue = None
         else:
             isConditionTrue = self.rowExpressionValues[expression["Token"]]
     else:
         expression = self.resolve_name_expr(expression, False)
         conditionSolver = ConditionSolverVisitor(expression,
                                                  self.rowExpressionValues,
                                                  self.expressions)
         isConditionTrue = conditionSolver.retrieveValueOfCondition()
     if isConditionTrue == True:
         children.append(
             self.resolveParent(ifNode, ifNode.nodeThen.accept(self)))
     elif isConditionTrue is None:
         children.append(
             self.resolveParent(ifNode, ifNode.nodeThen.accept(self)))
         if ifNode.nodeElse is not None:
             children.append(
                 self.resolveParent(ifNode, ifNode.nodeElse.accept(self)))
     else:
         if ifNode.nodeElse is not None:
             children.append(
                 self.resolveParent(ifNode, ifNode.nodeElse.accept(self)))
     return {
         'node': self.get_name(ifNode),
         'parent': None,
         'children': children
     }
 def visit_forloop(self, forLoop: ForLoop):
     children = []
     children.append(
         self.resolveParent(forLoop, forLoop.condition.accept(self)))
     children.append(
         self.resolveParent(forLoop,
                            forLoop.nodeInit.condition.accept(self)))
     expression = self.expressions[forLoop.id]
     if getTypeOfExpression(
             expression["$type"]) != Utils.COMPOSITE_EXPRESSION:
         expression = self.resolve_name_expr(expression, False)
         if not expression["Token"] in self.rowExpressionValues:
             isConditionTrue = None
         else:
             isConditionTrue = self.rowExpressionValues[expression["Token"]]
     else:
         expression = self.resolve_name_expr(expression, False)
         conditionSolver = ConditionSolverVisitor(expression,
                                                  self.rowExpressionValues,
                                                  self.expressions)
         isConditionTrue = conditionSolver.retrieveValueOfCondition()
     if isConditionTrue or isConditionTrue is None:
         children.append(
             self.resolveParent(forLoop, forLoop.nodeAfter.accept(self)))
         children.append(
             self.resolveParent(forLoop, forLoop.nodeBlock.accept(self)))
     return {
         'node': self.get_name(forLoop),
         'parent': None,
         'children': children
     }
Example #3
0
 def retrieveExpressions(self, values, expressions):
     for expression in values:
         if getTypeOfExpression(expression["$type"]) == Utils.COMPOSITE_EXPRESSION:
             self.retrieveExpressions(expression["Children"]["$values"], expressions)
         else:
             expressions.append(expression["Token"])
     return expressions
Example #4
0
 def visit_ifnode(self, ifNode: IfNode):
     children = [ifNode.condition]
     expression = self.expressions[ifNode.id]
     if getTypeOfExpression(
             expression["$type"]) != Utils.COMPOSITE_EXPRESSION:
         expression = self.resolve_name_expr(expression, False)
         if not expression["Token"] in self.rowExpressionValues:
             isConditionTrue = None
         else:
             isConditionTrue = self.rowExpressionValues[expression["Token"]]
     else:
         expression = self.resolve_name_expr(expression, False)
         conditionSolver = ConditionSolverVisitor(expression,
                                                  self.rowExpressionValues,
                                                  self.expressions)
         isConditionTrue = conditionSolver.retrieveValueOfCondition()
     if isConditionTrue == True:
         children.append(ifNode.nodeThen)
     elif isConditionTrue is None:
         children.append(ifNode.nodeThen)
         children.append(ifNode.nodeElse)
     else:
         if ifNode.nodeElse is not None:
             children.append(ifNode.nodeElse)
     return children
Example #5
0
 def visit_loop(self, loopNode: LoopNode):
     expression = self.expressions[loopNode.id]
     if getTypeOfExpression(
             expression["$type"]) != Utils.COMPOSITE_EXPRESSION:
         isConditionTrue = self.rowExpressionValues[expression["Token"]]
     else:
         conditionSolver = ConditionSolverVisitor(expression,
                                                  self.rowExpressionValues,
                                                  self.expressions)
         isConditionTrue = conditionSolver.retrieveValueOfCondition()
     loopNode.condition.accept(self)
     if isConditionTrue:
         loopNode.nodeBlock.accept(self)
     else:
         pass
Example #6
0
 def visit_forloop(self, forLoop: ForLoop):
     expression = self.expressions[forLoop.id]
     if getTypeOfExpression(expression["$type"]) != Utils.COMPOSITE_EXPRESSION:
         isConditionTrue = self.rowExpressionValues[expression["Token"]]
     else:
         conditionSolver = ConditionSolverVisitor(expression,
                                                  self.rowExpressionValues,
                                                  self.expressions)
         isConditionTrue = conditionSolver.retrieveValueOfCondition()
     if isConditionTrue:
         self.embedding = self.embedding + loop_embedding
         resultVectors = forLoop.return_vector(self)
         self.embedding = self.embedding - loop_embedding
         return resultVectors
     else:
         return []
Example #7
0
 def visit_forloop(self, forLoop: ForLoop):
     expression = self.expressions[forLoop.id]
     if getTypeOfExpression(
             expression["$type"]) != Utils.COMPOSITE_EXPRESSION:
         isConditionTrue = self.rowExpressionValues[expression["Token"]]
     else:
         conditionSolver = ConditionSolverVisitor(expression,
                                                  self.rowExpressionValues,
                                                  self.expressions)
         isConditionTrue = conditionSolver.retrieveValueOfCondition()
     forLoop.nodeInit.accept(self)
     forLoop.condition.accept(self)
     if isConditionTrue:
         forLoop.nodeBlock.accept(self)
         forLoop.nodeAfter.accept(self)
     else:
         pass
Example #8
0
    def visit_ifnode(self, ifNode: IfNode):
        expression = self.expressions[ifNode.id]

        if getTypeOfExpression(
                expression["$type"]) != Utils.COMPOSITE_EXPRESSION:
            isConditionTrue = self.rowExpressionValues[expression["Token"]]
        else:
            conditionSolver = ConditionSolverVisitor(expression,
                                                     self.rowExpressionValues,
                                                     self.expressions)
            isConditionTrue = conditionSolver.retrieveValueOfCondition()
        ifNode.condition.accept(self)
        if isConditionTrue:
            ifNode.nodeThen.accept(self)
        else:
            if ifNode.nodeElse is not None:
                ifNode.nodeElse.accept(self)
Example #9
0
 def visit_ifnode(self, ifNode: IfNode):
     list = []
     expression = self.expressions[ifNode.id]
     if getTypeOfExpression(expression["$type"]) != Utils.COMPOSITE_EXPRESSION:
         isConditionTrue = self.rowExpressionValues[expression["Token"]]
     else:
         conditionSolver = ConditionSolverVisitor(expression,
                                                  self.rowExpressionValues,
                                                  self.expressions)
         isConditionTrue = conditionSolver.retrieveValueOfCondition()
     list = list + ifNode.return_vector(self)
     self.embedding = self.embedding + if_embedding
     if isConditionTrue:
         list = list + ifNode.nodeThen.accept(self)
     else:
         if ifNode.nodeElse is not None:
             list = list + ifNode.nodeElse.accept(self)
     self.embedding = self.embedding + if_embedding
     return list
Example #10
0
 def visit_forloop(self, forLoop: ForLoop):
     expression = self.expressions[forLoop.id]
     children = [forLoop.nodeInit, forLoop.condition]
     if getTypeOfExpression(
             expression["$type"]) != Utils.COMPOSITE_EXPRESSION:
         expression = self.resolve_name_expr(expression, False)
         if not expression["Token"] in self.rowExpressionValues:
             isConditionTrue = None
         else:
             isConditionTrue = self.rowExpressionValues[expression["Token"]]
     else:
         expression = self.resolve_name_expr(expression, False)
         conditionSolver = ConditionSolverVisitor(expression,
                                                  self.rowExpressionValues,
                                                  self.expressions)
         isConditionTrue = conditionSolver.retrieveValueOfCondition()
     if isConditionTrue or isConditionTrue is None:
         children.append(forLoop.nodeAfter)
         children.append(forLoop.nodeBlock)
     #children.append(forLoop.nodeBlock)
     return children
 def resolve_name_expr(self, expression, flag):
     tokenirino = expression["Token"]
     if getTypeOfExpression(
             expression["$type"]) != Utils.COMPOSITE_EXPRESSION:
         expression["Token"] = self.retrieve_new_token(tokenirino, flag)
         return expression
     else:
         tmpDict = {}
         tmpToken = tokenirino.replace("And", "~")
         tmpToken = tmpToken.replace("Or", "~")
         tokens = tmpToken.split("~")
         for token in tokens:
             if token[-1:] == ' ':
                 token = token[:-1]
             if token[0] == ' ':
                 token = token[1:]
             new_token = self.retrieve_new_token(token, flag)
             tmpDict[token] = new_token
         for key in tmpDict.keys():
             tokenirino = tokenirino.replace(key, tmpDict[key])
         expression["Token"] = tokenirino
         return expression
Example #12
0
 def visit_loop(self, loopNode: LoopNode):
     expression = self.expressions[loopNode.id]
     if getTypeOfExpression(
             expression["$type"]) != Utils.COMPOSITE_EXPRESSION:
         expression = self.resolve_name_expr(expression, False)
         if not expression["Token"] in self.rowExpressionValues:
             isConditionTrue = None
         else:
             isConditionTrue = self.rowExpressionValues[expression["Token"]]
     else:
         expression = self.resolve_name_expr(expression, False)
         conditionSolver = ConditionSolverVisitor(expression,
                                                  self.rowExpressionValues,
                                                  self.expressions)
         isConditionTrue = conditionSolver.retrieveValueOfCondition()
     if isConditionTrue:
         children = [loopNode.condition, loopNode.nodeBlock]
     elif isConditionTrue is None:
         children = [loopNode.condition, loopNode.nodeBlock]
     else:
         children = [loopNode.condition]
     return children
 def resolve_expression(self, node):
     if node.id not in self.expressions:
         return 'None'
     expression = self.expressions[node.id]
     if getTypeOfExpression(
             expression["$type"]) != Utils.COMPOSITE_EXPRESSION:
         expression = self.resolve_name_expr(expression, True)
         if not expression["Token"] in self.rowExpressionValues:
             isConditionTrue = None
         else:
             isConditionTrue = self.rowExpressionValues[expression["Token"]]
     else:
         expression = self.resolve_name_expr(expression, True)
         conditionSolver = ConditionSolverVisitor(expression,
                                                  self.rowExpressionValues,
                                                  self.expressions)
         isConditionTrue = conditionSolver.retrieveValueOfCondition()
     if isConditionTrue:
         return str(1)
     elif isConditionTrue is None:
         return str(None)
     else:
         return str(0)