Compiler theory essays 1

<!doctype html>

Compiler theory

 

Compiler theory Overview

1, the compiler concepts:

  • From the high-level language -> Process object code (assembly language or machine code)

2, the structure of the compiler:

  • Analysis portion / distal end (front end) -> associated with the source language

    1. Lexical analysis lexical unit stream >>
    2. >> parsing parse tree parse tree
    3. Semantic analysis syntax tree >>
    4. Intermediate code generating intermediate representation >>
    5. Machine independent code optimization
  • Integrated part / back-end (back end) -> associated with the target language

    1. Target code generation target machine language >>
    2. Machine-dependent code optimization target machine language >>

3, lexical analysis

  • main mission:

    • Scan source -> the identification of each word -> determining the type of word -> the recognized word into the machine represented (i.e.: means lexical token)

    • token: <Do Species Code: attribute value>

      • Type the word Other species Species do not code
        Keyword if, etc. The term one yards
        Identifier Variables, arrays, procedure ...... Multi-word one yards
        constant   Multi-word one yards
        Operators Arithmetic operators: + -
        relational operators:> <==
        Logical operators: & ||!
        The term one yard
        a type one yards
        Delimiter ;{}()=…… The term one yards

       

4, parsing

  • Concept: The parser Parser token from the lexical analyzer output, the identification of various types of phrases constructed parse tree parse tree
  • 1563886893948
  • 1563887016328

 

5, semantic analysis

  • main mission:

    • Attribute-information collection identifier - >>> stored in the symbol table Symbol Table in

      1. 种属 kind
      2. Type type
      3. Storage location, length
      4. value
      5. Scope
      6. Information parameters and return values
      7. 1563887456617
    • Semantic checks:

      1. Or process variables without declaration will use
      2. ...... repeated statement
      3. Arithmetic component type mismatch (error or casts)

6、中间代码生成

  • 中间表示形式:

    • 三地址码Three-address Code

      • 1563888449816

      • 三地址指令的表示形式:

        • 三元式

        • 间接三元式

        • 四元式

          • 1563888570767
          • 1563888909029
    • 语法结构树/语法树Syntax Tree

7、目标代码生成:

  • 中间表示形式作为输入,映射到目标语言

    • 重要作用:为程序变量使用分配寄存器

8、代码优化

  • 等价程序变换,使其运行快,占内存少。

 

Guess you like

Origin www.cnblogs.com/sqchao/p/11234860.html