编译原理与编译构造 课堂笔记1 导论

前面是一些有关龙书的介绍,应该说是非常精彩的,由龙书的封面,讲解了龙书从第一版到第二版的过程中,人们对于编译原理的认识的变化,人们认识更深了,也因此减少了对编译原理的恐惧。我们的教材主要是使用龙书,而不是虎书、鲸书。 // 顺嘴吐槽一句,暑假看了一段时间的成龙历险记,所以听到龙书的第一反应是小玉的“龙叔”。


-----------------------------------------------------------------------------------------重要申明---------------------------------------------------------------------------------------------------

主要内容是复制粘贴的老师课件上的内容,可能会加上一些自己的感受,写博客的主要目的是督促自己及时复习

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

为什么要学习编译原理这门课:

1、 Seeing the development of a compiler gives you a feeling for how programs work.     That can help you understand the internal process of program execution deeply
更好理解程序的工作原理

2、Many algorithms and models you will use in compilers are fundamental, and will be useful to you elsewhere: 
automata
context-free grammars
学习一些经典的算法和模型,可以用在自动机和上下文无关语法

3、To program more efficient programs
Notes: Compiler writing spans programming languages, machine architecture, language theory, algorithms, and software engineering.
And the ideas behind principles and techniques of a compiler writing can be used many times in the career of a computer scientist. 
编写更有效率的程序


教学过程如下


编译原理与编译构造 课堂笔记1 导论_第1张图片


一个程序是如何被装载运行起来的:

编译原理与编译构造 课堂笔记1 导论_第2张图片


先写这么多,回去继续。。

-------------------------------------分割线-------------------------2017.9.5更新---------------------------------------------------------------------------------------------------------


以下部分进入正式的章节:

1.什么是一个编译器?

very general definition: It is a piece of software that translates a program in one (artificial) language, Lang1, to a program in another (artificial) language, Lang2.
narrower definition: Our primarily focus is the case where Lang1 is a programming language that humans like to program in, and Lang2 is (or is “closer to”) a machine language, that a computer “understands” and can execute.


编译原理与编译构造 课堂笔记1 导论_第3张图片

2.为什么避免用机器语言写编译器或者程序?

  • A good programming language allows us to think at a level of abstraction suitable for the problem domain we are interested in. 
  • A good programming language should also facilitate robust code development. 
3.编译的分析-综合模型
编译原理与编译构造 课堂笔记1 导论_第4张图片
  • Analysis part: Break up the source program into constitute pieces and create an intermediate representation of the source program
Notes: One of ordinary intermediate representation methods is syntax tree /parse tree

  • Syntax Tree/Parse tree: A hierarchical structure

编译原理与编译构造 课堂笔记1 导论_第5张图片

  • Synthesis part: Construct the desired target program from the intermediate representation
4.如何构造一个编译器

  • Program in a machine language for target machine directly
  • Program in an assembling language
 Notes: The kernel of a compiler is usually programmed in an assembling language
  • Program in high-level language

Notes: This is an ordinary method

  • Self-Compiling
  • Use compiler-construction tools
Lex,Yacc
  • Port among different platforms
Notes: When constructing a compiler, a source language, a destination language and the compiling methods should be considered


这里补充一下自编译。例如想要编译某种语言L,我们就可以将L分成若干个子集,便有L = L0 + L1 + …… + Ln。其中L0是最核心的部分,那么L0是由汇编写出来的,然后L1由L0写出来,L2由(L0+L1)写出来,……Ln由(L0+L1+……+Ln-1)写出来。那么就有L的自编译了。

-------------------------未完待续--------------------------------------------------------------------------------------------------------------

5.编译器的构造工具

  • Parser generators: Produce syntax analyzers, normally from input that is based on a context-free grammar
  • Scanner generators: Automatically generate lexical analyzers, normally from a specification based on regular expression
  • Syntax-directed translation engine: Produce collections of routines that walk the parse tree, generating intermediate code
  • Automatic code generators: Take a collection of rules that define the translation of each operation of the intermediate language into the machine language for the target machine
----------------------------------------------------------------编译原理 课堂笔记1就此完结---------------------------------------------------------------------------------------------------------------------------------


你可能感兴趣的:(编译原理与编译构造)