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)
def p_return_stmt(p): "return_stmt : RETURN SEMI" p[0] = node.return_stmt(ret=ret_expr)