Compilation principle_P1004

Summary of knowledge points related to the Dragon Book

//*************************Introduction********************* ****************//

1.  Compiler : The process of translating programs written in one language (source program) into another language (target language). If the target language is an executable machine language, then it can be invoked by the user to process input and produce output.

2.  Interpreter (interpreter) : can generally be considered as the first half of the compiler process, which does not generate the target language.

3.  Common language processing system flow chart :

  The above is a macro interpretation compiler. In a micro perspective, the compiler belongs to the middle part of the whole "compilation process".

  Process:

  source program → ( preprocessor ) → preprocessed source program → ( compiler ) → object assembler → ( assembler ) → relocatable machine code → ( linker/loader ) → object machine code

3.1  Preprocessor : Responsible for converting the abbreviated forms of macros into statements in the source language.

3.2  Macro (mirco) : Some compiled instruction sets or program sets.

3.3  Assembler (assembler) : The work of remotely assembling pseudocode or machine code.

3.4  Relocation : The process of converting the logical address space of the program into the actual physical space in the memory, that is, the process of modifying the instructions and data in the target program when loading.

3.5  Linker : Relocatable machine code must be linked with other relocatable object files and library files to form code that runs on the real machine. Code in one file may point to a location in another file, and the linker is how relocatables operate. (This step is the real conversion of language to machine language to form an exe or other executable file)

3.6  Loader (loader) : Put all executable object files into memory for execution.

4.  Compiler logic structure :

  If the compiler is regarded as a black box, after receiving the preprocessed source program, it will go through the following steps to generate the target assembler (also called the target and its language) and throw it to the compiler:

  (symbol table)

  character flow → (lexical analyzer) → symbol flow → (syntax analyzer) → syntax tree → (semantic analyzer) → syntax tree → (intermediate code generator) intermediate representation → (machine independent code optimizer) → intermediate Representation → (Code Generator) → Target Machine Language → (Machine Dependent Code Optimizer) → Target Machine Language

  The red part is called the front end, and the blue part is also called the back end; these two parts are also divided into analysis and synthesis. It is divided by intermediate code.
5.   A brief description of the symbol table :
  The first step of the compiler is lexical analysis or scanning, which organizes them into meaningful lexemes. In fact, the symbol table is similar to a form of "Mars text" or a carrier, which splits the character stream into one by one The lexical unit (token, some textbooks are called marks or symbols), as output to the following, after the organization is completed, the character stream becomes a symbol stream.
  The symbol table generally has the following definitions:
  <token-name,attribute-value>
  <identifier, identifier attribute>
  Examples of textbooks:
  position = initial + rate * 60
  A stream of symbols is generated by representing the lexical units in the symbol table as follows:
  <id,1><=><id,2><+><id,3><*><60>, each angle bracket is a lexeme, the id is called an identifier, and sometimes a number It is itself an identifier, or a token.
6.   The main idea of ​​object-oriented : data abstraction and feature inheritance, modularization
7.   Parallelism and memory hierarchy
  Parallel: CPU
  Memory Hierarchy: Cache Cache
8.   RISC and CISC
  Reduced instruction set computers and complex instruction set computers, most of Intel's current intel are complex instruction set computers, but the heat is large and the power consumption is high. x86 machines.
9.   SQL
  structured Query Language, structured query language
10.   Environment and Status
  Environment: A map of names to storage locations. Since variables refer to memory locations, we can also define the environment as a mapping from names to variables.
  state: is the mapping of memory locations to them
  In C language, the environment is an lvalue, and the state is an rvalue
11.   Static Scope and Block Structure
  Block: The most intuitive in C is to use { } to define, scope: the variable works in that area.
12.   Statements and Definitions
  The declaration generally refers to specifying the type of the variable, and the definition generally refers to the assignment process of the variable.
13.   The analogy between dynamic scope and static scope
  While there can be a variety of dynamically or statically scoped strategies, there is an interesting relationship between the usual (block-structured) static scoping rules and the usual dynamic strategies. In a sense, the way dynamic rules handle time is similar to the way static scope handles space. The static rule asks us to look for the declaration bit and the innermost unit (block) that contains where the variable is used; while the dynamic rule asks us to look for the declaration in the innermost unit (procedure call) that contains the time when the variable is used.
  location and time
  space and process
14.   Call by value and call by reference
  call-by-value: evaluate the argument (if it is an expression) or copy (if it is a variable)
  Call-by-Reference: The address of the actual parameter is passed to the caller as the value of the corresponding formal parameter.
  This is like calling by reference in high-level languages. When using a function, the address of the actual parameter is sent to the formal parameter of the function, and the formal parameter gets the address of the actual parameter to call the relevant expression or variable.
15.   Aliases
  This problem is most common with shallow and deep copies. Two formal parameters will point to the same object, causing modification of one variable to change the value of the other. In addition, when declaring variables, remember to try not to duplicate names. (It is also possible in some feature environments)
16.   A regular expression is an algorithm
 
 
 
//**************************** A Simple Syntax Guided Translator **************** ********************//
 
 
 
 
 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325293867&siteId=291194637