Complier
Complier
Compiler
- Definition: A compiler is a software program that translates high-level language (HLL) code written by developers into machine code, which can be directly executed by a computer.
Functionality of Compiler
-
Translation: The primary function of a compiler is to translate source code into machine code. Unlike interpreters which execute code line by line, compilers translate the entire program at once before execution.
-
Optimisation: A compiler optimises the code for better performance. It performs tasks like eliminating redundant code and choosing the fastest way to execute instructions.
-
Error Detection: During the compilation process, syntax and semantic errors in the source code are flagged. Providing an error report to the developer helps in debugging the program.
-
Executable File Generation: After successful compilation, the compiler generates an executable file. This file can be run independently without needing the source code.
Types of Compiler
-
Single-Pass Compilers: A single-pass compiler scans the source code only once. The code is translated and optimisation is carried out simultaneously. This process is faster but less optimised.
-
Multi-Pass Compilers: Multi-pass compiler scans the code multiple times. It separates translation and optimisation into separate passes, allowing for deeper analysis and better optimisation. This process is slower but produces more efficient code.
Advantages of Compiler
-
Speed: The compiled code is faster to execute because it’s directly in machine code, the code the CPU runs.
-
Security: Once compiled, it’s hard to reverse-engineer the machine code back into the original source code. This keeps the original program safe from tampering.
Disadvantages of Compiler
-
Debugging Difficulties: The entire program must be compiled again after each bug is fixed, making the debugging process potentially time-consuming.
-
Non-Portability: Programs compiled for one kind of system will not work on another. For every system, we need to compile the program separately.