예제 #1
0
파일: parse.py 프로젝트: RobBW/smop
def p_function(p):
    """
    function : func_decl
             | func_decl END_STMT
             | func_decl stmt_list
             | func_decl stmt_list END_STMT
    """
    # we backpatch the func_decl node
    func_decl = p[1]
    end_stmt = None
    if len(p) > 2 and isinstance(p[2], node.stmt_list):
        stmt_list = p[2]
        if len(p) == 4:
            end_stmt = p[3]
    else:
        stmt_list = node.stmt_list()
        if len(p) == 3:
            end_stmt = p[2]

    assert stmt_list.__class__ is node.stmt_list
    assert func_decl.__class__ is node.func_decl
    assert end_stmt is None or end_stmt == 'end', repr(end_stmt)
    func_decl.use_nargin = use_nargin
    func_decl.use_varargin = use_varargin

    # if not end_stmt:
    #    print "%s has no end" % func_decl.ident.name

    # for fns in [fn for fn in stmt_list if fn.__class__ is node.function and not fn.end]:
    #    print fn.head.ident.name

    if len(stmt_list) == 0 or stmt_list[-1].__class__ is not node.return_stmt:
        stmt_list.append(node.return_stmt(ret_expr))

    p[0] = node.function(head=func_decl, body=stmt_list, end=end_stmt)
예제 #2
0
def p_function(p):
    """
    function : func_decl
             | func_decl END_STMT
             | func_decl stmt_list
             | func_decl stmt_list END_STMT
    """
    # we backpatch the func_decl node
    func_decl = p[1]
    end_stmt = None
    if len(p) > 2 and isinstance(p[2], node.stmt_list):
        stmt_list = p[2]
        if len(p) == 4:
            end_stmt = p[3]
    else:
        stmt_list = node.stmt_list()
        if len(p) == 3:
            end_stmt = p[2]

    assert stmt_list.__class__ is node.stmt_list
    assert func_decl.__class__ is node.func_decl
    assert end_stmt is None or end_stmt == 'end', repr(end_stmt)
    func_decl.use_nargin = use_nargin
    func_decl.use_varargin = use_varargin

    # if not end_stmt:
    #    print "%s has no end" % func_decl.ident.name

    # for fns in [fn for fn in stmt_list if fn.__class__ is node.function and not fn.end]:
    #    print fn.head.ident.name

    if len(stmt_list) == 0 or stmt_list[-1].__class__ is not node.return_stmt:
        stmt_list.append(node.return_stmt(ret_expr))

    p[0] = node.function(head=func_decl, body=stmt_list, end=end_stmt)
예제 #3
0
파일: parse.py 프로젝트: RobBW/smop
def p_return_stmt(p):
    "return_stmt : RETURN SEMI"
    p[0] = node.return_stmt(ret=ret_expr)
예제 #4
0
def p_return_stmt(p):
    "return_stmt : RETURN SEMI"
    p[0] = node.return_stmt(ret=ret_expr)