Constructing Format-Preserving Printing from Syntax-Directed Definitions.

LiChao Wang,GuoQiang Li,ZhenJiang Hu
DOI: https://doi.org/10.1007/s11432-015-5368-9
2015-01-01
Science China Information Sciences
Abstract:Transformations between source codes, such as refactorings and program analysis, are frequently used in software engineering. Typically, transformations are effectively implemented using an abstract syntax tree (AST) on the origin source code. However, a critical limitation of ASTs is the loss of layout information such as whitespace and comments, which can result in poor readability. To overcome this shortcoming, this paper proposes a bidirectional transformation (BX) method that maintains consistency in the layout between the origin and transformed. First, a section of origin source code will be translated to a concrete syntax tree (CST) that includes layout information. Second, to make the BX practical, a new method is constructed that matches an AST with its respective CST. Finally, to get a reasonable CST, a method to amend the CST is also provided. We prove that the BX is well-behaved, which implies that it satisfies both the PutGet and GetPut laws. Furthermore, we illustrate the correctness of the methodology by treating XML language as a case study.
What problem does this paper attempt to address?