top of page

Compiler: Definition, Architecture, Advantages and Disadvantages

Updated: Sep 27, 2023


Compiler

The Compiler is a computer program that translate the high-level language (source code) into a computer-readable format known as low-level language or machine code. Compilers that translate source code to machine code target specific operating systems and computer architectures. This type of output is sometimes referred to as object code (which is not related to object-oriented programming). The outputted machine code is made up entirely of binary bits -- 1s and 0s -- so it can be read and executed by the processors on the target computers. For example, a compiler might output machine code for the Linux x64 platform or Linux ARM 64-bit platform.



Features of a Compiler:

  • Compilation speed.

  • The correctness of machine code.

  • The meaning of code should not change.

  • Speed of machine code.

  • Good error detection.

  • Checking the code correctly according to grammar.



Compiler Architecture

Compiler

ASML: Assembly Language

An assembly language statement is a line of text that translates into a single machine instruction (low level programming language). Assembly Language is expressed in a more human readable form than the binary instructions and names are allowed for memory locations, registers, operations etc. Here we have some of the advantages of using assembly languages:

  • Require less memory and execution time

  • Allow hardware hardware-specific complex jobs in an easier way.

  • Suitable for time-critical jobs


Parser

A parser is a compiler or interpreter component that breaks data into smaller elements for easy translation into another language. A parser takes input in the form of a sequence of tokens, interactive commands, or program instructions and breaks them up into parts that can be used by other components in programming.


Intermediate Representation

An intermediate representation (IR) is the data structure or code used internally by a compiler or virtual machine to represent source code. An IR is designed to be conducive to further processing, such as optimization and translation.


Semantic Analyzer

Semantic Analysis is the third phase of Compiler. Semantic Analysis makes sure that declarations and statements of program are semantically correct. It is a collection of procedures which is called by parser as and when required by grammar.


Object Code Generator

It is considered as final phase of compilation. Through post code generation, optimization process can be applied on the code. It is the object code of low level programming language (Assembly Language).

Object Code is the objective of the source code. The output of the compiler is simply called "Object Code".


Types of Compiler

Following are the different types of Compiler:

  • Single Pass Compilers

  • Two Pass Compilers

  • Multipass Compilers


1. Single Pass Compiler

Compiler

In single pass Compiler source code directly transforms into machine code. For example, Pascal language.


2. Two Pass Compiler

Compiler

Two pass Compiler is divided into two sections, viz.

  1. Front end: It maps legal code into Intermediate Representation (IR).

  2. Back end: It maps IR onto the target machine

The Two pass compiler method also simplifies the retargeting process. It also allows multiple front ends.


3. Multi-pass Compilers

Compiler

The multi-pass compiler processes the source code or syntax tree of a program several times. It divided a large program into multiple small programs and process them. It develops multiple intermediate codes. All of these multi-pass take the output of the previous phase as an input. So it requires less memory. It is also known as ‘Wide Compiler’.



Compiler Advantages

  1. Runs Faster → It runs faster than the Interpreter since the source code is already compiled and we only need to execute the executable file is generated.

  2. Optimized → Machine code of executable file generated with a compiler is often a native machine instruction for the targeted machine which is well optimized and runs faster.

  3. Secure → Executable files generated from the compiler can be executed on any of your clients or other systems without the need for actual source code. Which makes your program unhackable, secure and private

  4. No dependencies → Your client or anyone else doesn’t need any compiler, interpreter, or third party program to be installed in their system, for executing the shared executable file of your source code.

Compiler Disadvantages

  1. Extra Memory → It occupies extra memory since it needs to generate a new file.

  2. Extra step → Unlike interpreter, we can’t run our source code directly, we need to additionally run the executable file.

  3. Incompatibility issue → Since its code is optimized for the system it was executed on, which many times leads to system incompatibility issue even if the system is running on the same OS.

  4. Harder to Debug → After reading the whole code it returns all errors at once if available, which makes it harder to navigate and fix the error



Language uses Compiler

1. C++ C++ is an object-oriented programming (OOP) language that is viewed by many as the best language for creating large-scale applications. C++ is a superset of the C language. A related programming language, Java, is based on C++ but optimized for the distribution of program objects in a network such as the Internet.


2. Fortran Fortran stands for formula translation which is one of the programming languages ​​that can support writing calculation forms such as complex numbers, but Fortran has a weakness that the source code is difficult to understand because it uses a high-level programming language.


3. Pascal Pascal is a programming language by writing using an English structure algorithm, imperative and procedural. Pascal is a programming language that implements good programming structures and procedures. One of the advantages of Pascal is that it has a simple language that can be more easily understood by humans.


4. Swift

Swift is a general-purpose, multi-paradigm, compiled programming language developed by Apple Inc. and the open-source community.


5. C

C is a general-purpose programming language that is extremely popular, simple, and flexible to use. It is a structured programming language that is machine-independent and extensively used to write various applications, Operating Systems like Windows, and many other complex programs like Oracle database, Git, Python interpreter, and more.


6. Visual Basic Visual Basic or VB is an unusual programming language or can be called advanced because VB has the advantage that it can easily write programs on the Windows operating system. VB is formulated with an integrated development environment that is able to simplify code and correct errors or improvements.


7. Carbon

Carbon is a general-purpose programming language that was created at Google to be a C++ successor language. A Googler named Chandler Carruth introduced developers to the new programming language called Carbon.



The Tech Platform

0 comments
bottom of page