Language Processors

Language processors – Compiler, Interpreter and assemblers

Language processors are software that translates text written in one language to another language.

There are hundreds of programming and scripting languages as of now. Code written in these languages is generally written in some sort of English keywords and special symbols. But the computer doesn’t understand that directly. A computer understands everything in the form of a binary.

So how does a computer understands code written by a programmer?

The code written in any high-level language needs to be converted first. This work is done by a language processor (depending upon the language.)

There are mainly two types of language processors – interpreters and translators. The translator can be further categorized as an assembler or a compiler.

Types of language processors


What is a compiler?

A compiler is a software that converts the code written in some high-level language to the machine language. In general, a compiler translates the code from a high-level language to a low-level language.

Programming languages are the specific languages through which one can instruct a computer to perform a specific task. These languages are either compiled languages or interpreted languages. Some Examples of compiled languages are C, C++, Java, while some of the major interpreted languages include PHP, python, ruby.

Now, you might know that a computer understands only binary language, which means it understands everything in the form of 0 and 1 only. But different programming languages have different syntax and a different set of keywords. Now the question is how a computer understands the instructions written in the programs or scripts of these languages.

The computer does not understand the instructions directly unless the program is converted to the language that the computer understands. This conversion is known as compilation or interpretation depending upon the language (Whether the language is compiled or interpreted).

Types of a compiler :

Cross compiler: If the operating system of the system on which the compiler is installed is different from the system on which the compiled program runs, the compiler is called a cross compiler.

Bootstrap compiler: A bootstrap compiler is one that is written in the same language of whose programs it compiles.

Native code compiler: This compiler uses only the same operating system on which the particular programming language is assembled. Common advantages of using a native code compiler are better execution, load speed, and security.

Single-pass compiler: A single-pass compiler is one that passes through the parts of each compilation unit only once and translates immediately each part into its machine code.

Two-pass compiler: A two-pass compiler is a compiler that processes the code multiple times. The phases in this compiler are divided into two parts. The first pass consists of the Front end, analytic part, platform-independent.
The second pass refers to the Back end, synthesis part, platform dependent.

Decompiler: The vice versa of a compiler is a decompiler. A decompiler is a computer program or software that translates a code of low-level language to a high-level language.

Features of a compiler –

  • Speed of translation.
  • Better error reporting
  • Recognition of permitted programming constructs.
  • Preserving the code.

What is an interpreter?

An interpreter is another type of computer program or software which converts the code written in a high-level language to a low-level language. Unlike compiler, an interpreter reads every statement and then converts it separately. An interpreter can convert a high-level code into machine code or converts it into an intermediate language code that can be processed further. An interpreter is commonly used in languages that execute on a web server. Some languages that use interpreters are PHP, Python, Ruby, and JavaScript.

One major importance of an interpreter is quick recognition of errors as it executes every statement line by line. It goes onto the next statement only if the error is resolved.

Most of the web scripting languages use interpreters over compiler because of the fact that an interpreter finds errors separately and stops the script for further execution. In this way, the programmer can easily find out the error for fixation.

Note: An interpreter allows analysis and modification of the code while it is already executing.

Differences between compiler and interpreter :

  • A compiler translates the whole code in a single shot while an interpreter translates one line at a time.
  • A compiler does compilation before execution while the interpreter does interpretation and execution simultaneously.
  • Error detection in the compiler is difficult whereas error detection in the interpreter is comparatively easier. Because a compiler displays all of the errors after the whole program is compiled, whereas an interpreter displays errors individually.
  • A compiler generates object code. No object code is generated by an interpreter.
  • C, C++, C# are some of the compiled languages while PHP, Perl, Python, and Ruby are some of the interpreted languages.
  • The compiler needs comparatively more memory because it creates object code. The interpreter needs less memory space because it does not create any object code.
  • A compiler is comparatively faster because it converts the whole code in one single shot. while an interpreter is comparatively slower.

Assembler :

An assembler is a type of language processor that converts programs written in assembly language into machine code. Programs written in assembly language contain mnemonic keywords. Such as ADD, CALL, DEC, etc. These keywords help the programmer to write assembly programs. The assembly language is somehow identical to the machine language (except it uses the mnemonic keywords).

An assembler acts as a bridge between symbol-based coded instructions (which are written in assembly language), the processor, the memory, and other components. In general, an assembler converts the mnemonic code into an object code or an object file containing a series of zeros and ones (machine code).

“The machine code is the only form of code that can be directly processed by the processor!”