Proceedings of ISP RAS

Source code transformation and automatic correction of defects with KAST language.

N.L. Lugovskoy, S.V. Syromyatnikov.


This article is devoted to KAST pattern language extensions introduced for purposes of source code transformation. Currently KAST is used for matching syntactic patterns in syntactic trees built of C/C++, Java or C# sources. After introducing several new functions that can be called from a pattern, KAST patterns became applicable not only for detecting desired fragments of syntactic trees, but for specifying modifications of those fragments as well. Several existing approaches to code transformation are also considered. The main advantage of the described KAST based technique over those approaches is that our patterns can describe constructs we need to change together with the context these constructs are used in. Another important benefit is that KAST patterns can deal with semantic information about tree nodes. This significantly increases precision of pattern matching. The article also describes a method for converting modifications of syntactic trees into modifications of source code. The described technique allows to preserve comments, macro calls and indentation that were used in the initial code fragment. Though our approach is applicable only to a single compilation unit and doesn't guarantee syntactic correctness of newly generated code, it can greatly ease the task of automatic code transformation.


refactoring; code transformation; static analysis; program architecture; pattern language; KAST


Proceedings of the Institute for System Programming, vol. 25, 2013, pp. 51-66.

ISSN 2220-6426 (Online), ISSN 2079-8156 (Print).

DOI: 10.15514/ISPRAS-2013-25-4

Full text of the paper in pdf (in Russian) Back to the contents of the volume