标签:target language 读书笔记 into source program Techniques Tools compiler
-
Compiler
Programming languages are notations for describing computations to people and to machines.
Before a program can be run, it first must be translated into a form in which it can be executed by a computer.
The software systems that do this translation are called compilers.
A compiler is a program that can read a program in one language - the source language - and translate it into an equivalent program in another language - the target language.
An important role of the compiler is to report any errors in the source program that it detects during the tranlation process.
-
Interpreter
An interpreter is another common kind of language processor.
Instead of producing a target program as a translation, an interpreter appears to directly execute the operations sepcified in the source prorgam on input supplied by the user.
-
Compiler vs. Interpreter
The machine-language target program produced by a compiler is ususally much faster than an interpreter at mapping inputs to outputs.
An interpreter, however, can usually give better error diagnostics than a compiler, because it executes the source program statement by statement.
-
Language Processing System
In addition to a compiler, several other programs may be required to create an executable target program:
-
Preprocessor
The task of collecting the source program which maybe divided into modules stored in separate files, is sometimes entrusted to a separate program, called a preprocessor;
The preprocessor may also expand shorthands, called macros, into source language statement;
-
Compiler
The compiler may produce an assembly-language program as its output, because assembly language is easier to produce as output and is easier to debug;
-
Assembler
The assembly language is then processed by a program called an assembler that produces relocatable machine code as its output;
Large programs are often compiled in pieces, so the relocatable machine code may have to be linked together with other relocatable object files and library files into the code that actually runs on the machine;
-
Linker
The linker resolves external memory addresses, where the code in one file may refer to a location in another file;
-
Loader
The loader then puts together all of the executable object files into memory for execution;
-
-
Structure of a Compiler
We treat a compiler as a single box that maps a source program into a semantically equivalent target program, if we open up this box a little, we see that there are two parts to this mapping:
-
Analysis(the front end of the compiler)
The analysis part breaks up the source program into constituent pieces and imposes a grammatical structure on them;
It also collects information about the source program and stores it in a data stucture called symbol table;
-
Synthesis(back end of the compiler)
The synthesis part constructs the desired target grogram from the intermediate representation and the information in the symbol table;
-
-
Phases of a compiler
理解lexeme, syntax, semantic in Compiler
-
Lexical analysis (scanning)
The lexical analyzer reads the stream of characters making up the source program and groups the characters into meaningful sequences called lexemes;
-
Syntax Analyzer
-
Semantic Analyzer
-
Intermediate Code Generator
理解three-address code
-
Code Optimization
-
Code Generator
P11
标签:target,language,读书笔记,into,source,program,Techniques,Tools,compiler 来源: https://blog.csdn.net/The_Time_Runner/article/details/116070600
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。