contador Saltar al contenido

Difference between compiler and interpreter

A compiler a translator that transforms the source language (high level language) into object language (machine language). In contrast to a compiler, an interpreter is a program that imitates the execution of programs written in a source language. Another difference between compiler and interpreter that the compiler converts the whole program in one fell swoop, while the interpreter converts the program taking a single line at a time.

Evidently, the perceptibility of human beings and an electronic device such as a computer are different. Humans can understand anything through natural languages, but not a computer. The computer needs a translator to convert written languages ??into human readable form into computer readable form.

Compiler and interpreter are the types of linguistic translator. What is the language translator? This question could arise in your mind.

A linguistic translator is a software that translates programs from a source language that are in a readable form into an equivalent program in an object language. The source language generally a high-level programming language and the language of the object generally the machine language of a real computer.

Comparative graph

Basis for comparisonCompilerInterprete
Entrance It takes an entire program at a time. It takes a single line of code or instruction at a time.
Production Generate intermediate object code. It does not produce any intermediate object code.
Work mechanism The compilation is performed before execution. Compilation and execution take place simultaneously.
speed Comparatively faster More slowly
Memory The memory requirement is more due to the creation of the object code. It requires less memory as it does not create an intermediate object code.
Mistakes Show all errors after compilation, all at the same time. Display the error of each line one by one.
Error detection Difficult Easier in comparison
Related programming languages C, C ++, C #, Scala, typescript use the compiler. Java, PHP, Perl, Python, Ruby uses an interpreter.

Definition of the compiler

A compiler a program that reads a program written in the high-level language and converts it into the low-level machine or language and reports errors in the program. It converts the entire source code in one go or it may take several steps to do it, but eventually the user gets the compiled code that is ready to run.

The compiler works on phases; various phases can be grouped into two parts which are:

  • Analysis The phase the compiler is also defined as the front-end in which the program is divided into fundamental constituent parts and controls the grammar, semantics and syntax of the code after which the intermediate code is generated. The analysis phase includes lexical analyzer, semantic analyzer and syntax analyzer.
  • The phase of synthesis compiler also known as a backend where the intermediate code is optimized and the target code is generated. The synthesis phase includes code optimizer and code generator.


Now we understand the workings of each phase in detail.

  1. Lexical analyzer : analyzes the code as a flow of characters, groups the sequence of characters into lexemes and generates a sequence of tokens with reference to the programming language.
  2. Syntax Analyzer : in this phase, the tokens generated in the previous phase are compared with the grammar of the programming language, regardless of whether the expressions are syntactically correct or not. Makes the trees seem to do it.
  3. Semantic Analyzer : checks if the expressions and instructions generated in the previous step follow the programming language rule or not and creates annotated analysis trees.
  4. Intermediate code generator : generates an equivalent intermediate code of the source code. There are many representations of the intermediate code, but the TAC (Three Address Code) is the most used.
  5. Code Optimizer : improves the time and space required by the program. To do this, delete the redundant code in the program.
  6. Code generator : this is the final stage of the compiler where the destination code is generated for a particular machine. It performs operations such as memory management, register assignment and machine-specific optimization.

There symbol table in some way a data structure that manages the identifiers along with the type of relevant data it is storing. Error Handler detects, reports, corrects errors encountered between the different phases of a compiler.

Definition of an interpreter

The interpreter is an alternative for implementing a programming language and does the same job as a compiler. The interpreter executes lexing, analysis is type check similar to a compiler. But the interpreter processes the syntax tree directly to access expressions and execute the statement rather than generate code from the syntax tree.

An interpreter may require processing the same syntax tree more than once, which is why the relatively slower interpretation of the compiled program execution.

Compilation and interpretation probably combine to implement a programming language. Where a compiler generates intermediate level code, the code is interpreted rather than compiled into machine code.

The use of an advantageous interpreter during the development of the program, in which the most important part consists in being able to quickly test a modification of the program rather than running the program efficiently.

Key differences between compiler and interpreter

Let's take a look at the main differences between compiler and interpreter.

  1. The compiler takes a program as a whole and translates it, but the interpreter translates a program statement by instruction.
  2. Intermediate code or target code generated in the case of a compiler. As a counter-interpreter it does not create an intermediate code.
  3. A comparatively faster compiler than the interpreter because the compiler takes the whole program at once, while the interpreters compile each line of code after another.
  4. The compiler requires more memory than the interpreter due to the generation of the object code.
  5. The compiler presents all the errors simultaneously and it is difficult to detect errors in the interpretation of the contrast performer of each instruction one by one and it is easier to detect errors.
  6. In the compiler when an error occurs in the program, it stops its translation and after removing the error, the entire program is translated again. Conversely, when an error occurs in the interpreter, it prevents its translation and after removing the error, the translation resumes.
  7. In a compiler, the process requires two steps in which first the source code is translated into the destination program, then executed. While you are in Interpreter a one-step process in which the source code is compiled and executed at the same time.
  8. The compiler used in programming languages ??like C, C ++, C #, Scala, etc. In the other interpreter employed in languages ??like Java, PHP, Ruby, Python, etc.


Both the compiler and the interpreter intend to perform the same job, but differ in the operating procedure, the compiler takes the source code in an aggregate way while the interpreter takes constituent parts of the source code, that is, declaration by declaration.

Although both the compiler and the interpreter have some advantages and disadvantages, as interpreted languages ??are considered as multiplatform, that is the portable code. Moreover, it does not need to compile instructions previously, unlike the compiler, which saves time. The compiled languages ??are faster for the compilation process.