电子科技大学 编译原理期末女娲补天

算是考完了 真难啊。。 学弟学妹们看到了可以参考下 内有真题一套 稍有些混乱的复习笔记一堆 不建议全部相信 因为本人复习得比较拉胯。。
参考下是ok的 语雀链接食用体验更佳 戳这里~

考完来简单总结下
题目与往年差不太多

  • 语法树
  • FIRSTVT表 LASTVT集
  • FIRST集 FOLLOW集 构造预测分析表
  • 中间代码分析
  • SLR(1)分析法
  • 语义子程序的翻译

经验总结:ppt直接看根本看不懂 顺序也比较奇怪 建议先通读一遍ppt 有不懂的先跳过 然后重要知识点多百度一下 可以去bilibili听一些up主讲一下

我晕 图片因为是语雀导出的 所以链接有点问题 懒得改了 咱就是说 建议看语雀上的内容哈 戳这里~
电子科技大学 编译原理期末女娲补天_第1张图片

语言部分

1-变量及其属性

变量是对一个(或若干个)存储单元的抽象,赋值语句则是修改存储单元内容的抽象。

属性:

  • 作用域:可以访问该变量的程序范围
  • 生存期:一个储存区绑定于一个变量的时间区间
  • 值:变量对应的存储单元的内容
  • 类型:与变量相关联的值的类, 以及对这些值进行的操作的说明。

1-虚拟机的概念

