Joke Collection Website - News headlines - What can convert a high-level language into an object program is (what can convert a high-level language into an object program is a compiler)

What can convert a high-level language into an object program is (what can convert a high-level language into an object program is a compiler)

Brand model: Lenovo rescuer Y9000P

System: Windows 1 1

It is the compiler that transforms a high-level language into an object program. A program written in a high-level language is called a "source program" and a program expressed in binary code is called an "object program". It is a "compiler" that converts the source program into an object program that can be recognized by a machine. A compiler first translates the whole source program written in a high-level language into a machine language program, and then generates an object program that can be run directly under the operating system.

Compiler, also known as compiler, refers to a translation program that translates a source program written in a high-level programming language into an equivalent target program in machine language format. Compilers belong to translation programs that are realized by generating implementations. It takes the source program written in high-level programming language as input and the target program expressed in assembly language or machine language as output. The compiled target program usually goes through the running phase, so that it can run with the support of the running program, process the initial data and calculate the required calculation results.

Compiler, as an important software tool to realize programming, has been incorporated into the basic software tool of software support environment. Therefore, when planning the implementation scheme of compiler, we should start from the specific software support environment, not only follow the overall requirements and regulations of the whole environment, but also carefully consider the mutual support, cooperation and connection with other software tools.

The process of translating a source program into a target program by a compiler can be divided into five stages: lexical analysis; Grammatical analysis; Intermediate code generation; Code optimization; Object code generation. Mainly lexical analysis and grammatical analysis, also known as source program analysis, in the analysis process, grammatical errors are found and prompt information is given.

1, lexical analysis. The task of lexical analysis is to process the words composed of characters, scan the source programs one by one from left to right, and generate word symbols one by one, thus transforming the source programs as character strings into the intermediate programs of word symbol strings. A program that performs lexical analysis is called a lexical analyzer or scanner.

Using scanner to analyze the word symbols in the source program, it generally produces binary form: word category; The value of the word itself. Parts of speech are usually coded by integers. If a category contains only one word symbol, then the category code completely represents the value of the word symbol itself. If a species contains many character symbols, each character symbol should be given its own value in addition to the species code. Generally speaking, there are two ways to construct lexical analyzer: manual construction and automatic generation. The state diagram can be constructed manually, and the finite automaton can be automatically generated.

2. Grammatical analysis. The parser of the compiler takes word symbols as input, and analyzes whether the word symbol string constitutes a grammatical unit that conforms to grammatical rules, such as expression, assignment, cycle, etc. Finally, see if it constitutes a program that meets the requirements. It analyzes whether each sentence has a correct logical structure according to the grammatical rules used in the language, and the program is the final grammatical unit. Grammatical rules of compiler can be described by context-free grammar.

There are two methods of grammatical analysis: top-down analysis and bottom-up analysis. Top-down means starting from the beginning symbol of grammar, inferring downwards and deducing sentences. The bottom-up analysis method adopts the moving reduction method. The basic idea is: using a high-level post-stack of registered symbols, the input symbols are moved into the stack one by one, and when a generated candidate is formed at the top of the stack, this part of the top of the stack is reduced to the generated left neighbor symbols.

3. Intermediate code generation. Intermediate code is the internal representation of source program or intermediate language. The function of intermediate code is to make the structure of compiler logically simpler and clearer, especially to make the optimization of target code easier to realize. Intermediate code is an intermediate language program, and the complexity of intermediate language is between the source language and machine language. Interlanguage has many forms, such as anti-Polish notation, quaternary, ternary and tree.

4. Code optimization. Code optimization refers to various equivalent transformations of the program in order to generate more effective object code from the transformed program. The so-called equivalence means not changing the running result of the program. The so-called validity mainly refers to the short running time of the target code and the small storage space occupied. This transformation is called optimization.

There are two kinds of optimization: one is to optimize the parsed intermediate code, which does not depend on the specific computer; The other is when generating object code, which depends largely on the specific computer. For the former type of optimization, according to the program scope involved, it can be divided into three different levels: local optimization, circular optimization and global optimization.

5. Object code generation. The generation of object code is the last stage of compilation. The target code generator converts the parsed or optimized intermediate code into the target code. There are three forms of object code: machine language code that can be executed immediately, and all addresses are relocated; When the machine language module to be assembled needs to be executed, it is connected with some running programs through the connection loader and converted into executable machine language codes; Assembly language code must be assembled into executable machine language code by assembler.

In the stage of object code generation, we should consider three problems that directly affect the speed of object code: first, how to generate shorter object code; Secondly, how to make full use of the registers in the computer and reduce the number of times that the target code accesses the storage unit; Thirdly, how to make full use of the characteristics of computer instruction system to improve the quality of object code.

Heart of the King 2 Click on the demo.