[] Learning compiler theory 1- Introduction Notes

1.     Compile

Compile a translation, just to translate English into Chinese, the compiler usually refers to translate a programming language into machine language the computer can understand.

Compilers and interpreters : one-time programming language compiler fully translated into machine language, form a "executable", can be run repeatedly without further explanation, it can be understood as an English translation of the novel into Chinese and record . And while the interpreter interpreted programming language while running, but also to run again reinterpreted, like simultaneous interpretation.

2. The     compilation process

Compilation process is divided into lexical analysis, parsing and code generation, code optimization machine-independent, object code generation, code optimization target.

Lexical : basic elements of any language is the word, is the lexical category of a word, such as the Chinese word usually divided into verbs, nouns, adjectives, adverbs, etc., each of which represents a different category of use.

Lexical analysis : lexical analysis is to classify the input word string, and converts them to a more suitable storage machine, which we call lexical unit (token).

Grammar and syntax analysis : the syntax is different words according to certain rules make up phrases. The syntax lexical analysis is to analyze token sequence generated in accordance with the rules to find the phrase, it is to analyze the relationship between the individual words, phrases and record suitable for machine understanding of data structures.

Semantic Analysis : In natural language translation, the so-called semantic fact, how to interpret the phrase in English with Chinese. Semantic analysis is to be construed as an identifier of the phrase structure understood by the computer, for the variable, is a variable type, storage location, length, value, etc., and for the function, the function is the scope, parameters, return values. In addition, you also need to check whether the semantics does not comply with the rules.

Intermediate Language : Just like there are many Chinese dialects, although similar principles of modern computers, but the machine does not do the same language, so the machine language often varies depending on the platform, the source language is first translated into an intermediate language excessively, and be optimization. Intermediate language relative to the source language into machine language translation easier and more versatile, it is also referred to as machine-independent code, just like you would a dialect but English and Mandarin dialect translation and experts will not only Mandarin and dialects, you want to be translated into English dialect of Mandarin will need to be translated into this relatively more universal language.

Object code generation : intermediate language is mapped to the target language, an important task in this process is a reasonable allocation register for the variable in the program.

Guess you like

Origin www.cnblogs.com/tiumo/p/12664755.html