Compiler

COMPILER is a program that carries out source code translation at a go, it is a translator which will compile/translate the whole source code into machine code/ executable code at once. A compiler will translate the high-level language code into machine code before the program runs and will generate an executable which can be directly executed by the CPU.

The complete program will be compiled and translated in binary which can be processed by the CPU at the physical layer. It will translate source code into object code/binaries.

The compiler will translate the source code written in a high-level language to an executable at a go, all the source code will be compiled all at once.

Compiling is a much faster source code translation mechanism than the interpreter. Five major types of compilers are: Multi-pass compilers | Just-in-time compilers | single pass compilers | AOT | Cross Compilers.

Languages like C, C++, JAVA, and Cobol leverage specific compilers to carry out high-level source code translation.

Compiler will work on translation -> Linking -> loading

The process: The compiler will first run a scan of the program that needs to be compiled and then it will compile the program at once, the debugging in the case of the compiler is slower and more complex as all the errors in the program are shown at once.

Debugging is slower but the execution time is faster as the whole code is translated and executed at a go.

High-level languages are compiled and translated into machine code which is then executed by the CPU and stored in the memory, the format of execution will be base 2.

High level language code is written in ASCII, hence the translation of ASCII or hexa-based languages into binary format is carried out for low level processing by the compiler.

The key difference between the compiler and the interpreter.

Compiler: The compiler will generate an executable that can run without carrying out compilation, once the code is compiled it can be run N numbers of times without calling the compiler. Compilers translate the program before execution, In compilation the translation is done before execution.

The compiler will compile source code into machine code which will be executed by the processors, The compiler will generate an executable which can be run as many times as needed. Compile once and run the code as many times as needed

Interpreter: The interpreter will interpret the code line by line and will generate the output during run time, the interpreter will only render the output once all the lines are error free. The interpreter will be called all the time whenever the code needs to run. The interpreter converts code during run time, line by line translation will be done by an interpreter.

Diagrams

The article above is rendered by integrating outputs of 1 HUMAN AGENT & 3 AI AGENTS, an amalgamation of HGI and AI to serve technology education globally.

(Article By : Himanshu N)