top of page
Writer's picture_Romeyo Boy_

Compiler


Since computer hardware is capable of understanding machine level instructions, it is necessary to convert the instruction before the program can be executed by the computer. We have seen that assembly language uses an assembler to perform this conversion process. In case of high level language this work is done by the compiler.

Compiler - Creative Bloke

Compiler is a translating program that translates high level language instructions into machine language. A compiler is so called because it compiles a set of machine language instructions for each program instruction of a higher level language. A program written by a programmer in a higher level language is called a source program. Which is converted into machine language by a compiler, which is called an object program.

Compiler - Creative Bloke

An interpreter or compiler is a set of one or more computer programs that convert a program written in one high-level computer language into another computer language. The term interpreter is often used to refer to programs that convert a higher level language program into a lower level language program.

Compiler - Creative Bloke

The computer language in which the original program is contained is called the source language and this program is called the source code. Similarly, the language in which the source code is changed is called the target language and the code thus obtained is called object code. Object code is often in a binary language, whereby the linker generates machine code that is executable on a particular machine.


What Are The Main Parts Of The Compiler?

Well, the compiler mainly consists of two major parts;

  • Analysis Phase

  • Synthesis Phase

01. Analysis Phase

The first part is the analysis phase, in which an intermediate representation is created from a given source program. The main parts of this step are – Lexical Analyzer, Syntax Analyzer and Semantic Analyzer.


02. Synthesis Phase

Whereas the second part is the synthesis step, in which the equivalent target program is built from the intermediate representation. The main parts of this phase are - Intermediate Code Generator, Code Generator and Code Optimizer.


What Is A Decompiler?

A compiler that converts machine language into a high level natural language is called a decompiler. Or computer programs that generate programs from a low-level computer language and generate a program from a high-level language, are called forwarders or decompilers.


What Is A Cross-Compiler?

Compilers that generate object code that are meant to run only in the system are called cross-compilers.


Language Translator

  • A compiler that converts one programming language into another programming language is called a language translator or language translator. OR

  • A program that converts one high-level computer language into another high-level computer language is called a computer-language translator.


Major Operating Parts of the Compiler

The compiler does the following: In some compilers, some of these parts may be absent-

  • Lexical Analysis

  • Purging

  • Semantic Analysis

  • Code Generation

  • Code Optimization

Major Operating Parts of the Compiler - Creative Bloke

The compiler works in several phases, but in general all compilers can be considered to be composed of three main phases.


What Is The Use Of Compiler?

Compilers are most commonly used to perform the seven major steps.

  • Scanning

  • Lexical Analysis

  • Syntactic Analysis

  • Semantic Analysis

  • Intermediate Code Generator

  • Code Optimizer

  • Code Generated


01. Scanning

This scanner reads one character at a time from the source code and keeps track of all the characters to know which character is present in which line.


02. Lexical Analysis

The compiler converts the sequence of characters that appear in the source code into a series of string characters (called key tokens) that are associated with a specific rule, called a program. A symbol table is used to store the words in the lexical analysis in the source code, which corresponds to the generated token.


03. Syntactic Analysis

In this step, syntax analysis is performed, which includes preprocessing, which determines whether tokens created during lexical analysis are in the proper order or not as used. The correct sequence of the set of keywords which ultimately gives the desired result is called syntax. In this the compiler has to examine this source code to ensure syntactic accuracy.


04. Semantic Analysis

This stage consists of several intermediate steps. First it checks the structure of the tokens, as well as their order, whether it is according to the grammar of the given language or not. The meaning of the token structure is interpreted by the parser and analyzer to eventually generate an intermediate code called object code.


These object codes contain instructions that represent the processor action for the corresponding token when encountered in the program. Finally, the entire code is parsed and interpreted to check whether any optimizations are possible. Once the optimization is done, appropriately modified tokens are inserted into the object code to generate the final object code, which is saved to a file.


05. Intermediate Code Generator

This face of the compiler is also very important. It serves to give an organized look to all the above steps. It works to convert all their work into 3 address codes. So that their works can be put to work for the purposes of their creation.


06. Code Optimizer

When the intermediate code generator completes its task, that is, when it generates 3 address codes. So it serves to optimize those codes. That is, it serves to display his expansionism in a subtle way. By which it can be easy to read and understand.


07. Code Generated

After that it generates the code and completes it. After the completion of which the work of the compiler is completed, in simple words, this last step converts the high level language into machine language. Which helps in understanding the computer and can be easily read and understood as a low level language.


What are the different stages of the compiler?

Let us let you know about the different steps being used to operate the compiler here;

  • Lexical Analysis

  • Syntax Analysis

  • Semantic Analysis

  • Intermediate Code Generator

  • Code Optimizer

  • Code Generation


Finding Mistakes Or Errors

