A job (compiler, assembler, compiler translation and Ark)

(1) Description of the compiler and translator, assembler connections and differences of the program.

         Translation program refers to the translation of high-level language source code into machine language source code (object code) software.

         Translation program, there are two: one is the compiler, it will be high-level language source programs all at once translated into the target program, each time the execution of the program, as long as the target program.

            Another is to explain the program, its execution is a translation of an execution, and do not generate the target program.

    The compiler is a program that runs after the first complete compiler, such as C, C ++ and so on; is an interpreter and a translator translate and program execution, such as JavaScript, Python and so on.

         The assembler is a language translation program that translates assembly language source code into machine language program.

         The difference between the compiler and assembler: if the source language such as C, C ++, Java and other "high-level language", and the target language such as assembly language or machine language like "low-level language," such a translation program called a compiler program.

         If the source language is assembly language and the target language is the machine language, such a translation program called assembler.

(2) the compilation process, including the main function of which several main stages and each stage.

Lexical tasks: input source program, the source string is scanned and constituting an exploded, one word identified. 

Word: Is there a minimum level language syntax unit of real significance, which consists of characters.

In accordance with the rules of lexical lexical analysis, identify the correct word, converted into a unified specification, set aside.

Lexical rules effective tool for formal description of formula and finite automata.

 

Gramma analysis

Task: according to the syntax rules of the language, the word streams of all kinds of grammatical units, such as: phrases, sentences, processes, procedures

Grammar rules: rules of the language, also known as grammar; how to provide words to form phrases, statements, processes and procedures.

         Grammar rules are usually described by context-free grammars.

 

Parsing There are two ways:

Deriving (Derive) and protocols (the Reduce)

 

Parsing process can also be used to represent an upside down tree, the tree is called a parse tree

 

Semantic Analysis

Task: semantic correctness of the test program, the program to ensure that the parts are joined together meaningfully, the type of collection information generation stage subsequent code

The important work of the semantic analysis phase: type checking

 

Intermediate code generation

Task: generating a cross between an intermediate code between source and object code language in accordance with semantic rules.

The intermediate code is not tied to a construction machine but it is easy to generate object code that depends on the machine simple, unambiguous notation system

Intermediate code format 

  Reverse Polish Notation, quaternary type, three type

 

Code optimization

Task: The preceding intermediate code generated by conversion processing, in order to produce more efficient object code in the final stage.

 

Principles: the equivalent transformation 

 

Main areas: common sub-expressions to extract, merge a known quantity, delete unwanted statements, loops, optimization

Target code generation

Task: the optimized intermediate code is converted into low-level language code on a particular machine 

In object code form 

Absolute instruction code: object code can be executed immediately. 

Assembler instruction code: an assembly language program, to run through the need to compile assembler. 

Relocatable instruction codes: first connecting respective target module, determining a variable, constant position in the main memory, the main memory can be loaded absolute instruction code can be run.

Guess you like

Origin www.cnblogs.com/nazhabanma/p/11468554.html