Source to Source Compiler

06 Jun, 2022
A compiler is a software program that transforms a program or code written in a high-level programming language into a low-level machine-readable language. When we write a program or code which can be in a high-level language, such as C, C++ or such as the one given below.
//Simple Java program
public class simple{ 
  public static void main(String[] args){ 
    System.out.printIn("Hello World")
    }
  }
A high-level language is closer to English, which makes it easier for us to write programs. But we can’t just run the same code onto a computer as machines can’t understand that. All that a computer can understand is binary code, that is ones and zeros. Therefore, the solution to the problem that computers can’t understand high-level languages would be to convert those into machine-understandable binary code. This is the exact task that is done by a compiler.  
The compiling process of the simple ‘hello world’ program up there would be as follows –
We create the ‘hello world’ program and save the file as Hello.java.When we complete this program, the compiler generates the equivalent machine code and saves it into the class file of the same name but with class extension Hello.class.And when the program is executed, it is the class file that gets executed and gives the output.
We create the ‘hello world’ program and save the file as Hello.java.
When we complete this program, the compiler generates the equivalent machine code and saves it into the class file of the same name but with class extension Hello.class.
And when the program is executed, it is the class file that gets executed and gives the output.
Compiles are of many types, but in this article, we are going to learn about a specific one, that is Source to Source Compiler.
Source To Source Compiler :A source to source compiler (S2S compiler) is also referred to by three other name, the first is the source to source translator, the second is transcompiler and the third one is transpiler. If we try to summarize the work on the source to source compiler is a sentence, it would be as follows:
A S2S Compiler is given as input the source code of a program to which it returns a source code with the overall same functionality in the same or different programming language. 
Unlike the general compiler whose work is to convert a high-level programming language to a machine language that is binary, the source to source compiler converts one source code from one programming language to another programming language which is at the same level of compilation from machine language. For example, while the traditional compiler may convert C to assembly or Java to bytecode, the source to source compiler may convert one scripting language to another such as Javascript to Python, or C++ to Java. 
Some examples of traditional compilers are listed below :
Some Examples of Source to Source compilers are listed below :
ActionScript3, JavaScript, Java, C++,
C#, PHP, Python, Lua
One of the main source application of source to source compilers is to convert the old code, that is legacy code, to the newer versions of a programming language or an API which helps in retaining the backward compatibility of the code. Tools come in very handy in updating large and old code bases which otherwise would take too much time to do it manually. An example of it could be converting the program of the older version of C++ to the current stable version that is C++20. Or it could also be the case of an API such as the old Dart program to be converted to the newer Dart 2.0 version. The structure of the newer could is dependent on the compiler. It could either be very similar to the original code to ease the development process from one language to the other or from the older version to the newer. Or the code structure can be completely changed so as to make it look original or different.
If we give a closer look at the table above, we can deduce that the initial use of some of the main programming languages, such as PHP or C++, was started as a source to source compilers, as their main use was to convert to the other mainstream programming languages. Today also, if we take a look around, we can identify languages such as Dart, Typescript, CoffeeScript, Emcscript and others as being mainly used for the conversion to other languages.
Assembly Language Translator :Assembly language translators are one of the most important examples of the source to source compiler. Below we have discussed in brief the four assembly language translators.
Intel CONV86 – It is one of the first compilers which could translate assembly into the binary. Back in the late 70’s, it was made by Intel, which is famous for making processors. The intended purpose for this was to reliably run the program made for an 8-bit processor onto Intel’s 16-bit processor. As per the users, it being one of the first of its kind, it was not able to perform up to the expectations.
SCP TRANS86 – Similar to the Intel CONV86, this translator was developed in 1980 by an engineer named Tim Paterson who is known as the creator of the famous 86-DOS. This translator was designed to translate assembly code from Intel 8080 and Zilog Z80 into .ASM code for Intels 16-bit processor Intel 8086. But similar to its previous counterpart, it was unable to perform the job effectively and required a lot of manual correction.
Sorcim TRANS86 –Socrium is a start-up that also offered an assembly translator to the market in 1980. It was also invented to convert assembly to MS-DOS. This translator proved to be a better substitute for the previous two.
Digital Research XLT86 – This translator appeared in the market in September of 1981 and was developed by Gary Kildall. Before this translator, no one other had the optimizing compiler approach which provided an effective performance. Like SCP TRANS86, its object was also to convert .ASM source code from Intel 8080 into the .A86 code for Intel 8086.
These four assembly code translators mark the beginning for the source to source compilers, which now had made many folds of progress.
adnanirshad158
sumitgumber28
Picked
Compiler Design
GATE CS
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Directed Acyclic graph in Compiler Design (with examples)
Type Checking in Compiler Design
Data flow analysis in Compiler
S - attributed and L - attributed SDTs in Syntax directed translation
Runtime Environments in Compiler Design
Layers of OSI Model
ACID Properties in DBMS
TCP/IP Model
Types of Operating Systems
Normal Forms in DBMS