Note: This article refers to Li Wensheng teacher handouts. If you have any irregularities, please contact the programming language in time.
A tool for communication between people and computers. Low-level language machine language symbol language assembler
Question: What is the symbolic language? Advanced language Procedural language--user-oriented language such as: C, Pascal-specific language-problem-oriented languages such as: SQL
Advantages: independent of the machine. The program portability is better without considering the allocation of storage units, the external situation of data conversion into the internal situation of machines and other details with rich data structure and control structure more close to natural language programming efficiency High translation program
source program (Advanced language/assembly language) ——— (after) translation program--> (obtained) target program (target language, where the target is not necessarily machine language)
Assembler Program--Assembler program--Machine language Program
Advanced Language Program--compiler program--Low-level language program
Advanced Language Program: The compile phase processes the source program, the execution phase processes the data.
An interpreter processes both source and data. The execution is performed on the side of the interpretation and the target program is not generated.
Explain the pros and cons of the program
Advantages: Easy to communicate with users, compared to save memory space
disadvantage: Inefficient
solution: first translated into some intermediate form of the program, such as Java
Composition of the compiled program
Analysis phase (static analysis)
According to the definition of the source language, analyze the structure and semantics of the source program (the program source code is converted to some internal representation) lexical analysis-lexical analyzer-identify the strings with independent meaning as token (notation), and the grammatical analysis of marked flow------------------- Form grammatical phrase--analytic tree to express semantic analysis--semantic analyzer--check the meaning of the statement according to the semantic rules of the source language (such as type checking)
Integrated phase
According to the analysis result constructs the required target program intermediate code generation--the intermediate code is easy to translate into the target Code code optimization--improves the code, makes it occupy less space, runs fast (first is in the intermediate code) the target code generation-- The generated target code is typically machine code or assembly language code that can be relocated
Management error diagnosis and processing of symbol tables
Typical structure of compiling principle
Symbol Table Management
Documenting the identifiers used in the source program, and collecting various attribute information for each identifier is an important work of compiling the program.
Symbol table: A data structure consisting of several records each identifier has a record in the table. The field of the record is the attribute of the identifier
Requirements for a symbol table structure: A record that allows quick lookup of an identifier to access data in it
The various attributes of an identifier are filled in the symbol table at various stages of compilation. Preprocessor
Main function: Macro processing file contains language Extension connection assembly procedure
Two main tasks:
Load: Read the relocatable machine code modify the relocation address to place the modified instructions and data in the appropriate places of memory or to form an executable file
The connection connects several relocatable machine codes into an executable program.