Domov technika Compilation principle (understand compilation principle from actual combat)

Compilation principle (understand compilation principle from actual combat)



Essence

The essence of the principle of computer program compilation is to translate a high-level language program code stream that programmers can easily understand into a computer executable machine instruction code stream. You can use "One Break, Two Comparisons, Three Translations" to illustrate the essence.

1, off. Scan Word Break according to the grammatical rules of the language, and combine the grammar dictionary to decompose the program string stream into basic units (identifiers, operators) that can be recognized by computer language.

2, Compared. Find the definition of the extended identifier from the program flow, establish the structure of the identifier, and put it into the grammar dictionary to serve the new definition and the compilation of the function program code. The identifiers used in program statements and expressions can be found in the dictionary.

3, Translation. Translate the arithmetic expressions, assignment statements, and control statements in the text string stream of the function program into a computer machine language binary code stream.

4. Assemble the binary code stream after function translation, clarify the address and size of the data space, and generate the bare computer or operating system that can execute the target code.

Grammar

"Grammar is a tool to describe infinite sets with finite sets". The finite sets should have appeared. People Generally accepted words, phrases or sentences, an infinite set is a finite set of words, phrases, or sentences. The process and result of creating a new set is awaiting further understanding and acceptance.

Our grammar stipulates the connotation that has been clearly defined and is being defined (declared). Reflected in the computer language program is the character or string that has been defined and is being defined (declared) during programming. The grammar can be stored in the form of a table or a dictionary.

Syntax

Use "三二术" instead of "Syntax Tree".

Regardless of whether it is a constant, object variable, function, or "()", the expression can be regarded as an intermediate quantity with output

quantity 1 + quantity 2-quantity 3 * quantity 4 & Quantity 5 > Quantity 6

According to the order from front to back of the expression, first take the three quantities of the expression and two calculation symbols, and first calculate the two quantities and one symbol, and store the result in Among the intermediate quantities, the expressions are then taken in order of one sign and one quantity to become a new three quantities and two signs, repeating the calculation of two quantities and one sign in priority, until there are two quantities and one sign, and then the final calculation result is obtained.

Comparison

Compared with the general compilation principle (picture), the similarities and differences between the two compilation techniques can be seen from the picture.

Tento článek je ze sítě, nereprezentuje pozici této stanice. Uveďte prosím původ dotisku
HORNÍ