A Monadic Program Slicer
*
Yingzhou Zhang
1
, Jose Emilio Labra Gayo
2
, Agustín Cernuda del Río
2
(
1
College of Computer, Nanjing Univ. of Posts and Telecommunications, Nanjing 210003, China)
(
2
Dep.of Computer Science, Univ. of Oviedo, C/Calvo Sotelo s/n C.P. 33007, Oviedo, Spain)
zhangyz@njupt.edu.cn, {labra, guti}@lsi.uniovi.es
Abstract
Program slicing is an important decomposition
technique. It has been widely used in many software
activities, such as software analyzing, understanding,
debugging, testing, and maintenance. The current
slicing methods and tools, however, are monolithic,
and mainly based on program or system dependence
graph. This paper presents a novel formal tool for
program slicing. It abstracts the computation of
program slicing as a language-independent slice
monad transformer, which can be applied to the
semantic descriptions of the program in a modular
way, forming the corresponding slicing algorithms.
Such algorithms allow program slices to be computed
directly on abstract syntax, with no need to explicitly
construct intermediate structures such as dependence
graphs or to record an execution history. It has
reusability and language-flexibility properties in
comparison with the current program slicing
methods/tools.
Keywords: Program Slicer, Modular Monadic
Semantics, Monad, Monad Transformer
1. Introduction
Program slicing [29] is an effective technique for
narrowing the focus of attention to the relevant parts of
a program. The basic idea of program slicing is to
remove irrelevant statements from source code while
preserving the semantics of the program such that at a
specified point a variable produces the same value as
in the original program. Program slicing has been
widely used in many software activities including
software testing and debugging, measurement, re-
*
This work was supported by the Natural Science Research Plan for
Jiang Su High School (05KJD520151)
engineering, program analysis and comprehension, and
so on [1,3,5,23]. Program slicing can be classified into
static slicing and dynamic slicing according to whether
it only uses static information or dynamic execution
information for a specific program input.
As an example, Figure 1 includes a program and its
dynamic slice for the variable s and the input n=2 and
a=0. Notice that the statements 11−13 and 16 can be
removed as they do not affect the value of s.
The original program slicing method was expressed
as a sequence of data flow analysis problems [29]. An
alternative approach relied on program dependence
graphs (PDG) [18]. Most of the existing slicing
methods were evolved from both approaches. Current
slicing methods are mainly based on the reachability
problem over PDG or SDG (system dependence graph)
[6]. These methods are incremental and sequential, not
compositional. However modern programming
languages support modularized programming styles
and programs should consist of a set of modules. So
the program analysis should reflect this design
technology, and its methods (including program slicing)
should be flexible and reusable.
Hwang et al. [7] stated that a slicing algorithm
which will preserve the properties of a program, must
pay attention to semantic differences occurring among
languages other than merely data-flow information.
They showed that a program slicer should be language-
dependent. Therefore, the slicing algorithms should be
flexible enough to correspond to the semantics of a
given language. In addition, as the behavior of a
program is determined by the semantics of the
language, it is reasonable to study program slicing as
viewed from the formal semantics of a program.
The program slicing methods focused on program
semantics are mainly based on the standard
denotational semantics, i.e. denotational slicing
[4,17,24]. Denotational semantics, however, lack
modularity and reusability [8,15,16,21]. So it is
difficult to apply the denotational slicing approach to
more realistic programming languages containing
ACM SIGPLAN Notices 30 Vol. 41 (5), May 2006