Skip to content

Commit

Permalink
修正了一些图片路径错误
Browse files Browse the repository at this point in the history
  • Loading branch information
Chiichen committed Oct 20, 2023
1 parent 595e329 commit e7638a7
Show file tree
Hide file tree
Showing 121 changed files with 22 additions and 21 deletions.
7 changes: 4 additions & 3 deletions src/zh/posts/编译原理/Chapter0 前言.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ footer:
copyright: 转载请注明出处
---

# 前言
## 前言

## 写给华工软院学生
### 写给华工软院学生

1. 2021级编译原理考试难度较低,复习优先级低,不建议花太多时间准备。虽然根据老师不同(以徐老师为例),可能上课的内容比较深入,让学生产生了这门科目难度很大的错觉。诚然要彻底理解编译原理需要花费大量的时间,但考试内容基本都是简单的算法,只要把几个重要算法理解了,都不需要把每个概念搞的非常清楚,考试都基本不会出问题。
2. 编译原理博大精深,作为计算机底层设计的一部分,课堂上教授的内容少之又少,甚至可以说和一些工程实践是`严重脱钩`的,比如上课会花很大的精力教你自动机和自动机的相关算法,但是在实际工程运用中,我们有诸如 `lexer` 的工具帮我们完成这个工作,而且如果是编写一个简单的词法分析器,甚至只需要简单的 `最长字串匹配` 就能实现一个词法分析。仅凭课堂上学的内容,大概率连怎么写一个 TinyC(精简版的C语言) 都不知道。感兴趣的同学可以认真钻研一番,这对编程能力会有极大的提高。

## 写给全体
### 写给全体

1.本系列笔记是对自己大学生活的记录,不保证能记录下所有知识点,仅供同学们学习参考。
2.参考书籍为龙书第二版 (Compilers: Principles,Techniques,and Tools 译名:编译原理 Alfred V. Aho / Monica S. Lam / Ravi Sethi / Jeffrey D. Ullman等著)
12 changes: 6 additions & 6 deletions src/zh/posts/编译原理/Chapter1 编译器组成.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ footer:
copyright: 转载请注明出处
---

# Chapter1 编译器组成
## Chapter1 编译器组成

## 编译器的结构
### 编译器的结构

- 词法分析Lexical analysis (Scanning)
- 语法分析Syntax analysis (Parsing)
Expand All @@ -36,20 +36,20 @@ copyright: 转载请注明出处

$$C(源代码)\rightarrow TAC(Three Address Code)中间(intermediate)码\rightarrow 机器码$$

## 词法分析
### 词法分析

- 本质上就是为了输出一个合法的token序列,每个token就是一个关键词或者一个关键词+词素(lexeme)的组合如

$$\begin{array}{c}T\_While\quad 关键词\\ T\_Identifier \;\;x \quad 关键词+词素\end{array}$$

## 语法分析
### 语法分析

- 就是将一个token序列表示为一棵语法树

## 语义分析
### 语义分析

- 就是将语法分析得到的语法树转化为一个带注解(annotated)的语法树

## 中间代码生成
### 中间代码生成

- 从语法树生成通用的中间代码
24 changes: 12 additions & 12 deletions src/zh/posts/编译原理/Chapter2 词法分析.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ copyright: 转载请注明出处

## 扫描过程

```
```c
while(137<n)
++i;
```

$\rightarrow T\_while \rightarrow( \rightarrow T\_IntConst+137\rightarrow<·····$

![扫描过程图示](/assets/images/编译原理/词法分析/扫描过程图示.png)
![扫描过程图示](./images/词法分析/扫描过程图示.png)

### 词元(tokens)

Expand Down Expand Up @@ -180,10 +180,10 @@ $$ab|c^* \rightarrow ((ab)|(c^*))$$
#### 基本子表达式的NFA
![子表达式NFA1](/assets/images/编译原理/词法分析/子表达式NFA1.png)
![子表达式NFA3](/assets/images/编译原理/词法分析/子表达式NFA3.png)
![子表达式NFA4](/assets/images/编译原理/词法分析/子表达式NFA4.png)
![子表达式NFA5](/assets/images/编译原理/词法分析/子表达式NFA5.png)
![子表达式NFA1](./images/词法分析/子表达式NFA1.png)
![子表达式NFA3](./images/词法分析/子表达式NFA3.png)
![子表达式NFA4](./images/词法分析/子表达式NFA4.png)
![子表达式NFA5](./images/词法分析/子表达式NFA5.png)
- 对于一个长度为$m$的正则表达式和有$n$个状态的NFA,可以在$O(mn^2)$的时间里判断这个正则表达式是否被匹配
Expand All @@ -204,27 +204,27 @@ $$ab|c^* \rightarrow ((ab)|(c^*))$$
- move方法:$move(I,a)=\{t|s\in I,t=T(s,a)\}$
- 子集构造法:$Subset\;I_a=\varepsilon\_closure(Move(I,a))$
### 算法
### 子集构造算法
1. 计算$M$的初始状态$的\varepsilon\_closure$,并作为$M^{'}$ 的初始状态
2. 对于这个集合以及每个后续集合 S ,我们计算每个字符 $a∈Σ$ 上的转换 $S_a$,这定义了一个新状态以及一个新转换$S\stackrel{a}{\longrightarrow} S_a$
3. 不断进行这个过程,直到没有新的状态和转换生成
4. 标记包含接受态的状态
![NFA2DFA](/assets/images/编译原理/词法分析/NFA2DFA.png)
![NFA2DFA2](/assets/images/编译原理/词法分析/NFA2DFA2.png)
![NFA2DFA](./images/词法分析/NFA2DFA.png)
![NFA2DFA2](./images/词法分析/NFA2DFA2.png)
## 最小化DFA
- 等价状态:对于两个状态$S_a和S_b$,如果对于符号表中的每一个输入,$S_a和S_b$都有相同或等价的k个状态,则这两个状态是等价的
### 算法
### Hopcroft算法
1. 将DFA中的状态划分为两个等价类:接受状态和非接受状态。
2. 对于每个等价类,根据输入字符的转移关系。如果对于某个字符使得一个等价类内的一个状态转移到另一个等价类中的状态,就将这个状态其进一步划分为更小的等价类。
3. 重复第2步,直到不能再划分为止。
```
```c
//基于等价类的思想
split(S)
foreach(character c)
Expand All @@ -238,6 +238,6 @@ hopcroft()
split(s)
```

![最小化DFA](/assets/images/编译原理/词法分析/最小化DFA.png)
![最小化DFA](./images/词法分析/最小化DFA.png)

- 不过一般做题直接颅内找等价就行了,不用一定按照这个划分一步步做下去。
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e7638a7

Please sign in to comment.