Program slicing plays an important role in application of program comprehension and program testing. Therefore, a novel answer set programming (ASP) based solution to program slicing is proposed. ASP is a method for declarative problem solving, which can represent the problem of program slicing efficiently. Program slicing based on ASP is a method which translates locating of slice into computing the answer sets of ASP program. In addition, the traditional slicing algorithm with data flow is improved, which can reduce repetitive computation and enhance the operating efficiency for the process of program slicing. The experiment shows the correctness and efficiency of this method and compares the efficiency of three ASP solver(DLV,Smodels,Cmodels) ,the improved algorithm based on Cmodels is the best one.%针对程序切片在程序理解和程序测试方面的应用,提出了一种基于ASP的程序切片方法.ASP是一种声明性问题解决方法,它可以高效地描述程序切片问题,基于ASP的切片方法,可以把切片的查找转化为回答集的求解.另外,对传统数据流切片算法进行了改进;改进后的算法可以减少重复计算,提高了运行效率.通过实验表明了此改进法的正确性和高效性;并且比较了3种ASP求解器(DLV、Smodels、Cmodels)的执行效搴,基于Cmodels的改进算法的运行效率是最高的.
展开▼