SmaCC Transformation Toolkit
The SmaCC Transformation Toolkit can be used to create scripts to transform large code bases. It has been used on several projects to convert programs written in one language to another language. The basic process is to write a SmaCC Transformation Toolkit script file that performs the transformation, check the transformed code by running, and then iterate by fixing the script and rerunning the transformation.
The transformation toolkit takes a script and a set of files to be transformed. It processes each file individually by first parsing the file to get an AST and then running the script on the nodes in the AST. By default the nodes in the AST are processed top down, but this can be changed by the script. Once the script has processed the AST, the results are saved and the next file is processed. Unlike other tools that modify the AST and then generate the updated source from the modified AST, the SmaCC transformation toolkit, uses edit operations to modify the original source to the new source.
As an example, consider a script that converts a simple language defined by GtSmaCCTransformationExampleParser
into Javascript.
We can use this script to transform a program from our simple language into Javascript:
This is the result of using the above script on the simple program:
The Transforming Delphi code into C# (at syntax level) page has a simple script that converts basic Delphi syntax into C#. It isn't meant to be a full Delphi conversion, but does show how some of the Delphi syntax can be converted to C#.