今生恋露(网学)贡献
THSS
34100162
2010 / 4301
Principles of Compilation
王朝坤 IISE@Tsinghua
THSS
34100162
2010 / 4301
Chap. 1 Introduction
Chaokun Wang IISE@Tsinghua
Outline
THSS 34100162 2010 / 4301
What
– 什么是编译和编译器
Why Course Info. PL
– 编译与解释的区别和联系
History Contents
编译各阶段的内容
3
1.1 Computer &; Software
THSS 34100162 2010 / 4301
4
Cloud Computing
THSS 34100162 2010 / 4301
Pig Latin
– Pig Latin is a data flow language rather than procedural or declarative. – User code and existing binaries can be included almost anywhere. – Metadata not required, but used when available. – Support for nested types. – Operates on files in HDFS.
5
THSS
34100162
2010 / 4301
6
软件开发
THSS 34100162 2010 / 4301
程序开发工具? ? 如何从编辑器中的文本到可执行程序 的? ?
7
A language-processing system
THSS 34100162 2010 / 4301
8
What is …
THSS 34100162 2010 / 4301
Compilation(编译)
– Compilation is the process whereby one computer language is translated into another (usually simpler and more lowlevel i.e. machine orientated) language – Traditionally, programs in a high-level computer language (e.g. Pascal, C, Lisp) are compiled into assembly language (essentially machine code)
Compiler(编译器)
– The program that does the translation is known as a compiler.
9
Compilers
THSS 34100162 2010 / 4301
Simply stated, a compiler is a program that reads a program written in one language — the source language — and translate it into an equivalent program in another language — the target language. As an important part of this translation process, the compiler reports to its user the presence of errors in the source program.
10
Preprocessors
THSS 34100162 2010 / 4301
Preprocessors produce input to compilers. They may perform the following functions. Macro inclusion. File inclusion. “Rational” preprocessors. Language extensions.
11
Assemblers
THSS 34100162 2010 / 4301
Some compilers produce assembly code that is passed to an assembler for further processing. Other compilers perform the job of the assembler, producing relocatable machine code that can be passed directly to the loader/link-editor. The relationship between assembly and machine code
– Assembly code is mnemonic version of machine code, – names are used instead of binary codes for operations – names are also given to memory address.
12
Loaders and Link-Editors
THSS 34100162 2010 / 4301
Usually, a program called a loader performs the two functions of loading and link-editi
ng. The linker resolves external memory addresses, where the code in one file may refer to a location in another file. The loader then puts together all of the executable object files into memory for execution.
13
1.2 Why is PoC?
THSS 34100162 2010 / 4301
Why Learn it ?
– Computer Science
OS (shell) DBS (sql) WEB (wsdl, roap)
– Career
Programmer (javac, gcj) Scientist (wm)
Why research it?
– Live
1956~ POPL(1973~)
– Impact
PLDI
14
Why Study Compilers
THSS 34100162 2010 / 4301
Excellent software-engineering example
– theory meets practice.
Essential software tool Influences hardware design
– RISC – VLIW
Tools (mostly “optimization”) for enhancing software reliability and security
– memory leak
15
1.3 General Course Information
THSS 34100162 2010 / 4301
Instructor: Office: Phone: Email: TA: Office: Phone: Email:
王朝坤 FIT-1-105 (Info. Sci. &; Tech. Bldg.) (010) 6279-5393 chaokun@tsinghua.edu 白易元 FIT-1-106 (Info. Sci. &; Tech. Bldg.) 136-9926-9303 eldereal@gmail
Course web page: learn.tsinghua.edu/
16
Textbooks
THSS 34100162 2010 / 4301
Compilers: Principles, Techniques and Tools (2ed) Alfred V. Aho, Monica S. Lam, Ravi Sethi, Jeffrey D. Ullman Addison-Wesley, 2006 (77, 86) ISBN 0-32148-6811 Advanced Compiler Design and Implementation Steven Muchnick Morgan Kaufman Publishers, 1997 ISBN 1-55860-320-4
17
Ref.
THSS 34100162 2010 / 4301
The Definitive ANTLR Reference. Terence Parr. The Pragmatic Programmers, 2007 ISBN-10: 0-9787392-5-6 Lex and Yacc (2nd edition) John R Levine Tony Mason Doug Brown O'Reilly &; Associates, October 1992 ISBN: 1-56592-0007 ……
18
Course Requirements
THSS 34100162 2010 / 4301
Checking attendance Homework (20%).
– Testing – Exercises – 14 times
Programming project (30%).
– read/improve the source code of a popular JAVA compiler and will involve
lexical analysis parsing semantic analysis code generation
– teams
Final exam (50%).
– closed-book and closed-notes
19
1.4 Programming Languages
THSS 34100162 2010 / 4301
declarative programming languages
– Fortran, C
objective-oriented programming languages
– SmallTalk, C++, Java
functional programming languages
– Lisp, Scheme
logical programming languages
– Prolog
other languages
– SQL, Ruby
20
How are languages implemented?
THSS 34100162 2010 / 4301
Various strategies depend on how much preprocessing is done before a program can be run, and how CPU-specific the program is. Interpreters run a program “as is” with little or no pre-processing, but no changes need to be made to run on a different platform. Compilers take time to do extensive pre-processing, but will run a program generally 2- to 20-
times faster.
21
Language implementations cont’d
THSS 34100162 2010 / 4301
Some newer languages use a combination of compiler and interpreter to get many of the benefits of each. Examples are Java and Microsoft’s .NET, which compile into a virtual assembly language (while being optimized), which can then be interpreted on any computer. Other languages (such as Basic or Lisp) have both compilers and interpreters written for them. Recently, “Just-in-Time” compilers are becoming more common - compile code only when its used!
22
Buddies of Compilation
THSS 34100162 2010 / 4301
反编译、汇编、反汇编、翻译、… 高级语言之间的转换工具 由于计算机硬件的不断更新换 代,更新更好的程序设计语言的推出为提高计算机的使用 效率提供了良好条件,然而一些已有的非常成熟的软件如 何在新机器新语言情况下使用呢?为了减少重新编制程序 所耗费的人力和时间,就要解决如何把一种高级语言转换 成另一种高级语言,乃至汇编语言转换成高级语言的问题。 这种转换工作要对被转换的语言进行词法和语法分析,只 不过生成的目标语言是另一种高级语言而已。这与实现一 个完整的编译程序相比工作量要少些。
23
Compilation and Interpretation
THSS 34100162 2010 / 4301
程序设计语言的实现主要的途
上一篇:
深入解读Ruby自动化测试作用_Ruby代码
下一篇:
试论建设企业信息化提升企业竞争力