The compiler and interpreter confusion - WIP

work in progress..

I’ve seen people getting confused with whether the language is of compiler and interpreter type, people often say python/perl/ruby.. are just interpreted languages.

Wikipedia say’s…

The compiler

A compiler is a computer program that translates computer code written in one programming language (the source language) into another programming language (the target language). The name compiler is primarily used for programs that translate source code from a high-level programming language to a lower level language (e.g., assembly language, object code, or machine code) to create an executable program.

As per the definition:

  • There is no hard rule that the outcome of compiling process is a machine level executable.

The interpreter

In computer science, an interpreter is a computer program that directly executes, i.e. performs, instructions written in a programming or scripting language, without requiring them previously to have been compiled into a machine language program. An interpreter generally uses one of the following strategies for program execution:

  • parse the source code and perform its behavior directly;
  • translate source code into some efficient intermediate representation and immediately execute this;
  • explicitly execute stored precompiled code[1] made by a compiler which is part of the interpreter system.

As per the definition:

  • Interpreters doesn’t always read the source directly and execute.

How to understand a language is compiled or interpreted?

Most of the modern high level languages try to escape redundant work they do to execute a program, they don’t have to perform [ parse -> tokenize -> create AST -> decide the control flow ] for every execution of a program, it can be simply cached and used at every execution until there is a change to the source. This is how they inroduced a program to transform the source into intermediate representation, it’s mostly called as the bytecode, What do we have to call this process? why not compiling?

As per the definition, compiler is just a program that transform the source into target. High languages are doing the same in the execution process, they maintain a compilation phase inbetween and cache the outcome as they can be used until the change is necessary.

Published: March 11 2019

  • category:
blog comments powered by Disqus