Home>Article> What is the difference between interpreter and compiler?

What is the difference between interpreter and compiler?

不言
不言 Original
2019-03-08 10:19:24 43394browse

The difference between an interpreter and a compiler is: 1. An interpreter is a program that directly executes instructions written in a programming language, while a compiler is a program that converts source code into a low-level language that translates; 2. Compiler Generates a stand-alone program, whereas interpreted programs always require an interpreter to run.

What is the difference between interpreter and compiler?

Interpreter:A program that directly executes instructions written in a programming language.

Compiler:A program that converts (translates) source code into a low-level language.

The compiler compiles each statement of the source program into machine language and saves it into a binary file. In this way, the computer can directly run the program in machine language at runtime, which is very fast;

The interpreter only interprets the program one by one into machine language for the computer to execute, so the running speed is not as fast as the compiled program.

The compiler generates a stand-alone program, while an interpreted program always requires an interpreter to run.

If you have a compiled program, you don't need to install anything else to run it, making distribution very simple. Executables, on the other hand, run on a specific platform: different operating systems and different processors require different compiled versions.

If the program is to be interpreted, identical copies on different platforms can be distributed to users. However, they require an interpreter that runs on their specific platform. So source code or intermediate products can be distributed.

It is easier to create cross-platform programs using interpreted programming languages.

Compiled programs execute much faster than interpreted programs, but that's just the tip of the iceberg. To put it simply, in terms of execution, it is true that compiled programs that are compiled and executed execute faster, but the compilation and execution time of compiled programs is longer than the time of interpretation and execution of interpreted languages.

The compiler does produce faster programs because it must analyze each statement once, while the interpreter must analyze it every time. In addition, the compiler can also optimize the executable code it generates. . This is both because it knows exactly where it will run and it takes time to optimize the code.

The above is the detailed content of What is the difference between interpreter and compiler?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn