Exemplo n.º 1
0
def p_end_function(p):
    """
    top : top END_FUNCTION
    """
    p[0] = p[1]
    p[0].append(node.return_stmt(ret=ret_expr))
    p[0].append(node.comment_stmt("\nif __name__ == '__main__':\n    pass"))
Exemplo n.º 2
0
def p_top(p):
    """
    top :
        | stmt_list
        | top func_decl stmt_list_opt
        | top func_decl stmt_list END_STMT semi_opt
    """
    if len(p) == 1:
        p[0] = node.stmt_list()
    elif len(p) == 2:
        p[0] = p[1]
    else:
        # we backpatch the func_decl node
        assert p[2].__class__ is node.func_decl
        p[2].use_nargin = use_nargin

        try:
            if p[3][-1].__class__ is not node.return_stmt:
                p[3].append(node.return_stmt(ret_expr))
        except:
            raise syntax_error(p)

        p[0] = p[1]
        p[0].append(node.function(head=p[2],body=p[3]))
    assert isinstance(p[0],node.stmt_list)
Exemplo n.º 3
0
def p_top(p):
    """
    top :
        | stmt_list
        | top func_decl stmt_list_opt
        | top func_decl END_STMT semi_opt
        | top func_decl stmt_list END_STMT semi_opt
    """
    if len(p) == 1:
        p[0] = node.stmt_list()
    elif len(p) == 2:
        p[0] = p[1]
    else:
        # we backpatch the func_decl node
        assert p[2].__class__ is node.func_decl
        p[2].use_nargin = use_nargin
        p[2].use_varargin = use_varargin

        try:
            if p[3][-1].__class__ is not node.return_stmt:
                p[3].append(node.return_stmt(ret_expr))
        except:
            raise syntax_error(p)

        p[0] = p[1]
        p[0].append(node.function(head=p[2],body=p[3]))
    assert isinstance(p[0],node.stmt_list)
Exemplo n.º 4
0
def p_end_function(p):
    """
    top : top END_FUNCTION
    """
    p[0] = p[1]
    p[0].append(node.return_stmt(ret=ret_expr))
    p[0].append(node.comment_stmt("\nif __name__ == '__main__':\n    pass"))
Exemplo n.º 5
0
def p_return_stmt(p):
    "return_stmt : RETURN SEMI"
    p[0] = node.return_stmt(ret=ret_expr)
Exemplo n.º 6
0
def p_return_stmt(p):
    "return_stmt : RETURN SEMI"
    p[0] = node.return_stmt(ret=ret_expr)
Exemplo n.º 7
0
def p_end_function(p):
    """
    top : top END_FUNCTION
    """
    p[0] = p[1]
    p[0].append(node.return_stmt(ret=ret_expr))