Beispiel #1
0
def p_body(p):
    """
    body : statement SEMICOLON body
            | while_block body
            | if_block body
            |
    """
    if len(p) == 1:
        body = ASTNode('BODY', 'body')
    elif len(p) == 3:
        body = p[2]
        body.prepend_child(p[1])
    elif len(p) == 4:
        body = p[3]
        if p[1] is not None:
            body.prepend_child(p[1])

    p[0] = body
Beispiel #2
0
def p_param_list_non_empty(p):
    """
    param_list_non_empty : type function_term_r COMMA param_list_non_empty
            | type function_term_r
    """
    # p[0] = ast_node, [(id, type, deref_depth) ...]
    if len(p) == 3:
        _type = p[1]
        param_ast_node, _id, deref_depth = p[2]
        node = ASTNode('PARAM_LIST', 'param_list')
        type_child = ASTNode('TYPE', _type)
        node.prepend_child(param_ast_node)
        node.prepend_child(type_child)
        p[0] = node, [(_id, _type, deref_depth)]
    elif len(p) == 5:
        _type = p[1]
        param_ast_node, _id, deref_depth = p[2]
        param_list_ast_node, param_meta_data_list = p[4]
        type_child = ASTNode('TYPE', _type)
        param_list_ast_node.prepend_child(param_ast_node)
        param_list_ast_node.prepend_child(type_child)
        p[0] = param_list_ast_node, [(_id, _type, deref_depth)
                                     ] + param_meta_data_list