Compilers are large programs that reside permanently on the secondary storage of the computer. When a program is to be translated, they are copied to the main memory (RAM) of the computer. A computer is able to find the following type of error in a source program.

  • Illegal Characters.

  • Illegal Combination Of Characters.

  • Improper Sequencing Of Instruction In A Program.

Note :- A computer, though cannot diagnose logical errors, it can only diagnose system errors in programs.


How Does The Compiler Work?

The compiler first scans the entire program and simultaneously converts the entire program into machine language. That is, the compiler scans the entire program written by the programmer at once, converts them into machine language and if there is an error or error, then displays it in the debugging window. Which we can fix step by step and compile the program again. Compilers do not translate each statement of the program line-by-line like an interpreter.


The object program or object code generated by the compiler is machine dependent i.e. computer dependent. This means that a program compiled on one machine/computer will not work on any other machine/computer. Therefore, to write programs in a particular language in every computer, it is necessary to have a compiler of that language. Programs are written in a high-level language to eliminate machine dependencies.


Advantages Of The Compiler

  • Compiler converts programs written in high-level language i.e. source program together into object program or machine level language.

  • If an error occurs, it is displayed in the debugging window, which we can fix one by one and compile the program again.

  • Compilers allow programmers to use high-level languages, thereby eliminating the shortcomings of machine language (binary language) and assembly language, which were much more complex than high-level languages.


Disadvantages Of The Compiler

  • The compiler compiles the source program together. So it takes a lot of time to write a program.

  • Finding and correcting errors or errors can be very difficult and time consuming as the program gets bigger.


History Of The Compiler

The first compiler was developed by Grace Murray Hopper while working on the Harvard Mark I computer. Today, most high-level languages ​​will include their own compilers or have available toolkits that can be used to compile programs. Two popular compilers are Eclipse for Java and GCC commands for C and C++. Depending on how big the program is, compilation should take a few seconds or minutes. If no errors occur when compiling, an executable file is created.

  • 1952 - Development of the autocode compile for the Mark 1 computer.

  • 1952 - Created a compiler for the Grass Hopper A-0 programming language.

  • 1954-1957 - Development of the FORTRAN language at IBM, considered the first high-level programming language. Compiler was also made for it in 1957.

  • 1959 - Development of COBOL started. Its design was influenced by the A-0 and FLOW-MATIC. COBOL's compiler was also built in the early 1960s.

  • 1958-1962 - LISP was designed at MIT.


Type Of Compiler

Following are the different types of compilers:-

  • Single-Pass Compiler

  • Two-Pass Compiler

  • Multi-Pass Compiler

i. Single-Pass Compiler

The function of a single-pass compiler is to read the program. It organizes all the phases of the compiler and brings them uniformity. Single-pass compilers also serve to store the output. By which he provides his process completely.


ii. Two-Pass Compiler

It works to organize all the phases of the compiler by dividing it into two parts. It divides the first four phases and the last two phases into different parts. It plays an important role in the process of input and output. It helps him in the process of semantic analysis.


iii. Multi-Pass Compiler

It works in contrast to a single-pass compiler. It checks the above two passes in several steps and produces an output only after completing its test. If we understand it in simple words, then it works to fulfill the deficiency that is left in the above 2 passes.


Why Use A Compiler?

  • The compiler verifies the entire program, so there are no syntax or semantic errors.

  • The executable file is optimized by the compiler, so it executes faster.

  • Allows you to create internal structures in memory.

  • There is no need to execute the program on the same machine it was created on.

  • Translates the entire program into another language.

  • Generates files on disk.

  • Links files in an executable format.

  • Helps you to increase your understanding of the semantics of the language.


What Are The Features Of The Compiler?

  • Accuracy

  • Compilation Speed

  • Preserve The True Meaning Of The Code

  • Target Code Speed

  • Identify Legal and Illegal Program Creations

  • Good Error Reporting and Handling

  • Code Debugging Help.


* Frequently Asked Question


01. What is Compiler and Interpreter?

Answer:- Compiler is a kind of translator which converts source language into object language. An interpreter is a type of program that works in the source language itself.


02. What do you understand by compiler?

Answer:- Compiler is a type of translator program.


03. Which software is the compiler?

Answer:- Compiler is such a program. Which translates programs written in a high-level language into the computer's machine language.


04. What is a compiler called?

Answer:- The one who reads the complete source program written in a high-level language language in one go and translates it into an equivalent program in machine language, is called a compiler.


05. Who made the compiler first?

Answer:- The term compiler was first used by Grace Murray Hopper in 1950. However, the first compiler was built between 1954 and 1957 by IBM company employee John Beckham and his team.


06. Which is the first high-level language?

Answer:- COBOL was the first high-level language, which was compiled with the help of a compiler.




✨ Also Know Some Related Articles

1 view0 comments

Recent Posts

See All

Comentários


bottom of page