The first sequel to the compilation principle

The first sequel to the compilation principle

The structure of the compiler

Insert picture description here

  • The compiler is mainly divided into front-end and back-end

  • Front end: only rely on the source program, independent of the target machine, generate intermediate code

  • Back-end: depends on the target machine, has nothing to do with the source program, only with the intermediate language, the target code is generated from the intermediate code

  • Maybe some people have forgotten what the target code is?
    The target code is mainly machine language or assembly language
    Insert picture description here

  • Obscure language may make it difficult for everyone to understand, so let’s not say the picture above

  • One hundred causes will have results, and people must have their reasons for designing it like this.
    Benefits: It improves the efficiency of developing compilers, which is like building blocks and you can build different things.

  • Take the front end of a compiler and rewrite its back end to generate a compiler of the same source language on another machine (front end: C language, Java language)

  • Different front-ends use the same back-end to get several compilers on one machine (note: the same intermediate language must be used here) (back-end: Mac back-end, Windows back-end, etc.)

all over

  • A scan of the source program or the intermediate representation of the source program, read in a file each pass, perform one or several stages of compilation operations, and output an intermediate representation of the source program
  • The input of each pass is the output of the previous pass, the input of the first pass is the body of the source program, and the output of the last pass is the target code
  • Many passes: the compiler structure is clear, but the time efficiency is not high
  • Few passes: fast compilation speed, but high memory requirements for the machine
    Insert picture description here

Question from the soul: What language was the world's first compiler written in?

The answer is obvious, of course it was developed in machine language

Self-propelled technology

  • It is too much work to write the source language compiler directly in the machine language on the target machine
  • Use the machine language on the target machine to write the compiler of a subset of the source language, and then use this subset as the writing language to implement the compiler of the source language. This is the self-development technology.

Compiler construction tool

  • Lexical analyzer automatically generates programs — LEX
  • Syntax analyzer automatically generates programs — YACC

Language processing system

Insert picture description here

Preprocessor

  • Delete comment
  • Macro expansion
  • Process include files
  • Language expansion

Assembler

  • Process assembly language code to generate relocatable machine code

Assembler, connector

  • Connect and assemble multiple relocatable machine code files into one executable machine code file.

Guess you like

Origin blog.csdn.net/DoMoreSpeakLess/article/details/106897409