Home computickets Difference between compiler and interpreter

Difference between compiler and interpreter




What’s the difference between a compiler and an interpreter? Can a programming language have both a compiler and an interpreter?

Answer 1, authority 100%

To clarify the difference, let’s find out what it is:

A compiler is a program or hardware that performs compilation.

Compilation – translation of a program written in a high-level source language into an equivalent program in a low-level language close to machine code (absolute code, object module, sometimes into assembly language). The input information for the compiler (source code) is a description of the algorithm or a program in a domain-specific language, and the output of the compiler is an equivalent description of the algorithm in a machine-oriented language (object code). Wikipedia

An interpreter is a program (a kind of translator) that performs interpretation.

Interpretation – operator-by-statement (command-by-command, line-by-line) analysis, processing and then immediately executing the original program or request (as opposed to compilation, in which the program is translated without executing it). Wikipedia

Thus, we can conclude that the compiler converts the source code to close to machine code. The interpreter, on the other hand, allows you to perform some representation of the program, converting it into machine code on the fly.

If we take the java language, then it has both a compiler and an interpreter. The compiler converts the source code to bytecode. And the bytecode at the initial stage of program execution is processed by the interpreter.

The compiler is a separate javac program, while the interpreter is built into jvm . In addition to the usual compiler, jvm contains just-in-time compilation. since interpretation is rather slow, hot spots in the program are compiled into machine code jit by the compiler, thereby speeding up execution.

Answer 2, authority 26%

1) The difference is that the compiler converts the code of the algorithmic language into executable (bytecode or native) code (in the limit – into machine codes), while the interpreter independently recognizes and executes line by line instructions of the program code.

2) Yes, it can. Even the ancient turbo / quick basic could. Moreover, Borland Turbo BASIC was “in one bottle”, while Microsoft Quick Basic used, like all modern ones, an external compiler.

UPD: Probably, we can also formulate this: the interpreter for executing the program must have the source code of the program (in the original or formalized form) in the algorithmic language, while compilation creates an executable module that does not contains the text of the program in the algorithmic language. Also, if no debug information is added during compilation, a complete restoration of the source code is not possible.

Answer 3, authority 16%

the interpreter executes the program,
translators incl. compilers convert without executing

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions