Compilation and interpretation

Source: Internet
Author: User

Compilation process overview


Lexical Analysis: scans source programs from left to right character by character to identify word symbols.

Example: regular and automatic machines

 

Syntax analysis-Based on lexical analysis, word sequences are divided into various syntax units based on the syntax rules of the language, such as expressions, statements, and programs.

Example: Type 0 grammar, context-related grammar, and context-independent grammar.

 

Semantic Analysis: Performs Type Analysis and checks. A Data Type in a programming language generally includes two aspects: the type carrier and its operation. For example, the remainder operator can only perform operations on integer data. If there is a floating point in the operation object, it is considered as a Type Mismatch Error.

 

Intermediate code generation-the intermediate code generated based on the output of semantic analysis. Intermediate code is a simple and clearly-defined mark system. It can be in several forms. Their common features are irrelevant to specific machines.

Semantic Analysis and intermediate code generation are based on semantic rules.

 

Code optimization-the optimization process can be performed in the intermediate code generation phase or in the target code generation phase. Optimization is based on the equivalent conversion rule of the program.

 

Target code generation-converts intermediate code into absolute code, relocatable code, or assembly code on a specific machine. The generation of target code is closely related to the specific code.

1. the compiler processes source programs in advanced languages in several stages, including lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and target code generation, among them, intermediate code generation and code optimization are not required by every compiler.


2. The compilation process of an advanced language source program is divided into several stages. The assignment register is used in the code generation phase.


3. When compiling a program to analyze the syntax of the C language source program, you can determine whether the variable is defined or declared.


Explain BASIC Program Principles

 

The interpreter works basically the same as the compiler in terms of lexical, syntax, and semantic analysis. However, when running a user program, it directly executes the intermediate representation of the source program or source program.

The interpreter does not generate the target program of the source program, which is the main difference between it and the compiled program.

 

Differences between compilation and interpretation:

 

· Efficiency: compilation may be more efficient than interpretation. The explanation method may need to scan the source program repeatedly during running. The compilation method creates the target program for a longer time than the explanation time, but the compilation method can be run multiple times.

· Flexibility: The interpreter needs to check the source program repeatedly, so it is more flexible than the compilation method.

· Portability: The interpreter is generally written in a programming language. Therefore, the interpreter can run in different environments as long as it is re-compiled.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.