Beispiel #1
0
def build_branches(s_exprs, method_node):
    index = 0
    branch_count = 0

    while index < len(s_exprs):
        s_expr = assert_node(s_exprs[index],
                             [s_expression.List, s_expression.Symbol])

        branch_name = 'branch_' + str(branch_count)

        if match_node(s_expr, s_expression.Symbol):
            branch_name = s_expr.text

            if index + 1 < len(s_exprs):
                index = index + 1
                s_expr = s_exprs[index]
            else:
                raise s_expression.SyntaxException(s_expr.pos)

        precondition = None
        task_list = None

        if match_node(s_expr, s_expression.List):
            if match_child(s_expr, 0, s_expression.Symbol, lex_token.FOREACH):
                precondition = assert_child(s_expr, 1, s_expression.List)
                task_list = assert_child(s_expr, 2, s_expression.List)
                index = index + 1
            else:
                if index + 1 < len(s_exprs):
                    precondition = s_expr
                    task_list = assert_node(s_exprs[index + 1],
                                            s_expression.List)
                    index = index + 2
                else:
                    raise s_expression.SyntaxException(s_expr.pos)

        if precondition != None and task_list != None:
            branch = build_branch(branch_name, precondition, task_list,
                                  method_node)
            method_node.children.append(branch)
            branch_count = branch_count + 1

            if match_child(s_expr, 0, s_expression.Symbol, lex_token.FOREACH):
                branch.foreach = True
        else:
            raise s_expression.SyntaxException(s_expr.pos)
Beispiel #2
0
def build_branches(s_exprs, method_node):
    index = 0
    branch_count = 0

    while index < len(s_exprs):
        s_expr = assert_node(s_exprs[index], [s_expression.List, s_expression.Symbol])

        branch_name = 'branch_' + str(branch_count)

        if match_node(s_expr, s_expression.Symbol):
            branch_name = s_expr.text
            
            if index + 1 < len(s_exprs):
                index = index + 1
                s_expr = s_exprs[index]
            else:
                raise s_expression.SyntaxException(s_expr.pos)

        precondition = None
        task_list = None

        if match_node(s_expr, s_expression.List):
            if match_child(s_expr, 0, s_expression.Symbol, lex_token.FOREACH):
                precondition = assert_child(s_expr, 1, s_expression.List)
                task_list = assert_child(s_expr, 2, s_expression.List)
                index = index + 1
            else:
                if index + 1 < len(s_exprs):
                    precondition = s_expr
                    task_list = assert_node(s_exprs[index + 1], s_expression.List)
                    index = index + 2
                else:
                    raise s_expression.SyntaxException(s_expr.pos)

        if precondition != None and task_list != None:
            branch = build_branch(branch_name, precondition, task_list, method_node)
            method_node.children.append(branch)
            branch_count = branch_count+1

            if match_child(s_expr, 0, s_expression.Symbol, lex_token.FOREACH):
                branch.foreach = True
        else:
            raise s_expression.SyntaxException(s_expr.pos)
Beispiel #3
0
def build(s_expr):
    node = node_type.Term()

    if match_node(s_expr, s_expression.List):
        assert_child(s_expr, 0, s_expression.Symbol,
                     [lex_token.CALL, lex_token.VAR_REF])

        if match_child(s_expr, 0, s_expression.Symbol, lex_token.CALL):
            node.term_type = node_type.TERM_CALL
            node.name = assert_child(s_expr, 1, s_expression.Symbol).text

            for child_expr in s_expr.children[2:]:
                child_node = build(child_expr)
                node.children.append(child_node)

            return node

        if match_child(s_expr, 0, s_expression.Symbol, lex_token.VAR_REF):
            node.term_type = node_type.TERM_VAR_REF
            node.name = assert_child(s_expr, 1, s_expression.Symbol).text
            return node

    if match_node(s_expr, s_expression.Number):
        node.name = s_expr.value
        node.term_type = node_type.TERM_NUMBER
        return node

    if match_node(s_expr, s_expression.Symbol):
        node.name = s_expr.text

        if lex_token.is_variable(s_expr.text):
            node.term_type = node_type.TERM_VAR
            return node

        if lex_token.is_constant(s_expr.text):
            node.term_type = node_type.TERM_CONST_REF
            return node

        node.term_type = node_type.TERM_SYMBOL
        return node
Beispiel #4
0
def build(s_expr):
    node = node_type.Term()

    if match_node(s_expr, s_expression.List):
        assert_child(s_expr, 0, s_expression.Symbol, [lex_token.CALL, lex_token.VAR_REF])

        if match_child(s_expr, 0, s_expression.Symbol, lex_token.CALL):
            node.term_type = node_type.TERM_CALL
            node.name = assert_child(s_expr, 1, s_expression.Symbol).text

            for child_expr in s_expr.children[2:]:
                child_node = build(child_expr)
                node.children.append(child_node)

            return node

        if match_child(s_expr, 0, s_expression.Symbol, lex_token.VAR_REF):
            node.term_type = node_type.TERM_VAR_REF
            node.name = assert_child(s_expr, 1, s_expression.Symbol).text
            return node

    if match_node(s_expr, s_expression.Number):
        node.name = s_expr.value
        node.term_type = node_type.TERM_NUMBER
        return node

    if match_node(s_expr, s_expression.Symbol):
        node.name = s_expr.text

        if lex_token.is_variable(s_expr.text):
            node.term_type = node_type.TERM_VAR
            return node

        if lex_token.is_constant(s_expr.text):
            node.term_type = node_type.TERM_CONST_REF
            return node

        node.term_type = node_type.TERM_SYMBOL
        return node
Beispiel #5
0
def build_branch(name, precondition_expr, tasklist_expr, method_node):
    branch = node_type.Branch()
    branch.name = lex_token.fixup_name(name)

    if match_child(precondition_expr, 0, s_expression.Symbol, lex_token.PERMUTE):
        permute_atom_expr = assert_child(precondition_expr, 1, s_expression.List)
        branch.permute_atom = build_permute_atom(permute_atom_expr)
        precondition_expr.children = precondition_expr.children[2:]

    precondition_node = logical_expression.build(precondition_expr)
    precondition_node = logical_expression.convert_to_dnf(precondition_node)
    logical_expression.classify_variables(method_node.variables, precondition_node)

    task_list_nodes = build_task_list(tasklist_expr)

    branch.children = [precondition_node] + task_list_nodes

    return branch
Beispiel #6
0
def build_branch(name, precondition_expr, tasklist_expr, method_node):
    branch = node_type.Branch()
    branch.name = lex_token.fixup_name(name)

    if match_child(precondition_expr, 0, s_expression.Symbol,
                   lex_token.PERMUTE):
        permute_atom_expr = assert_child(precondition_expr, 1,
                                         s_expression.List)
        branch.permute_atom = build_permute_atom(permute_atom_expr)
        precondition_expr.children = precondition_expr.children[2:]

    precondition_node = logical_expression.build(precondition_expr)
    precondition_node = logical_expression.convert_to_dnf(precondition_node)
    logical_expression.classify_variables(method_node.variables,
                                          precondition_node)

    task_list_nodes = build_task_list(tasklist_expr)

    branch.children = [precondition_node] + task_list_nodes

    return branch