Compiler - 编译器
Compiler - 編譯器
intermediate representation,IR:中間表示 front end,FE:前端 middle end,ME:中端 back end,BE:后端The first compiler was build by John Backum and his group between 1954 and 1957 at IBM.
編譯器就是將高級語言翻譯為低級語言的程序。
1. What is a Compiler?
A compiler is a computer program which helps you transform source code written in a high-level language into low-level machine language. It translates the code written in one programming language to some other language without changing the meaning of the code. The compiler also makes the end code efficient which is optimized for execution time and memory space.
編譯器是一種計算機程序,可以幫助你將以高級語言編寫的源代碼轉換為低級機器語言。它將以一種編程語言編寫的代碼轉換為另一種語言,而無需更改代碼的含義。編譯器對代碼執行時間和存儲空間進行優化,使最終代碼高效率。
The compiling process includes basic translation mechanisms and error detection. Compiler process goes through lexical, syntax, and semantic analysis at the front end, and code generation and optimization at a back end.
編譯過程包括基本的轉換機制和錯誤檢測。編譯器過程在前端進行詞法,語法和語義分析,在后端進行代碼生成和優化。
front end: lexical, syntax, and semantic analysis
back end: code generation and optimization
2. 編譯器類型
2.1 Single Pass Compilers
In single pass Compiler source code directly transforms into machine code. For example, Pascal language.
2.2 Two Pass Compilers
Two pass Compiler is divided into two sections, viz.
The Two pass compiler method also simplifies the retargeting process. It also allows multiple front ends.
videlicet [v?'del?s?t]:adv. 即 viz. [v?z]:adv. 即,就是2.3 Multipass Compilers
The multipass compiler processes the source code or syntax tree of a program several times. It divided a large program into multiple small programs and process them. It develops multiple intermediate codes. All of these multipass take the output of the previous phase as an input. So it requires less memory. It is also known as ‘Wide Compiler’.
multipass compiler 會多次處理程序的源代碼或語法樹。它將一個大型程序劃分為多個小型程序并進行處理。它開發了多個中間代碼。所有這些多通道都將前一階段的輸出作為輸入。因此,它需要更少的內存。它也被稱為 Wide Compiler。
3. Language processing systems
源代碼 (source code) -> 預處理器 (preprocessor) -> 編譯器 (compiler) -> 目標代碼 (object code) -> 鏈接器 (Linker) -> 可執行程序 (executables)
Preprocessor: The preprocessor is considered as a part of the Compiler. It is a tool which produces input for Compiler. It deals with macro processing, augmentation, language extension, etc.
預處理器被視為編譯器的一部分。它是為編譯器生成輸入的工具。它處理宏處理,擴充,語言擴展等。
Interpreter: An interpreter is like Compiler which translates high-level language into low-level machine language. The main difference between both is that interpreter reads and transforms code line by line. Compiler reads the entire code at once and creates the machine code.
解釋器就像編譯器一樣,可以將高級語言翻譯成低級機器語言。兩者之間的主要區別是解釋器逐行讀取和轉換代碼。編譯器立即讀取整個代碼并創建機器代碼。
Assembler: It translates assembly language code into machine understandable language. The output result of assembler is known as an object file which is a combination of machine instruction as well as the data required to store these instructions in memory.
它將匯編語言代碼轉換為機器可理解的語言。匯編器的輸出結果稱為目標文件,該文件是機器指令以及將這些指令存儲在內存中所需的數據的組合。
Linker: The linker helps you to link and merge various object files to create an executable file. All these files might have been compiled with separate assemblers. The main task of a linker is to search for called modules in a program and to find out the memory location where all modules are stored.
鏈接器可幫助您鏈接和合并各種目標文件以創建可執行文件。所有這些文件可能都已使用單獨的匯編器進行了編譯。鏈接器的主要任務是在程序中搜索被調用的模塊,并找出所有模塊的存儲位置。
Loader: The loader is a part of the OS, which performs the tasks of loading executable files into memory and run them. It also calculates the size of a program which creates additional memory space.
加載程序是操作系統的一部分,它執行將可執行文件加載到內存中并運行它們的任務。它還計算程序的大小,該程序將創建額外的內存空間。
Cross-compiler: A cross compiler is a platform which helps you to generate executable code.
交叉編譯器是一個可幫助您生成可執行代碼的平臺。
Source-to-source Compiler: Source to source compiler is a term used when the source code of one programming language is translated into the source of another language.
源到源編譯器是將一種編程語言的源代碼轉換為另一種語言的源時使用的術語。
4. Compiler Construction Tools
These tools use specific language or algorithm for specifying and implementing the component of the compiler.
這些工具使用特定的語言或算法來指定和實現編譯器的組件。
Scanner generators: This tool takes regular expressions as input. For example LEX for Unix Operating System.
該工具將正則表達式作為輸入。例如,用于 Unix 操作系統的 LEX。
Syntax-directed translation engines: These software tools offer an intermediate code by using the parse tree. It has a goal of associating one or more translations with each node of the parse tree.
這些軟件工具通過使用解析樹提供中間代碼。它的目標是將一個或多個轉換與解析樹的每個節點相關聯。
Parser generators: A parser generator takes a grammar as input and automatically generates source code which can parse streams of characters with the help of a grammar.
解析器生成器將語法作為輸入,并自動生成可在語法幫助下解析字符流的源代碼。
Automatic code generators: Takes intermediate code and converts them into Machine Language
接受中間代碼并將其轉換為機器語言。
Data-flow engines: This tool is helpful for code optimization. Here, information is supplied by user and intermediate code is compared to analyze any relation. It is also known as data-flow analysis. It helps you to find out how values are transmitted from one part of the program to another part.
該工具有助于代碼優化。在此,信息由用戶提供,并且將中間代碼進行比較以分析任何關系。也稱為數據流分析。它可以幫助您了解如何將值從程序的一個部分傳輸到另一部分。
References
https://www.guru99.com/compiler-design-tutorial.html
http://personal.kent.edu/~rmuhamma/Compilers/MyCompiler/phase.htm
總結
以上是生活随笔為你收集整理的Compiler - 编译器的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 老毛桃重启计算机没反应,遇到电脑无法启动
- 下一篇: 密码学--对称加密和非对称加密联合使用