![image.png](https://img-blog.csdnimg.cn/img_convert/4ea42b00770d306ab2d814f608d83c3d.png#clientId=u43ff57c7-d1bf-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=354&id=ufd028177&margin=[object Object]&name=image.png&originHeight=443&originWidth=921&originalType=binary&ratio=1&rotation=0&showTitle=false&size=60450&status=done&style=none&taskId=u97a96f7f-845d-488a-8fde-1b0e9da8cea&title=&width=736.8)

1-程序单元 & 单元实例

![image.png](https://img-blog.csdnimg.cn/img_convert/a29ee9edde321e691997abada95ea9cb.png#clientId=u43ff57c7-d1bf-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=102&id=ua5e9e170&margin=[object Object]&name=image.png&originHeight=127&originWidth=777&originalType=binary&ratio=1&rotation=0&showTitle=false&size=27477&status=done&style=none&taskId=ub53aec50-8eb1-4677-9517-ab5c982c9e7&title=&width=621.6)
![image.png](https://img-blog.csdnimg.cn/img_convert/a3958e7b07bc8dc20d26ed1b3ba756a3.png#clientId=u43ff57c7-d1bf-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=183&id=u8aae8fe3&margin=[object Object]&name=image.png&originHeight=229&originWidth=751&originalType=binary&ratio=1&rotation=0&showTitle=false&size=46256&status=done&style=none&taskId=ub08c3f54-1add-481c-b421-9ca447cb1b9&title=&width=600.8)

  • 活动记录:执行单元所需要的信息,以及该单元的局部变量所绑定的数据对象的存储区

2-数据类型的作用

简答题~

  • 实现了数据抽象
  • 使程序员从机器的具体特征中解脱出来
  • 提高了编程效率

2-数据聚合的六种方式

填空题~
![image.png](https://img-blog.csdnimg.cn/img_convert/7897ffa1407d29a8f86b39154567ec04.png#clientId=u43ff57c7-d1bf-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=334&id=u76a6340b&margin=[object Object]&name=image.png&originHeight=417&originWidth=958&originalType=binary&ratio=1&rotation=0&showTitle=false&size=64229&status=done&style=none&taskId=uc14c57dc-64c5-45e4-a39b-d6bf6ba93ca&title=&width=766.4)

2-类型检查及分类

  • 对数据对象的类型和使用的操作是否匹配的一致性检查称为类型检查
    • 静态检查
    • 动态检查

![image.png](https://img-blog.csdnimg.cn/img_convert/222c54acc3d7cf5b0d7882076fe757e0.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=237&id=ub1ec4e54&margin=[object Object]&name=image.png&originHeight=296&originWidth=945&originalType=binary&ratio=1&rotation=0&showTitle=false&size=89989&status=done&style=none&taskId=u356cb54e-7b02-4164-a2a0-be2d01c67b0&title=&width=756)

2-抽象数据类型的条件

  • 在实现该类型的程序单元中,建立与表示有关的基本操作;
  • 对使用该类型的程序单元来说,该类型的表示是隐蔽的。

![image.png](https://img-blog.csdnimg.cn/img_convert/bd7a7f41b7170652423cd51d7f5d08bd.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=441&id=u364192c8&margin=[object Object]&name=image.png&originHeight=551&originWidth=902&originalType=binary&ratio=1&rotation=0&showTitle=false&size=97074&status=done&style=none&taskId=uc12038a7-3563-4926-b922-bf2acc13e0d&title=&width=721.6)

2-何为类型等价

![image.png](https://img-blog.csdnimg.cn/img_convert/5ae8c0d480687bc024939988ac9cdb9b.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=374&id=u5ccef115&margin=[object Object]&name=image.png&originHeight=467&originWidth=893&originalType=binary&ratio=1&rotation=0&showTitle=false&size=99995&status=done&style=none&taskId=u257d2868-c304-434a-b651-0dfd3e7c0e9&title=&width=714.4)

3-语句级控制结构——顺序、选择、重复

  • 顺序

![image.png](https://img-blog.csdnimg.cn/img_convert/c1eebe51aabfa1b86aa759a3fb347cba.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=65&id=u85ebdc94&margin=[object Object]&name=image.png&originHeight=157&originWidth=569&originalType=binary&ratio=1&rotation=0&showTitle=false&size=12334&status=done&style=none&taskId=u187fe682-37cb-4c0e-a00d-16dd696d688&title=&width=234.1875)

  • 选择

![image.png](https://img-blog.csdnimg.cn/img_convert/91b67fd3878c1ae2bf8cd4b213957663.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=165&id=ubedc469e&margin=[object Object]&name=image.png&originHeight=457&originWidth=918&originalType=binary&ratio=1&rotation=0&showTitle=false&size=72341&status=done&style=none&taskId=uff967589-fae9-4aab-a4aa-6b318f245a2&title=&width=331)
![image.png](https://img-blog.csdnimg.cn/img_convert/77321d14808c7a613711110208b6e6f8.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=231&id=ue298d98d&margin=[object Object]&name=image.png&originHeight=370&originWidth=551&originalType=binary&ratio=1&rotation=0&showTitle=false&size=23707&status=done&style=none&taskId=u31f95994-51ab-4676-b316-d53997f30c5&title=&width=343.796875)

  • 重复

![image.png](https://img-blog.csdnimg.cn/img_convert/072c73c5e124e0b4ea6eacbaeade6ae7.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=247&id=uec49d88a&margin=[object Object]&name=image.png&originHeight=600&originWidth=973&originalType=binary&ratio=1&rotation=0&showTitle=false&size=62611&status=done&style=none&taskId=uaaba7098-415d-44a1-a484-51ec8fec2f2&title=&width=400)
![image.png](https://img-blog.csdnimg.cn/img_convert/e9386c4b60aac0780dbf10c6d23887aa.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=81&id=ua0fa35f1&margin=[object Object]&name=image.png&originHeight=157&originWidth=781&originalType=binary&ratio=1&rotation=0&showTitle=false&size=19215&status=done&style=none&taskId=ud26a853d-eb9a-439d-b5fa-6e1fe302f38&title=&width=401)

  • 语句级控制结构分析

![image.png](https://img-blog.csdnimg.cn/img_convert/cd74faefe1cf0687662e0c1c0487bc36.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=294&id=u38a9b680&margin=[object Object]&name=image.png&originHeight=368&originWidth=778&originalType=binary&ratio=1&rotation=0&showTitle=false&size=70921&status=done&style=none&taskId=u8034c626-00f1-44e2-a159-40782249e54&title=&width=622.4)

3-单元级控制结构

规定程序单元之间控制流程的机制
![image.png](https://img-blog.csdnimg.cn/img_convert/e6963813f665e34c775ad6fc776f3873.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=239&id=u688b1300&margin=[object Object]&name=image.png&originHeight=299&originWidth=427&originalType=binary&ratio=1&rotation=0&showTitle=false&size=23465&status=done&style=none&taskId=uc25848a9-e8ae-48ea-855c-59c8204e52d&title=&width=341.6)

3-副作用、别名

  • 非局部变量
    一个程序单元可以引用未被本单元说明而被其他单元说明的变量

int a;
int b = 666;
a = 666; —— a为非局部变量 可以这么理解?

  • 非局部变量绑定于其他的程序单元(定义该非局部变量的程序单元)的活动记录中的数据对象;
  • 或非局部变量绑定全局数据区中的数据对象称为非局部环境

![image.png](https://img-blog.csdnimg.cn/img_convert/b414159eac01b4368f63108d8cfe99f8.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=454&id=uc3f41212&margin=[object Object]&name=image.png&originHeight=567&originWidth=800&originalType=binary&ratio=1&rotation=0&showTitle=false&size=64726&status=done&style=none&taskId=u9d6a78d5-bb7f-426e-bad6-09b5fddca7b&title=&width=640)
![image.png](https://img-blog.csdnimg.cn/img_convert/0b5b364fcd9e166abc5dbf17375236f1.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=418&id=u6f5dccb5&margin=[object Object]&name=image.png&originHeight=523&originWidth=894&originalType=binary&ratio=1&rotation=0&showTitle=false&size=52180&status=done&style=none&taskId=ua1223ac1-44de-45ac-a582-37d1fb013ff&title=&width=715.2)
哪俩属于别名?
![image.png](https://img-blog.csdnimg.cn/img_convert/6da799257570f8c12851e297fad88831.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=478&id=u640b86ba&margin=[object Object]&name=image.png&originHeight=598&originWidth=757&originalType=binary&ratio=1&rotation=0&showTitle=false&size=36187&status=done&style=none&taskId=u2af28ad0-420e-4b8f-88a2-f967d813b2c&title=&width=605.6)
![image.png](https://img-blog.csdnimg.cn/img_convert/fadeb4946f80a3e3242b19f0693b21a5.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=458&id=ud28580e6&margin=[object Object]&name=image.png&originHeight=573&originWidth=969&originalType=binary&ratio=1&rotation=0&showTitle=false&size=65953&status=done&style=none&taskId=ua63169b4-23dd-4152-b97b-af667388c66&title=&width=775.2)
![image.png](https://img-blog.csdnimg.cn/img_convert/760c9831aedf7109c5f5fd1666a20943.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=426&id=uc02b90f5&margin=[object Object]&name=image.png&originHeight=532&originWidth=898&originalType=binary&ratio=1&rotation=0&showTitle=false&size=60809&status=done&style=none&taskId=u768a9a27-b237-4404-9fb7-71dd1c83e80&title=&width=718.4)

4-语言的定义

程序设计语言是用来描述计算机所执行的算法的形式表示;
![image.png](https://img-blog.csdnimg.cn/img_convert/f718579c80c1b0c3521ac83556bed5c7.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=118&id=u43109937&margin=[object Object]&name=image.png&originHeight=358&originWidth=1293&originalType=binary&ratio=1&rotation=0&showTitle=false&size=25025&status=done&style=none&taskId=u94151c07-f5dc-4222-b866-185e68a88d0&title=&width=425)
![image.png](https://img-blog.csdnimg.cn/img_convert/f1a8a771a00725f489372bb8191497b2.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=387&id=u3fb896f9&margin=[object Object]&name=image.png&originHeight=597&originWidth=816&originalType=binary&ratio=1&rotation=0&showTitle=false&size=69518&status=done&style=none&taskId=uc404048d-ae12-4117-a249-f2641650355&title=&width=528.7999877929688)
![image.png](https://img-blog.csdnimg.cn/img_convert/a60caebf194b477479b2fc2bea703fba.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=350&id=u2f1657ea&margin=[object Object]&name=image.png&originHeight=437&originWidth=758&originalType=binary&ratio=1&rotation=0&showTitle=false&size=56747&status=done&style=none&taskId=u22960806-f342-46d5-af02-300dc8e81f6&title=&width=606.4)

4-语法描述的基本用途

![image.png](https://img-blog.csdnimg.cn/img_convert/7e76816c8b43164cec47c72560c3654f.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=282&id=u7f7b6a4d&margin=[object Object]&name=image.png&originHeight=468&originWidth=934&originalType=binary&ratio=1&rotation=0&showTitle=false&size=45725&status=done&style=none&taskId=uc428b845-649f-42b4-bb77-e64b0cc3f32&title=&width=563.2000122070312)

4-文法的定义

![image.png](https://img-blog.csdnimg.cn/img_convert/fd4646dee97593183162bf56c44cee33.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=424&id=u54669f0a&margin=[object Object]&name=image.png&originHeight=530&originWidth=675&originalType=binary&ratio=1&rotation=0&showTitle=false&size=77163&status=done&style=none&taskId=ua77509a4-df0c-4999-b095-632b9aabf0f&title=&width=540)
用英文大写字母表示非终结符;小写字母表示终结符;希腊小写字母表示串

4-文法的分类

  • 0型文法 产生式形如α→b
    • α中至少含一个非终结符
  • 1型文法 │α│<=│β│(S→e例外)或产生式形如αAβ→αwβ,w∈V+ (上下文有关文法)
    • α中终结符个数小于β
  • 2型文法 产生式形如A→α (上下文无关文法)
    • 产生式右端均为终结符
      • S—>aB|bA
      • A—>aS|bAA|a
      • B—>bS|aBB|b
  • 3型文法 产生式形如A→α或A→αB (正则文法,右线性文法) α∈VT*
    • 在2型的基础上要求右端最多有一个非终结符,且位于最右端
      • S—>bA
      • A—>(B|a
      • B—>aA

![image.png](https://img-blog.csdnimg.cn/img_convert/331e2dedba860ee2b8cf127bd383de9f.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=269&id=udef3ba5b&margin=[object Object]&name=image.png&originHeight=417&originWidth=817&originalType=binary&ratio=1&rotation=0&showTitle=false&size=28475&status=done&style=none&taskId=ub50e0a93-3294-42f1-bebf-c62bb634533&title=&width=527.6000366210938)

4-文法产生的语言

推导(与归约)

![image.png](https://img-blog.csdnimg.cn/img_convert/60a3610f2b828fe80d1937a04f721a1f.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=315&id=u1a375cc2&margin=[object Object]&name=image.png&originHeight=394&originWidth=791&originalType=binary&ratio=1&rotation=0&showTitle=false&size=34742&status=done&style=none&taskId=ubc6ae221-b7e5-4dcf-a576-b6fda1cdf39&title=&width=632.8)
![image.png](https://img-blog.csdnimg.cn/img_convert/042a7de27d1ee26f5927f51e715fca50.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=254&id=u761b4190&margin=[object Object]&name=image.png&originHeight=414&originWidth=971&originalType=binary&ratio=1&rotation=0&showTitle=false&size=49300&status=done&style=none&taskId=u09d083e2-0c16-4126-80cd-befa91d2e0a&title=&width=594.7999877929688)

句型 & 句子

![image.png](https://img-blog.csdnimg.cn/img_convert/9a1140a6569e7bd98fc6ba5eebd406fc.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=273&id=u59fee977&margin=[object Object]&name=image.png&originHeight=341&originWidth=842&originalType=binary&ratio=1&rotation=0&showTitle=false&size=49331&status=done&style=none&taskId=uc7080528-eb38-441d-84a9-cfbabb6e838&title=&width=673.6)
![image.png](https://img-blog.csdnimg.cn/img_convert/2517dec41cdc9b1522ff043b4ed0e57c.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=267&id=Mxi6C&margin=[object Object]&name=image.png&originHeight=334&originWidth=692&originalType=binary&ratio=1&rotation=0&showTitle=false&size=24343&status=done&style=none&taskId=u29a24ab4-e42c-4c99-834b-0a8f1221f70&title=&width=553.6)

文法产生的语言L(G)

![image.png](https://img-blog.csdnimg.cn/img_convert/1d4529c962e1fde24d8a493543843db9.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=159&id=u7a9ebf3d&margin=[object Object]&name=image.png&originHeight=199&originWidth=813&originalType=binary&ratio=1&rotation=0&showTitle=false&size=23648&status=done&style=none&taskId=u442ad452-6abb-47a1-bbf2-d679e21d536&title=&width=650.4)

  • 例一

![image.png](https://img-blog.csdnimg.cn/img_convert/2e4e748e773263d5e3c24bef100995a9.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=308&id=ub89fa06c&margin=[object Object]&name=image.png&originHeight=385&originWidth=552&originalType=binary&ratio=1&rotation=0&showTitle=false&size=18490&status=done&style=none&taskId=uc92a77f3-0666-4f37-837c-1d1bcbd6f4f&title=&width=441.6)

  • 例二

![image.png](https://img-blog.csdnimg.cn/img_convert/c27298832a6a7bcc0f090e0c45556afe.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=392&id=ucc3603d3&margin=[object Object]&name=image.png&originHeight=490&originWidth=388&originalType=binary&ratio=1&rotation=0&showTitle=false&size=20793&status=done&style=none&taskId=u741ffa9c-f3ee-4d5e-8024-0ddad519d6b&title=&width=310.4)
![image.png](https://img-blog.csdnimg.cn/img_convert/73f66c6ba2930e96ff4e904de059b468.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=222&id=ub38f0547&margin=[object Object]&name=image.png&originHeight=277&originWidth=729&originalType=binary&ratio=1&rotation=0&showTitle=false&size=36495&status=done&style=none&taskId=uf4265922-0b2e-4d54-8cbc-2c2e40ff22d&title=&width=583.2)

短语、句柄、素短语

  • 短语——叶子节点
  • 句柄——最左直接短语

![image.png](https://img-blog.csdnimg.cn/img_convert/010e72803b14cd60543ce9cb2fdde33d.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=261&id=u7cc5f028&margin=[object Object]&name=image.png&originHeight=514&originWidth=1744&originalType=binary&ratio=1&rotation=0&showTitle=false&size=162522&status=done&style=none&taskId=u2b570d71-bd78-4179-b43c-796baae436f&title=&width=887.2000732421875)

语法树(推导树)

字面意思~

4-例题:推导、句型、句子、短语、句柄

  • 例一

![image.png](https://img-blog.csdnimg.cn/img_convert/49fb78a55400d1c802137355645ab243.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=322&id=ubc2d4f11&margin=[object Object]&name=image.png&originHeight=402&originWidth=855&originalType=binary&ratio=1&rotation=0&showTitle=false&size=33061&status=done&style=none&taskId=u465d51e3-f69b-4fbb-822c-3232734b18a&title=&width=684)
![image.png](https://img-blog.csdnimg.cn/img_convert/66a899536c553397a99a79f3d2589326.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=570&id=ub0adc1d6&margin=[object Object]&name=image.png&originHeight=712&originWidth=1004&originalType=binary&ratio=1&rotation=0&showTitle=false&size=94544&status=done&style=none&taskId=uffd152eb-77b6-49c3-af2e-0a99e1c1f2c&title=&width=803.2)

  • 例二

![image.png](https://img-blog.csdnimg.cn/img_convert/6b3da262bfab21da2b7ccc4a7a17237d.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=518&id=u0841fc97&margin=[object Object]&name=image.png&originHeight=648&originWidth=931&originalType=binary&ratio=1&rotation=0&showTitle=false&size=70378&status=done&style=none&taskId=u2593ee07-6eb8-4a33-80c6-623ca122f1e&title=&width=744.8)

  • 例三

![image.png](https://img-blog.csdnimg.cn/img_convert/8bfa9f70f5b85b6912acdc8bdc9c97cc.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=497&id=u126181dc&margin=[object Object]&name=image.png&originHeight=621&originWidth=893&originalType=binary&ratio=1&rotation=0&showTitle=false&size=79256&status=done&style=none&taskId=u6219a196-881b-4239-ab82-661bb39377f&title=&width=714.4)

编译部分

5-编译等概念

翻译:将一种语言编写的程序转换成完全等效的另一种语言编写的程序的过程。在计算机中,翻译由一 个程序来实现,称为翻译程序

**宿主语言:**编写编译程序的语言。运行翻译程序的机称为宿主机

静态语言需要先进行编译,才能执行代码
![image.png](https://img-blog.csdnimg.cn/img_convert/692788931d22f11a854f3709e9c809e4.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=130&id=u524af629&margin=[object Object]&name=image.png&originHeight=320&originWidth=766&originalType=binary&ratio=1&rotation=0&showTitle=false&size=34683&status=done&style=none&taskId=uaf376318-3dfd-4994-b246-4d5bd20c73d&title=&width=310)
动态语言则是可以边解释 边执行代码
![image.png](https://img-blog.csdnimg.cn/img_convert/ec10684b070a25a77ff0f7f31c7fbc2e.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=217&id=u7ab9f48e&margin=[object Object]&name=image.png&originHeight=563&originWidth=867&originalType=binary&ratio=1&rotation=0&showTitle=false&size=113864&status=done&style=none&taskId=ub17f7c64-2e68-4b1d-b524-cac722c2322&title=&width=334)

5-编译步骤

  • 词法分析
    • 输入字符串 根据词法规则识别出单词符号
  • 语法分析
    • 根据语法规则 将单词符号构成各类语法单位 并进行语法检查
  • 语义分析
    • 根据语义规则,进行初步编译
  • 优化
    • 对中间代码进行等价变换 以使代码更有效
  • 目标代码生成
    • 生成机器语言程序或汇编语言程序
  • 符号表管理
    • 完成符号表的建立、查找、更新
  • 出错处理

![image.png](https://img-blog.csdnimg.cn/img_convert/51195f7e1e94a6f559a48ee165130664.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=509&id=u1de7bbc3&margin=[object Object]&name=image.png&originHeight=636&originWidth=931&originalType=binary&ratio=1&rotation=0&showTitle=false&size=83981&status=done&style=none&taskId=uadc51272-f6e0-4370-8b71-805d045caf5&title=&width=744.8)

6-词法分析器的功能

  • 扫描源程序的字符串,按照词法规则,识别出单词符号作为输出

  • 对识别过程中发现的词法错误输出有关的错误信息。

  • 词法分析器是子程序

    • ![image.png](https://img-blog.csdnimg.cn/img_convert/66ce5b647542b4e3315294a9f4368ee9.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=82&id=u9809a478&margin=[object Object]&name=image.png&originHeight=102&originWidth=844&originalType=binary&ratio=1&rotation=0&showTitle=false&size=7851&status=done&style=none&taskId=uec78837a-4f30-46ec-81f4-4ee309fee13&title=&width=675.2)
    • ![image.png](https://img-blog.csdnimg.cn/img_convert/59a43798ef8f4a5384c02ef24693a113.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=244&id=ufee0b24d&margin=[object Object]&name=image.png&originHeight=305&originWidth=775&originalType=binary&ratio=1&rotation=0&showTitle=false&size=21612&status=done&style=none&taskId=u4a5d00a0-0051-4283-ab35-dc805af2586&title=&width=620)

6-单词符号的分类

  • 标识符![image.png](https://img-blog.csdnimg.cn/img_convert/776baa0ef93ee692c3079e360174c88e.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=70&id=u744bdd60&margin=[object Object]&name=image.png&originHeight=88&originWidth=592&originalType=binary&ratio=1&rotation=0&showTitle=false&size=12930&status=done&style=none&taskId=ub71358fe-02a1-44e2-a62f-9e3840532b1&title=&width=473.6)
  • 基本字![image.png](https://img-blog.csdnimg.cn/img_convert/7cfa930f51aef1daeb84878ad532cf88.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=74&id=ub51a6d37&margin=[object Object]&name=image.png&originHeight=92&originWidth=658&originalType=binary&ratio=1&rotation=0&showTitle=false&size=11849&status=done&style=none&taskId=u75e448b3-c878-482c-b97b-f4f1006300f&title=&width=526.4)
  • 常数![image.png](https://img-blog.csdnimg.cn/img_convert/44ff4e1453c77a339bd6fb2cc0ceaa8c.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=38&id=ub5d89dbc&margin=[object Object]&name=image.png&originHeight=48&originWidth=723&originalType=binary&ratio=1&rotation=0&showTitle=false&size=9557&status=done&style=none&taskId=ue1025b26-738a-48a8-824d-96983de652c&title=&width=578.4)
  • 运算符![image.png](https://img-blog.csdnimg.cn/img_convert/1d89891f41ab940b9766e802ccac1187.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=29&id=u4beea98b&margin=[object Object]&name=image.png&originHeight=36&originWidth=201&originalType=binary&ratio=1&rotation=0&showTitle=false&size=1251&status=done&style=none&taskId=u7fc48843-860e-4b33-8c9d-855cb92fcea&title=&width=160.8)
  • 界符![image.png](https://img-blog.csdnimg.cn/img_convert/9ca2b2851691b8dccc089e120bd49b3b.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=30&id=u37faffd8&margin=[object Object]&name=image.png&originHeight=37&originWidth=234&originalType=binary&ratio=1&rotation=0&showTitle=false&size=1405&status=done&style=none&taskId=u883b916f-d585-47f6-bd58-0141bc7a02c&title=&width=187.2)

单词类别的划分(编码的方式)

![image.png](https://img-blog.csdnimg.cn/img_convert/7a780b85443a9d897fe341be98ad5b6f.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=194&id=Ktok7&margin=[object Object]&name=image.png&originHeight=243&originWidth=633&originalType=binary&ratio=1&rotation=0&showTitle=false&size=20425&status=done&style=none&taskId=ue65ae947-508b-46da-ad49-244943f1290&title=&width=506.4)
![image.png](https://img-blog.csdnimg.cn/img_convert/93908c56864e8e7e2a742edc35b84909.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=386&id=u83677bb9&margin=[object Object]&name=image.png&originHeight=483&originWidth=567&originalType=binary&ratio=1&rotation=0&showTitle=false&size=55812&status=done&style=none&taskId=u4debca2d-2623-4546-a1aa-8c083ba5c90&title=&width=453.6)

6-状态转换图

简称转换图,是一张有限方向图,是设计词法分析器的有效工具;它由如下成分构成:
1.结点(node):圆圈表示结点,代表状态(state)
2.有向边(弧):连接结点,边上的标记字符表示该状态下可能接收或识别的字符;
![image.png](https://img-blog.csdnimg.cn/img_convert/7af71e05b57eb78eb04672825dee8b84.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=183&id=u05fa2709&margin=[object Object]&name=image.png&originHeight=229&originWidth=785&originalType=binary&ratio=1&rotation=0&showTitle=false&size=31271&status=done&style=none&taskId=u5a75951d-eb61-4dd3-9d34-eed32bffe75&title=&width=628)
![image.png](https://img-blog.csdnimg.cn/img_convert/a27ba920d2ba371b89f36b539b77ca2d.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=290&id=u4cc05622&margin=[object Object]&name=image.png&originHeight=457&originWidth=874&originalType=binary&ratio=1&rotation=0&showTitle=false&size=44464&status=done&style=none&taskId=u9d970797-3027-4f12-8162-de8165638e9&title=&width=554.2000122070312)

例子

![image.png](https://img-blog.csdnimg.cn/img_convert/b2481e3039e718e9cb7c21ad3004b69c.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=416&id=u204147bc&margin=[object Object]&name=image.png&originHeight=520&originWidth=918&originalType=binary&ratio=1&rotation=0&showTitle=false&size=58327&status=done&style=none&taskId=ufb1e2848-affd-443c-9467-8dab4662488&title=&width=734.4)

第六章 ppt p21

![image.png](https://img-blog.csdnimg.cn/img_convert/2fc35d37e63a1280f8c09febc4d63b88.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=444&id=uc76e7931&margin=[object Object]&name=image.png&originHeight=874&originWidth=1394&originalType=binary&ratio=1&rotation=0&showTitle=false&size=195253&status=done&style=none&taskId=u1521593f-fa99-4e42-b988-5c12788b7e3&title=&width=708.2000732421875)

重点——语法分析

语法分析分为两种
第七章——自上而下(自顶而下)
第八章——自下而上(自底而上)
![image.png](https://img-blog.csdnimg.cn/img_convert/323e076582d628b80ae4930d8a48caf8.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=447&id=u749fac64&margin=[object Object]&name=image.png&originHeight=559&originWidth=844&originalType=binary&ratio=1&rotation=0&showTitle=false&size=80443&status=done&style=none&taskId=u1ca8cc0c-4667-4a07-9e4a-daea6b4eabb&title=&width=675.2)

7-回溯分析法

![image.png](https://img-blog.csdnimg.cn/img_convert/d51d761ec076975913349e782091b6b6.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=374&id=u9c7ab631&margin=[object Object]&name=image.png&originHeight=538&originWidth=931&originalType=binary&ratio=1&rotation=0&showTitle=false&size=84847&status=done&style=none&taskId=u54b26544-2ea7-4a51-bb36-7f664de5412&title=&width=647.7999877929688)
![image.png](https://img-blog.csdnimg.cn/img_convert/e17307a94513a9aac68fcdab563c3d0c.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=386&id=u95cd013f&margin=[object Object]&name=image.png&originHeight=482&originWidth=701&originalType=binary&ratio=1&rotation=0&showTitle=false&size=35735&status=done&style=none&taskId=u6188a0ea-626d-42e8-9562-ce86e9e05d1&title=&width=560.8)

7-公共左因子

这个例子是啥意思?
![image.png](https://img-blog.csdnimg.cn/img_convert/617e818c03f734f4db30cfe30e44c0eb.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=287&id=ub29867d2&margin=[object Object]&name=image.png&originHeight=527&originWidth=833&originalType=binary&ratio=1&rotation=0&showTitle=false&size=35019&status=done&style=none&taskId=ucb752984-3135-4ac4-a71c-ddb1aee89d6&title=&width=454.4000244140625)

提取公共左因子
![image.png](https://img-blog.csdnimg.cn/img_convert/706b2fe84fce4212f258d397b1c83cdf.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=394&id=u6553a707&margin=[object Object]&name=image.png&originHeight=492&originWidth=926&originalType=binary&ratio=1&rotation=0&showTitle=false&size=63860&status=done&style=none&taskId=u198a6511-61d7-4331-ab39-1dc1bc0c4d8&title=&width=740.8)
先提取左公因子 再消除左递归也ok

![image.png](https://img-blog.csdnimg.cn/img_convert/f9a46082a3cb64aa13facc1cc3cc9c85.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=297&id=u4866a11c&margin=[object Object]&name=image.png&originHeight=1262&originWidth=1146&originalType=url&ratio=1&rotation=0&showTitle=false&size=1157311&status=done&style=none&taskId=ue83a0873-b2d2-474a-9d15-c4adfcf9c87&title=&width=270)

7-左递归

![image.png](https://img-blog.csdnimg.cn/img_convert/906ba4ed80939febb49439e5d3f2acca.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=464&id=ue443c4ae&margin=[object Object]&name=image.png&originHeight=580&originWidth=792&originalType=binary&ratio=1&rotation=0&showTitle=false&size=37622&status=done&style=none&taskId=u916eabcf-726b-4d0c-80d9-54abec2ba15&title=&width=633.6)

消除左递归

  • 公式

![image.png](https://img-blog.csdnimg.cn/img_convert/6ec507fef7b50afc01d6d1e594e8a5ab.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=321&id=u1ef7020d&margin=[object Object]&name=image.png&originHeight=401&originWidth=812&originalType=binary&ratio=1&rotation=0&showTitle=false&size=27327&status=done&style=none&taskId=u9efcdcea-3986-4168-ad8a-8c31aece357&title=&width=649.6)

  • 例题

![image.png](https://img-blog.csdnimg.cn/img_convert/89287b11b17eefeba032025f14133f96.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=363&id=ua6850bdc&margin=[object Object]&name=image.png&originHeight=454&originWidth=768&originalType=binary&ratio=1&rotation=0&showTitle=false&size=42394&status=done&style=none&taskId=ub1dccc77-f8eb-4c1e-b4dd-15ac076a8db&title=&width=614.4)

间接左递归的消除

![image.png](https://img-blog.csdnimg.cn/img_convert/13923dec79add1b79a62d0b3ec837c92.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=380&id=u559474b9&margin=[object Object]&name=image.png&originHeight=475&originWidth=700&originalType=binary&ratio=1&rotation=0&showTitle=false&size=40145&status=done&style=none&taskId=u87ba403e-037a-43e9-8119-b954821ed03&title=&width=560)

复杂的间接左递归消除

![image.png](https://img-blog.csdnimg.cn/img_convert/390db38d6cbf9092d2528d83aba6a7bb.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=295&id=uda03023b&margin=[object Object]&name=image.png&originHeight=369&originWidth=584&originalType=binary&ratio=1&rotation=0&showTitle=false&size=21181&status=done&style=none&taskId=u0469aede-cdb5-4d27-9938-ae6a7324305&title=&width=467.2)

  • 这个产生的语言是怎么出来得?

![image.png](https://img-blog.csdnimg.cn/img_convert/2869063ef93d4f19fdae9ef3fdcbf79f.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=350&id=uadb08ef7&margin=[object Object]&name=image.png&originHeight=590&originWidth=821&originalType=binary&ratio=1&rotation=0&showTitle=false&size=61456&status=done&style=none&taskId=u546ae122-6933-4851-836f-3d16ee9161e&title=&width=486.79998779296875)
![image.png](https://img-blog.csdnimg.cn/img_convert/b6febead91aa99550ffb50b2cca7d637.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=313&id=u0d5bd3a1&margin=[object Object]&name=image.png&originHeight=574&originWidth=911&originalType=binary&ratio=1&rotation=0&showTitle=false&size=63685&status=done&style=none&taskId=u3407ed12-b156-43de-ab5d-2dde2098e21&title=&width=496.8000183105469)

7-ε产生式

![image.png](https://img-blog.csdnimg.cn/img_convert/0b3079c9f9e27cdbee3183ab97b1290f.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=368&id=uff79b4e4&margin=[object Object]&name=image.png&originHeight=460&originWidth=922&originalType=binary&ratio=1&rotation=0&showTitle=false&size=36846&status=done&style=none&taskId=u02f22093-c4f8-4d63-a5ee-f5be0335ddc&title=&width=737.6)

提取公共左因子、消除左递归例题

对于文法G=({a,b,c,d,},{S,A},S,P);
其中P为:
S → Aa|Ac|bc
A → Ad|Sbc|d
请先提取文法G的工共左因子,再消除左递归
![image.png](https://img-blog.csdnimg.cn/img_convert/b24e51e60868cb8fd1a717f8c728c3e6.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=424&id=u7bf77f9b&margin=[object Object]&name=image.png&originHeight=530&originWidth=865&originalType=binary&ratio=1&rotation=0&showTitle=false&size=137884&status=done&style=none&taskId=uda9d219c-9ebe-48e9-ac85-31b40ffa8dd&title=&width=692)

7-递归下降分析法

这个不在老师画的重点中 要考察麽?
![image.png](https://img-blog.csdnimg.cn/img_convert/a0682ad950b774fbabd77082951ed13b.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=462&id=ub4bad021&margin=[object Object]&name=image.png&originHeight=577&originWidth=954&originalType=binary&ratio=1&rotation=0&showTitle=false&size=74564&status=done&style=none&taskId=uedbb1815-5ebd-4691-a585-f85fe200a3f&title=&width=763.2)
![image.png](https://img-blog.csdnimg.cn/img_convert/ca96072e03c24424009691d79c250112.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=442&id=ueded4e09&margin=[object Object]&name=image.png&originHeight=593&originWidth=941&originalType=binary&ratio=1&rotation=0&showTitle=false&size=90876&status=done&style=none&taskId=u9d61bc94-96fc-494a-878d-2db732d3254&title=&width=701.7999877929688)

7-预测分析法


7-预测分析表的构建方法

预测分析表
对于LL(1)文法来说,在使用最左推导时,非终结符号的每一步推导使用的产生式是确定的,不用进行试探和回溯。
求预测分析表 要先求出来FIRST表
FIRST(α)中的每一个终结符号a,表格项M(A,a)=A→α
如果是非空串产生式A→α,求FIRST(α),对于FIRST(α)中的每一个终结符号a,M(A,a)=A→α
如果是空串产生式A→α,求FOLLOW(A),对于FOLLOW(A)中的每一个终结符号b,M(A,b)=A→ε
![image.png](https://img-blog.csdnimg.cn/img_convert/4c8ebab926f99dd6082533ec5d3bea2d.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=328&id=uD7uJ&margin=[object Object]&name=image.png&originHeight=410&originWidth=830&originalType=binary&ratio=1&rotation=0&showTitle=false&size=21790&status=done&style=none&taskId=u71f0d725-4f1a-4e88-b0d0-0abd94921d0&title=&width=664)

![image.png](https://img-blog.csdnimg.cn/img_convert/9789ab79289a15b4e8c03822a7b5b031.png#clientId=u041e7754-53fd-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=306&id=u1f0d26df&margin=[object Object]&name=image.png&originHeight=382&originWidth=877&originalType=binary&ratio=1&rotation=0&showTitle=false&size=12986&status=done&style=none&taskId=ube65de2c-4d93-4311-a474-5dd034d14e8&title=&width=701.6)

预测分析方法

![image.png](https://img-blog.csdnimg.cn/img_convert/fc750980d96ef90b7f783d51511ef2f3.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=330&id=ub7c44402&margin=[object Object]&name=image.png&originHeight=487&originWidth=923&originalType=binary&ratio=1&rotation=0&showTitle=false&size=49598&status=done&style=none&taskId=u571dc0e5-b5b1-434c-8264-1de90885470&title=&width=625.4000244140625)

例题

![image.png](https://img-blog.csdnimg.cn/img_convert/1806828b3073c0866da7648b9ea12474.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=328&id=u9726d230&margin=[object Object]&name=image.png&originHeight=410&originWidth=830&originalType=binary&ratio=1&rotation=0&showTitle=false&size=21790&status=done&style=none&taskId=u71f0d725-4f1a-4e88-b0d0-0abd94921d0&title=&width=664)
![image.png](https://img-blog.csdnimg.cn/img_convert/c593bf3bedca317cd8062247e63d2024.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=492&id=u480f2442&margin=[object Object]&name=image.png&originHeight=615&originWidth=704&originalType=binary&ratio=1&rotation=0&showTitle=false&size=45196&status=done&style=none&taskId=u333850e0-acd3-4951-aef4-33289163ba5&title=&width=563.2)
![image.png](https://img-blog.csdnimg.cn/img_convert/283b670c3761613e76347d1096dc11ff.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=489&id=u815b052b&margin=[object Object]&name=image.png&originHeight=611&originWidth=703&originalType=binary&ratio=1&rotation=0&showTitle=false&size=29563&status=done&style=none&taskId=u8ee1b364-854b-43f2-9879-bcc0f573645&title=&width=562.4)

7-FIRST集

![image.png](https://img-blog.csdnimg.cn/img_convert/35374bca1238bc72a91ce5aaa7fdd1ee.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=104&id=As0LL&margin=[object Object]&name=image.png&originHeight=196&originWidth=718&originalType=binary&ratio=1&rotation=0&showTitle=false&size=17814&status=done&style=none&taskId=uadc420bd-0f94-4ff7-8bb7-bf7b88fd783&title=&width=379.4000244140625)
大白话:

  • 非空串产生式
  1. 在所要求的字符产生式的右边的第一位寻找终结符,假设该字符产生式集的第一位就是终结符,那么该终结符就是所要求的first集;
  2. 假设产生式的右边第一位是非终结符,那么继续寻找该非终结符的first集,直至寻找到一个终结符,即是起初所要求字符的first集;
    ![image.png](https://img-blog.csdnimg.cn/img_convert/0595e8807b7de4b00cbdd733fb4a3f87.png#clientId=u041e7754-53fd-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=480&id=u1c6d8879&margin=[object Object]&name=image.png&originHeight=600&originWidth=448&originalType=binary&ratio=1&rotation=0&showTitle=false&size=14006&status=done&style=none&taskId=u81aeab0c-411e-43ef-b297-50b9e726509&title=&width=358.4)
    ![image.png](https://img-blog.csdnimg.cn/img_convert/aacd894a87dba927753da3bc19c72ddc.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=224&id=k7I4c&margin=[object Object]&name=image.png&originHeight=347&originWidth=329&originalType=url&ratio=1&rotation=0&showTitle=false&size=15420&status=done&style=none&taskId=u572ac25e-6bfd-4f10-a968-37c4f1596e1&title=&width=212)
    ![image.png](https://img-blog.csdnimg.cn/img_convert/00b92e85075811bea9dca0b74a478231.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=241&id=qKBTS&margin=[object Object]&name=image.png&originHeight=570&originWidth=934&originalType=binary&ratio=1&rotation=0&showTitle=false&size=66073&status=done&style=none&taskId=u47d99d5d-93b6-4924-b8c2-3a6156e8ceb&title=&width=394.20001220703125)
    ![image.png](https://img-blog.csdnimg.cn/img_convert/9c1b6be979a54a5262c332cdbcfe10e4.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=185&id=R9U3A&margin=[object Object]&name=image.png&originHeight=461&originWidth=974&originalType=binary&ratio=1&rotation=0&showTitle=false&size=45212&status=done&style=none&taskId=ue25d96d7-f8c4-457f-bc23-17beb748353&title=&width=390.20001220703125)
    ![image.png](https://img-blog.csdnimg.cn/img_convert/46d0609486dc4eee52379a2386dd49a8.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=142&id=u831d9d49&margin=[object Object]&name=image.png&originHeight=177&originWidth=588&originalType=binary&ratio=1&rotation=0&showTitle=false&size=16409&status=done&style=none&taskId=u7ed00a98-9708-4213-874b-b09dc7582ee&title=&width=470.4)
    ![image.png](https://img-blog.csdnimg.cn/img_convert/15360603e5d216a133a0985423bc7490.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=118&id=ufaee039d&margin=[object Object]&name=image.png&originHeight=147&originWidth=541&originalType=binary&ratio=1&rotation=0&showTitle=false&size=13489&status=done&style=none&taskId=u383951b6-37dd-48ca-ab87-9ddc529f4e6&title=&width=432.8)
    ![image.png](https://img-blog.csdnimg.cn/img_convert/fa20317f08f9fb86b81c2846dc1117a0.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=482&id=u251c6066&margin=[object Object]&name=image.png&originHeight=603&originWidth=854&originalType=binary&ratio=1&rotation=0&showTitle=false&size=34043&status=done&style=none&taskId=u65292550-7a9f-4833-92b9-0e73d26c810&title=&width=683.2)

7-FOLLOW集

https://www.jianshu.com/p/210fda081c76

  • 如果存在产生式A -> αBβ ,那么 FIRST(β)中所有非ε的符号都在FOLLOW(B)中;
    • ![image.png](https://img-blog.csdnimg.cn/img_convert/3e0a3fa1069e6eae6382386ddab29b58.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=92&id=u56000570&margin=[object Object]&name=image.png&originHeight=115&originWidth=406&originalType=binary&ratio=1&rotation=0&showTitle=false&size=4068&status=done&style=none&taskId=u182dbc11-df5a-4357-a98f-c4e773bd561&title=&width=324.8)
  • 如果存在产生式A -> αB,或者A -> αBβ 且FIRST(β)包含ε,那么FOLLOW(A)中的所有符号都加入到FOLLOW(B)中
    • ![image.png](https://img-blog.csdnimg.cn/img_convert/98e49521771f79bccab4e06f82eb9ff4.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=142&id=u242ef21c&margin=[object Object]&name=image.png&originHeight=177&originWidth=428&originalType=binary&ratio=1&rotation=0&showTitle=false&size=8842&status=done&style=none&taskId=u89bfac79-c721-46b3-8906-9d2ab15698b&title=&width=342.4)($=>#)

follow集的意义是寻找所要求字符的下一个字符可能产生的集合,所以寻找follow集应从产生式的右边进行寻找。

大白话求FOLLOW集

  1. 在产生式的右边找到相应的字符(从左到右第一个非终结符),假设紧跟其后的是一个终结符,那么该终结符就是所要求的follow集;
  2. 假设跟在其后的是一个非终结符,那么需要判断该非终结符是否可以为空:
  3. 假如可以为空,那么将该产生式的左边的follow集加入到寻找集合当中,
    1. 因为假如该非终结符为空的话,那么需要寻找产生这个非终结符的产生式左边的非终结符,因为产生式左边的非终结符的follow集就有可能是该非终结符的follow集;
  4. 假如不为空,那么寻找该非终结符的first集,并将结果加入到搜索集合当中。
  5. 直到不再有非终结符产生,找到所有的终结符,计算结束。

找L的Follow集,先从式子右边找到L——

![image.png](https://img-blog.csdnimg.cn/img_convert/f4274df24b97cea09df9b253cf89bdc7.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=163&id=u31646599&margin=[object Object]&name=image.png&originHeight=204&originWidth=499&originalType=binary&ratio=1&rotation=0&showTitle=false&size=93048&status=done&style=none&taskId=u310356e5-6c5d-4dde-a8d4-341310106ea&title=&width=399.2)

求follow集的算法

  • 默认将右端结束标记 # 放到 FOLLOW(S) 中
  • 按照下面两个规则不断迭代,直到所有的FOLLOW集合都不再增长为止
    • 如果存在产生式A -> *B),那么FOLLOW(B) = { ), # };——对应上面大白话的1
      • ![image.png](https://img-blog.csdnimg.cn/img_convert/2a45e9a2ca15b613cc02c17eb67ccb12.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=93&id=u87f51c5f&margin=[object Object]&name=image.png&originHeight=116&originWidth=339&originalType=binary&ratio=1&rotation=0&showTitle=false&size=5231&status=done&style=none&taskId=ud629c3a6-ff4b-4504-98a2-907dcd2808f&title=&width=271.2)
    • 如果存在产生式A -> *BC ,那么FOLLOW(B) = FIRST© - ε;——对应上面的2.b
      • ![image.png](https://img-blog.csdnimg.cn/img_convert/d79ff4fffcc0854a64e7ecfb7af263e0.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=91&id=u1902000b&margin=[object Object]&name=image.png&originHeight=114&originWidth=385&originalType=binary&ratio=1&rotation=0&showTitle=false&size=4582&status=done&style=none&taskId=u7ebdf6df-cbcf-4c34-ab83-5fa0ef39f82&title=&width=308)
      • ![image.png](https://img-blog.csdnimg.cn/img_convert/7f9355090e78e5f7563e9288d4cccc0c.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=102&id=u400fa169&margin=[object Object]&name=image.png&originHeight=127&originWidth=386&originalType=binary&ratio=1&rotation=0&showTitle=false&size=4880&status=done&style=none&taskId=u98f549f5-f603-42b6-99d6-32973da7786&title=&width=308.8)
    • 如果存在产生式A -> *B,或者A -> xxBC 且FIRST©包含ε,那么FOLLOW(B)=FOLLOW(A)——对应上面的2.a.i

求预测分析表过程中的应用

  • 空串产生式
    • ![image.png](https://img-blog.csdnimg.cn/img_convert/2b80b31d80662c446467b69037f09e95.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=64&id=afXje&margin=[object Object]&name=image.png&originHeight=80&originWidth=522&originalType=binary&ratio=1&rotation=0&showTitle=false&size=9179&status=done&style=none&taskId=uab731a0e-9c00-464f-92cd-d6aafc50963&title=&width=417.6)
    • ![image.png](https://img-blog.csdnimg.cn/img_convert/2dc57012f7ece69e22a2f00054e15373.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=328&id=bqboU&margin=[object Object]&name=image.png&originHeight=410&originWidth=959&originalType=binary&ratio=1&rotation=0&showTitle=false&size=45237&status=done&style=none&taskId=u95586747-b922-4c0e-a01b-204d0bcbc5e&title=&width=767.2)

LL(1)文法的判定

![image.png](https://img-blog.csdnimg.cn/img_convert/24bc76dcd024eee5bdc16c7dd4e8f928.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=288&id=u5a190891&margin=[object Object]&name=image.png&originHeight=360&originWidth=1178&originalType=binary&ratio=1&rotation=0&showTitle=false&size=519384&status=done&style=none&taskId=u0f6f2972-7717-4ef3-839d-61717372ebf&title=&width=942.4)
每一个推导式经过推导其对应的SELECT集的交集为空,其为LL(1)文法。

7-求first follow 预测分析表例题

p55之后

8-自下而上的语法分析——规约

![image.png](https://img-blog.csdnimg.cn/img_convert/d72c2112811f1f0b2b8d2327d2a4213a.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=214&id=u7e724d8a&margin=[object Object]&name=image.png&originHeight=268&originWidth=919&originalType=binary&ratio=1&rotation=0&showTitle=false&size=34303&status=done&style=none&taskId=ue6a22409-de56-4383-9300-12848086cb5&title=&width=735.2)
![image.png](https://img-blog.csdnimg.cn/img_convert/f4cc4d4f891d96ac33e94985942dddd1.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=276&id=ufc0b73ed&margin=[object Object]&name=image.png&originHeight=637&originWidth=1347&originalType=binary&ratio=1&rotation=0&showTitle=false&size=59428&status=done&style=none&taskId=uf6b896ee-be19-4e74-8d67-6f2dd4f59ef&title=&width=584.6000366210938)
![image.png](https://img-blog.csdnimg.cn/img_convert/bea8165e7bac466a6eae040e6c4a8a10.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=264&id=u4327d2e5&margin=[object Object]&name=image.png&originHeight=472&originWidth=964&originalType=binary&ratio=1&rotation=0&showTitle=false&size=25994&status=done&style=none&taskId=u970b0018-9e27-435d-9944-c8646ab3ecd&title=&width=539.2000122070312)

算符优先文法的判定

上下文无关文法G,没有形如P→ε或P→. . .QR. . .的产生式,则称G为算符文法
若算符文法G的任何终结符a,b之间的优先关系至多有=、>、<中的一个, 则G为算符优先文法

最左素短语分析法——基于算符优先表的下堆栈分析过程

![image.png](https://img-blog.csdnimg.cn/img_convert/c9f1e83d6a3a3e3206858988338a547f.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=334&id=ue30211a8&margin=[object Object]&name=image.png&originHeight=417&originWidth=600&originalType=binary&ratio=1&rotation=0&showTitle=false&size=36855&status=done&style=none&taskId=udd018193-16e3-4821-a232-9dc7b1d23e0&title=&width=480)
![image.png](https://img-blog.csdnimg.cn/img_convert/dadfdd6b6e91c05cee05d43341080c80.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=514&id=u5fa34c97&margin=[object Object]&name=image.png&originHeight=643&originWidth=1404&originalType=binary&ratio=1&rotation=0&showTitle=false&size=149264&status=done&style=none&taskId=u1ce59a54-886f-4931-a7a2-4836ce09c17&title=&width=1123.2)

-P21才到优先分析表 中间是一些规约的方法
![image.png](https://img-blog.csdnimg.cn/img_convert/33ec6dc1b315c6d8633c6685040f9237.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=290&id=u0e4d4d25&margin=[object Object]&name=image.png&originHeight=629&originWidth=1010&originalType=binary&ratio=1&rotation=0&showTitle=false&size=72652&status=done&style=none&taskId=u3211cf93-26dc-4224-b899-a281f851eae&title=&width=466)

![image.png](https://img-blog.csdnimg.cn/img_convert/8e0bcdf01dd877dbece1e3b13144ea01.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=203&id=u168dabc1&margin=[object Object]&name=image.png&originHeight=254&originWidth=603&originalType=binary&ratio=1&rotation=0&showTitle=false&size=28081&status=done&style=none&taskId=u502a3628-c35e-48fe-8e29-ca677c79a37&title=&width=482.4)

8-FIRSTVT集

![image.png](https://img-blog.csdnimg.cn/img_convert/2fc61ae5056d233f6ef9f724c11f9a67.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=289&id=ue8fa77f9&margin=[object Object]&name=image.png&originHeight=361&originWidth=850&originalType=binary&ratio=1&rotation=0&showTitle=false&size=34647&status=done&style=none&taskId=ua29d4e53-a0e3-4ae3-be28-19b06cd62c3&title=&width=680)

8-LASTVT集

![image.png](https://img-blog.csdnimg.cn/img_convert/916f05afa281e31826da1ec52a416c53.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=426&id=u79bbee6c&margin=[object Object]&name=image.png&originHeight=532&originWidth=880&originalType=binary&ratio=1&rotation=0&showTitle=false&size=39966&status=done&style=none&taskId=u4e143048-38a3-404c-9572-e86e9403b2b&title=&width=704)

8-*算符优先(分析)表的构造

![image.png](https://img-blog.csdnimg.cn/img_convert/ed2753c4ce508d58a5a62b1aa65988b6.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=293&id=ucd0c47cd&margin=[object Object]&name=image.png&originHeight=421&originWidth=835&originalType=binary&ratio=1&rotation=0&showTitle=false&size=37367&status=done&style=none&taskId=ucf52bffd-214f-4a8a-a169-1ff45a8c46e&title=&width=581)
![image.png](https://img-blog.csdnimg.cn/img_convert/dbd6ca166522c0792fee78b0c5030dd9.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=391&id=uc95f8d56&margin=[object Object]&name=image.png&originHeight=787&originWidth=1454&originalType=binary&ratio=1&rotation=0&showTitle=false&size=171812&status=done&style=none&taskId=ua40d5337-9bb8-4124-8a86-76bbfa184ca&title=&width=722.2000122070312)

规范句型的活前缀

最右推导就是规范推导,因此最右推导过程中产生的句型都是规范句型
活前缀:规范句型的不含句柄之后任何符号的一个前缀。
如:aAcde => aAbcde,句柄为A→Ab, 活前缀为:ε,a, aA, aAb

构造识别所有活前缀的转换图——识别全部活前缀的DFA

  • 构造分算符优先表的准备工作~
  • 推导的过程中注意——是否有重复的项目
    • 推导到后期一般就是看是否有重复项目了 I10前后

![image.png](https://img-blog.csdnimg.cn/img_convert/9bb9dd65b162e0190316476ac2c9adfd.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=383&id=uba5388c0&margin=[object Object]&name=image.png&originHeight=383&originWidth=563&originalType=binary&ratio=1&rotation=0&showTitle=false&size=86891&status=done&style=none&taskId=u4b6840a8-5642-4e90-ab32-d880d3da504&title=&width=563)

8-LR(0)分析法

关键:构建LR(0)分析表

  • 拓广文法
  • 识别全部活前缀的DFA

![image.png](https://img-blog.csdnimg.cn/img_convert/be4ffea12f1a32f620c1da293458781d.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=353&id=ua8fb22cf&margin=[object Object]&name=image.png&originHeight=498&originWidth=866&originalType=binary&ratio=1&rotation=0&showTitle=false&size=87962&status=done&style=none&taskId=u2a015848-8369-4615-bfbf-8b84b326065&title=&width=613.7999877929688)
![image.png](https://img-blog.csdnimg.cn/img_convert/254f304ca0f292b08674403e6ccd24c9.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=350&id=ub2b011ff&margin=[object Object]&name=image.png&originHeight=591&originWidth=840&originalType=binary&ratio=1&rotation=0&showTitle=false&size=43993&status=done&style=none&taskId=u1a79a095-f44a-4626-8321-21352ff9719&title=&width=498)

LR(0)项目集规范族的构造

*LR分析表的构造

https://www.cnblogs.com/xpwi/p/11070888.html
![image.png](https://img-blog.csdnimg.cn/img_convert/841a02a2797fa38f5aaef2f32c96ef73.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=442&id=ud4417740&margin=[object Object]&name=image.png&originHeight=684&originWidth=1173&originalType=binary&ratio=1&rotation=0&showTitle=false&size=234530&status=done&style=none&taskId=ub88980d7-58cd-4c67-b917-8443f993d80&title=&width=757.4000244140625)

![image.png](https://img-blog.csdnimg.cn/img_convert/756ae02700e18a9d818e424a8611094f.png#clientId=u041e7754-53fd-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=378&id=u97afd2a7&margin=[object Object]&name=image.png&originHeight=607&originWidth=513&originalType=binary&ratio=1&rotation=0&showTitle=false&size=23979&status=done&style=none&taskId=u03fda2f4-664e-4531-a45f-720c73f1d51&title=&width=319.3999938964844)
![image.png](https://img-blog.csdnimg.cn/img_convert/e3d86ce9366eb76acf1d39b746bc01d8.png#clientId=u041e7754-53fd-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=488&id=u0dae83e9&margin=[object Object]&name=image.png&originHeight=610&originWidth=858&originalType=binary&ratio=1&rotation=0&showTitle=false&size=53950&status=done&style=none&taskId=u17d8ac72-ccd6-4622-a886-6dc2fc2f376&title=&width=686.4)

基于LR分析表的分析过程

规约时退出的状态个数,规约后用goto判断下一状态

8-SLR(1)分析法

通过考察有关非终结符的FOLLOW集来解决移进-归约和归约-归约冲突——DFA中存在冲突项目(一个状态li中同时有移进、规约项目/有两个规约项目),以此构造出来的LR分析表,叫 做SLR(1)分析表
I={X→a•bb, A→a•, B→a•}
当状态I面临任何输入符号xi时,可采用如下策略:

  • 若xi=b,则移进
  • 若xi∈FOLLOW(A),则用产生式A→a归约
  • 若xi∈FOLLOW(B),则用产生式B→a归约
  • 此外,报错。

![image.png](https://img-blog.csdnimg.cn/img_convert/e2d78930f622bbb2d922e1bd2d5bbbbb.png#clientId=u7c804c2a-f82f-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=517&id=u438edcc6&margin=[object Object]&name=image.png&originHeight=1034&originWidth=1888&originalType=binary&ratio=1&rotation=0&showTitle=false&size=1522905&status=done&style=none&taskId=ubfe12e66-4a59-4ed0-ba5f-15b6f51dc5a&title=&width=944)

9-语法制导翻译

![image.png](https://img-blog.csdnimg.cn/img_convert/8649d1ac29cac1640a677569ec4faad1.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=401&id=ua3e1a7d3&margin=[object Object]&name=image.png&originHeight=501&originWidth=841&originalType=binary&ratio=1&rotation=0&showTitle=false&size=78804&status=done&style=none&taskId=u6d8f9516-6e18-46c3-897c-184e59336db&title=&width=672.8)
每使用一次产生式则调用相应的语义子程序,则推导完成时,语义值E.VAL也计算出来。

9-*语义子程序的翻译

9-*语句的四元式翻译

10-局部优化方法

![image.png](https://img-blog.csdnimg.cn/img_convert/ad8031099bef401e300eba9b5e6b383e.png#clientId=ub82bd813-5d31-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=111&id=u15fb3e50&margin=[object Object]&name=image.png&originHeight=111&originWidth=469&originalType=binary&ratio=1&rotation=0&showTitle=false&size=35572&status=done&style=none&taskId=uafe497b2-8ed0-44e4-940a-8c13c154829&title=&width=469)

10-全局优化方法

循环优化

10-翻译过程的寄存器分配

每次操作只能是寄存器-寄存器或寄存器-变量;不能是变量-变量

10-参数传递

引用调用(传地址)、值调用、名调用三种方式的输出结果

11-活动记录的内容

  • 临时变量、局部变量
  • 参数单元、参数个数
  • 现场保护
  • 静态链接、动态链接
  • 返回指针

11-三种存储分配模式——静态、栈式、堆

11-只含半静态变量的栈式分配

11-静态作用域

11-动态作用域

11-数据参数的传递方式

你可能感兴趣的:(计算机基础知识,r语言,开发语言)