예제 #1
0
파일: domain.py 프로젝트: Johnicholas/PyHTN
def build(s_exp):
    '''
    Build Domain AST from the given S-expression
    '''
    assert_node(s_exp, s_expression.List)
    assert_child(s_exp, 0, s_expression.Symbol, lex_token.DOMAIN)
    name_expr = assert_child(s_exp, 1, s_expression.Symbol)

    domain = node_type.Domain()
    domain.name = lex_token.fixup_name(name_expr.text)

    for child_expr in s_exp.children[2:]:
        assert_node(child_expr, s_expression.List)
        symbol = assert_child(child_expr, 0, s_expression.Symbol)

        if symbol.text == lex_token.METHOD:
            method = build_method(child_expr)
            domain.children.append(method)
            domain.method_map[method.name] = method

        if symbol.text == lex_token.MODULE:
            module_name = assert_child(child_expr, 1, s_expression.Symbol).text

            if len(child_expr.children) == 3:
                symbol_name = assert_child(child_expr, 2, s_expression.Symbol).text
            else:
                symbol_name = None

            domain.modules.append((module_name, symbol_name))

        if lex_token.is_constant(symbol.text):
            rhs_expr = assert_child(child_expr, 1, [s_expression.List, s_expression.Symbol, s_expression.Number])
            domain.constants[symbol.text] = term.build(rhs_expr)

    return domain
예제 #2
0
파일: domain.py 프로젝트: Johnicholas/PyHTN
def build_method(s_exp):
    signature_expr = assert_child(s_exp, 1, s_expression.List)

    method = node_type.Method()
    method.name = lex_token.fixup_name(assert_child(signature_expr, 0, s_expression.Symbol).text)

    for child_expr in signature_expr.children[1:]:
        method.variables.append(assert_node(child_expr, s_expression.Symbol).text)

    build_branches(s_exp.children[2:], method)

    return method
예제 #3
0
def build_method(s_exp):
    signature_expr = assert_child(s_exp, 1, s_expression.List)

    method = node_type.Method()
    method.name = lex_token.fixup_name(
        assert_child(signature_expr, 0, s_expression.Symbol).text)

    for child_expr in signature_expr.children[1:]:
        method.variables.append(
            assert_node(child_expr, s_expression.Symbol).text)

    build_branches(s_exp.children[2:], method)

    return method
예제 #4
0
def build_task_list(s_expr):
    task_list = []

    for child_expr in s_expr.children:
        assert_node(child_expr, s_expression.List)
        task_node = node_type.Atom()
        symbol = assert_child(child_expr, 0, s_expression.Symbol)
        task_node.name = lex_token.fixup_name(symbol.text)

        for arg_expr in child_expr.children[1:]:
            term_node = term.build(arg_expr)
            task_node.children.append(term_node)

        task_list.append(task_node)

    return task_list
예제 #5
0
파일: domain.py 프로젝트: Johnicholas/PyHTN
def build_task_list(s_expr):
    task_list = []

    for child_expr in s_expr.children:
        assert_node(child_expr, s_expression.List)
        task_node = node_type.Atom()
        symbol = assert_child(child_expr, 0, s_expression.Symbol)
        task_node.name = lex_token.fixup_name(symbol.text)

        for arg_expr in child_expr.children[1:]:
            term_node = term.build(arg_expr)
            task_node.children.append(term_node)

        task_list.append(task_node)

    return task_list
예제 #6
0
파일: domain.py 프로젝트: Johnicholas/PyHTN
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
예제 #7
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
예제 #8
0
def build(s_exp):
    '''
    Build Domain AST from the given S-expression
    '''
    assert_node(s_exp, s_expression.List)
    assert_child(s_exp, 0, s_expression.Symbol, lex_token.DOMAIN)
    name_expr = assert_child(s_exp, 1, s_expression.Symbol)

    domain = node_type.Domain()
    domain.name = lex_token.fixup_name(name_expr.text)

    for child_expr in s_exp.children[2:]:
        assert_node(child_expr, s_expression.List)
        symbol = assert_child(child_expr, 0, s_expression.Symbol)

        if symbol.text == lex_token.METHOD:
            method = build_method(child_expr)
            domain.children.append(method)
            domain.method_map[method.name] = method

        if symbol.text == lex_token.MODULE:
            module_name = assert_child(child_expr, 1, s_expression.Symbol).text

            if len(child_expr.children) == 3:
                symbol_name = assert_child(child_expr, 2,
                                           s_expression.Symbol).text
            else:
                symbol_name = None

            domain.modules.append((module_name, symbol_name))

        if lex_token.is_constant(symbol.text):
            rhs_expr = assert_child(
                child_expr, 1,
                [s_expression.List, s_expression.Symbol, s_expression.Number])
            domain.constants[symbol.text] = term.build(rhs_expr)

    return domain