contador javascript Skip to content
Contact : alejandrasalcedo0288@gmail.com

Difference between compiler and interpreter


A compiler is 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 mimics the execution of programs written in a source language. Another difference between the compiler and the interpreter is that the compiler converts the entire program at once; On the other hand, the interpreter converts the program by taking only one line at a time.

Obviously, the perception of human beings and an electronic device such as a computer is different. Humans can understand anything through natural languages, but not a computer. The computer needs a translator to convert written languages ​​in human readable form to computer readable form.

Compiler and interpreter are the types of language translator. What is the language translator? This question may be emerging in your mind.

A language translator is software that translates programs from a source language that can be read in humans to an equivalent program in an object language. The source language is generally a high-level programming language, and the object language is typically the machine language of a real computer.

Comparative graph

Basis for comparison Compiler Interpreter
Entry One complete program is needed at a time. Take only one line of code or instruction at a time.
Exit Generate intermediate object code. It does not produce any intermediate object code.
Working mechanism The compilation is done before execution. Compilation and execution are performed simultaneously.
Speed Comparatively faster Slower
Memory The memory requirement is more due to the creation of object code. It requires less memory since it does not create an intermediate object code.
The mistakes Show all errors after compilation, all at the same time. Show error of each line one by one.
Error detection Difficult Comparatively easier
Corresponding Programming Languages C, C ++, C #, Scala, typescript uses compiler. Java, PHP, Perl, Python, Ruby uses an interpreter.

Compiler Definition

A compiler is a program that reads a program written in the high level language and converts it into the low level machine or language and reports the errors present in the program. Convert all the source code at once or it may take several passes to do so, but in the end, the user gets the compiled code that is ready to run.

The compiler operates in phases; The different stages can be grouped into two parts that are:

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

Phases of the compiler

Now let's understand in detail the operation of each stage.

  1. Lxico Analyzer : Scan the code as a character stream, group the character sequence into lexemes and generate a token sequence with reference to the programming language.
  2. Syntax analyzer : In this phase, the tokens that are generated in the previous stage are compared with the grammar of the programming language, whether the expressions are synthetically correct or not. It makes the trees stand to do it.
  3. Semantic analyzer : Verify whether the expressions and statements generated in the previous phase follow or not the rule of the programming language and create annotated analysis trees.
  4. Intermediate Code Generator : Generates equivalent intermediate code from the source code. There are many representations of intermediate code, but the TAC (three-way code) is the most used.
  5. Code Optimizer : Improves the time and space requirements of the program. To do this, remove the redundant code present in the program.
  6. Code Generator : This is the final phase of the compiler in which the destination code is generated for a particular machine. Performs operations such as memory management, allocation of records and specific machine optimization.

The symbol table It is, in a way, a data structure that manages identifiers along with the type of relevant data it is storing. The error handler detects, informs and corrects errors that occur between the different phases of a compiler.