The process of basic code translation is detailed in this lesson.
How does a Computer Perform Binary Code Translation?
Computers cannot understand the coding language, which is in English. Then how will the computer understand those statements and process the given instructions for generating the desired output? It is by converting the English base code into machine language or binary format, known as basic code translation.
For instance, look at the instructions, System.out.println(“Hello Ashok”) from the Java programming language can be understood by the programmer, but the computer cannot understand the same statement. So, to understand, the computer uses an interpreter to convert the English-based code into a binary or machine-readable format.
Limitations with Interpreter
However, there were some limitations to the functioning of interpreters. Because an interpreter could not identify errors in the code written by the programmer, it translated even the wrong code. After the basic code translation, the code is sent to the microprocessor for processing the data. However, if there are errors in the code, the microprocessor finds it challenging to understand. At such times, the computer used to shut down suddenly, giving rise to many technical issues. But this was all before the introduction of compilers and the emergence of the ‘C’ language. Some basic languages, such as Pascal and Cobol, run using an interpreter alone.
Introduction of Compilers
With some drawbacks with an interpreter, there was an urgent need to rectify these issues. Against this backdrop, compilers were introduced to assist the interpreters in running the correct code. So, all the programming languages developed from and after C language include the compiler and Interpreter.
Now let’s see precisely what the compiler does to solve the limitations of an interpreter.
Compilers are much more sophisticated than interpreters. Because during translation, if any error is found, they do not allow the code translation to complete; instead, they caution the programmer first to rectify the error. After fixing the error, the compiler allows the data to enter the Interpreter for translation to the binary code. It means the compiler only translates the code once it is correct regarding semantics and syntax.
Here what do you mean by code that is correct in terms of semantics and syntax?
We all know that each programming language has to follow some pre-determined steps or specifications to run a program successfully. If the programmer deviates from those specifications, then errors can happen.
For instance, the program has syntax errors if a semicolon is missing in the code.
If the programmer forgets to give a name for a function, doesn’t type the word function, or doesn’t give a bracket, then they are called semantics errors. The specifications required before the starting of a program are known as semantics.
What is a Compiler?
The compiler is software that checks each line sequentially from top to bottom for semantics and syntax errors; if there are no errors in terms of semantics and syntax, then the code is subjected to the Interpreter to convert. While the raw data is called source code, the interpreted code is called destination code or binary code.
Now let’s look at the difference between Basic code translation and Byte code Translation
With the help of an interpreter located inside the compiler, the compiler takes the responsibility of converting the source code into a machine-readable format. While in C programming language, this process is called “Basic Code Translation, in Java, it is called Byte Code Translation.
To what can the compiler be compared to in a human language?
It is like checking grammatical errors in any language, such as English.
Let’s see a few more lines about Interpreter.
The Interpreter converts the High-level language into machine code which is in 1s and 0s.
Notably, the compiler it is to be noted that while converting the source code into destination code or binary code, the compiler generates another file. For example, after compiling in C language dot e x e file is generated, while in Java, it generates a dot class file.