Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does an interpreter/compiler work

How does an interpreter/compiler work? What is the difference between interpreter and compiler.

like image 994
developer Avatar asked Mar 04 '10 06:03

developer


People also ask

How does an interpreter language work?

In a compiled language, the target machine directly translates the program. In an interpreted language, the source code is not directly translated by the target machine. Instead, a different program, aka the interpreter, reads and executes the code.

How does interpreter work example?

An Interpreter directly executes instructions written in a programming or scripting language without previously converting them to an object code or machine code. Examples of interpreted languages are Perl, Python and Matlab. Following are some interesting facts about interpreters and compilers.

How does an interpreter process a program?

You write the program using a text editor or something similar, and then instruct the interpreter to run the program. It takes the program, one line at a time, and translates each line before running it: It translates the first line and runs it, then translates the second line and runs it etc.

How do interpreters execute code?

Unlike a compiler, it doesn't translate everything and hand over a file to us, the programmers, to execute. Instead, an interpreter will translate a single line/section of code at a time. Once it has finished translating one line, it will take the machine code version of it, and run it immediately.


1 Answers

Compilers

Compilers were the first sort of translator program to be written. The idea is simple: You write the program, then hand it to the compiler which translates it. Then you run the result.

Interpreters

An interpreter is also a program that translates a high-level language into a low-level one, but it does it at the moment the program is run. You write the program using a text editor or something similar, and then instruct the interpreter to run the program. It takes the program, one line at a time, and translates each line before running it: It translates the first line and runs it, then translates the second line and runs it etc.

Compiler characteristics:

  • spends a lot of time analyzing and processing the program
  • the resulting executable is some form of machine- specific binary code
  • the computer hardware interprets (executes) the resulting code
  • program execution is fast

Interpreter characteristics:

  • relatively little time is spent analyzing and processing the program
  • the resulting code is some sort of intermediate code
  • the resulting code is interpreted by another program
  • program execution is relatively slow
like image 65
Adriaan Stander Avatar answered Sep 19 '22 01:09

Adriaan Stander