What is a compiler?

Rumman Ansari   Software Engineer   2024-01-20 08:05:08   358 Share
Subject Syllabus DetailsSubject Details 2 Questions 15 MCQ
☰ Table of Contents

Table of Content:


A Compiler is a program (or set of programs) that converts source code written in a high-level language to low-level language (assembly language or machine language). A programming language can have many compilers. For example – GCC C, Turbo C, Quick C etc. are different compilers for C programming language.

Compilers

Compiler is a program that converts human readable code into machine readable code. This process is called compilation.

Examples of Compiler in Different Programming Language

Here's a table with the names of compilers for different programming languages:

Programming Language Compiler Name Description
C GCC (GNU Compiler Collection) A powerful and widely used compiler for the C programming language. Supports various operating systems and architectures.
C++ g++ The GNU C++ compiler, part of the GCC suite. Used to compile C++ source code into executable programs.
Java javac The Java compiler that translates Java source code into bytecode for execution on the Java Virtual Machine (JVM).
Python CPython While Python is interpreted, CPython is the default implementation that compiles Python source code into bytecode.
C# Roslyn (.NET Compiler Platform) An open-source set of compilers and code analysis APIs for C#. Developed by Microsoft, it provides advanced tools.
Fortran GFortran The GNU Fortran compiler, part of the GCC suite. Used to compile Fortran source code into executable programs.
Swift swiftc The compiler for the Swift programming language. Translates Swift source code into machine code for execution.
Rust rustc The compiler for the Rust programming language, emphasizing memory safety and performance through ownership rules.
Go gc (official compiler) The official Go compiler, often referred to as "gc." Compiles Go source code into machine code for execution.
Haskell GHC (Glasgow Haskell Compiler) The primary compiler for the Haskell programming language. Supports various language extensions and optimizations.

This table provides a concise overview of some commonly used compilers in different programming languages.

Why do we need a compiler?

A Computer understands only binary language and executes instructions coded in binary language. It cannot execute a single instruction given in any other form. Therefore, we must provide instructions to the computer in binary language. Means we must write computer programs entirely in binary language (sequence of 0s and 1s).

But think for a while, how cumbersome programming would have been, if we have to write every program as a sequence of 0s and 1s? It would have been a nightmare to write complex software's. Humans are good at giving instructions in English language, whereas computers can only process binary language.

So, there was a need of a translator that translates the computer instructions given in English language to binary language. Hence, to accomplish the job of a translator compiler was invented. The world’s first compiler was written by Grace Hopper in 1952 for the A-0 programming language.

What do a compiler do?

Apart from translating source code from high level language to low level language, compiler has other responsibilities too. After reading source code written in high level language it performs below operations -

  1. Performs a pre-processing of source code. Gather all files required for the source code to compile.
  2. Parses the entire source code. Checks for any syntax errors in the source code.
  3. Performs a thorough syntax analysis of the source code. To understand the structure and semantic of the source code.
  4. Optionally translates the source code in an intermediate code known as object code to enhance the performance.
  5. Translates the object code to binary language known as executable code.

Some popular compilers

Language Compilers Developed by
BASIC FreeBASIC FreeBASIC development team
QuickBASIC Microsoft
Visual Basic Microsoft
C GCC C GNU Project
Borland Turbo C Embarcadero
Quick C Microsoft
C++ GCC GNU Project
Borland C++ Borland
Visual C++ Microsoft
C# Visual C# Microsoft
Mono Xamarin
Java javac Sun Microsystems (Owned by Oracle)
gcj GNU Project