Compilation principle_P1001

1 Most software is written in high-level programming languages. Software written in these languages ​​must be compiled by a compiler to be converted into machine code that can be run on a computer. The correctness and quality of the code generated by the compiler directly affects thousands of pieces of software. While most people won't be involved in designing compilers, having knowledge of compilers will have a beneficial effect on their research and development feast.

2 Introduction

3 Have a deep understanding of the design and implementation of programming languages, have an understanding of the theories related to programming languages, and play a click role in grasping programming languages ​​on a macro level. From the perspective of software functions, the compiler is a good tool Examples of introduced concepts and techniques refer to software design in general.

  translator, compiler, interpreter

3.1 The compiler can logically be layered into several stages, and each stage changes the source program from one representation to another interpretation

Source Program----Lexical Analyzer----Syntax Analyzer----Semantic Analyzer----Intermediate Code Generator----Machine Independent Code Optimizer----Code Generator- --- Machine Dependent Code Optimizer --- Target Machine Code

Symbol table

3.2 Lexical Analyzer

3.3 Parser

grammatical features of expressions

3.4 Semantic Analyzer

3.5 Intermediate code generator

3.6 Code Optimizer

3.7 Code Generator

3.8 Differences between interpreters and compilers

The interpreter does not generate object code, but directly executes the operation specified by the source program

3.9 Interpreters in the BASIC Era

  Function: Translate the source program of a high-level language into an intermediate language program, and then interpret and execute the intermediate language program. In those days, in the program in which the two functions of compilation and interpretation were combined, the modified program was called an interpreter.

  Interpreters in the Java era

  The above two functions are in two programs. The former is called the compiler, which translates the source program into an intermediate language program called byte code, and the latter is called the interpreter, which interprets and executes the byte code program.

 3.10 Stage grouping (front-end and back-end, pass (number of scans, write to external memory, C language scans on both sides))

 

4. Application of Compiler Technology

The emergence of each round of high-level languages ​​stimulates new research in compiler optimization, supporting user-defined aggregate data types and high-level control flow, the main concepts of object orientation are data abstraction and property integration, and yes, programs are more modular and easier to maintain, type Safe language: Java does not have pointers and does not allow pointer arithmetic. C language is not a type-safe language. It uses garbage collection mechanism to automatically free the memory occupied by variables that are not in use. Java is designed to support code porting

 

5. Lexical Analysis

      

 

Guess you like

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