| Transformations between source codes are usually used in software engineering,such as refactorings and program analysis. Most of such transformations are effectively implemented by an abstract syntax tree(AST) of the premier source code. One of the limitations of the method is the loss of layout information such as blank space and comments, which makes the resulting source code poorly read. To overcome the shortcomings, this paper proposes a bidirectional transformation(BX) to keep the layout consistent between the premier source code and the result code by ?rst matching their concrete syntax trees(CST). Secondly, to make the BX practical, a new method is constructed to match the two trees. To get a reasonable CST, a method to amend CST is also proposed. It is proved that the BX we develop is well-behaved, which implies it satis?es the PutGet law and GetPut law. Furthermore, we prove the correctness of the methodology formally, and treat the XML language as a case study to extend the methodology on languages that cannot be generated by context-free grammars. |