华信教育资源网
编译原理简明教程
丛   书   名: 工业和信息化部“十四五”规划教材
作   译   者:费蓉 出 版 日 期:2022-06-01
出   版   社:电子工业出版社 维   护   人:孟宇 
书   代   号:G0435750 I S B N:9787121435751
定价 69.8
您的专属联系人更多
关注 评论(0) 分享
配套资源 图书内容 样章/电子教材 图书评价
  • 配 套 资 源

    本书资源

    本书暂无资源

    会员上传本书资源

  • 图 书 内 容

    内容简介

    内 容 简 介
    本书系统地介绍了编译程序的设计原理及实现技术。在内容的组织上,本书强调知识的实用性,有机地结合了编译的基本理论与具体的实现技术,既注重理论的完整性,化繁为简,又将理论融于具体的实例中,化难为易,以达到准确、清楚地阐述相关概念和原理的目的。在具体内容的讲述中,思路清晰、条理分明,给出的示例丰富,实用性与连贯性强,可使读者全面、直观地认识编译的各个阶段。本书采用的算法全部由C语言描述,各章均附有习题,且附录中提供了习题解答。
    本书既可作为计算机本科专业学生的教材,又可作为计算机软件工程人员的参考资料。

    图书详情

    ISBN:9787121435751
    开 本:16(185*260)
    页 数:300
    字 数:480

    本书目录

       

     

    1  绪论·························································································· 1

    1.1  程序设计语言和编译程序································································· 1

    1.2  编译程序的历史及发展···································································· 3

    1.3  编译过程和编译程序结构································································· 4

    1.4  编译程序的开发············································································ 6

    1.5  构造编译程序所应具备的知识内容······················································ 7

    习题1······························································································· 8

    2  词法分析··················································································· 10

    2.1  词法分析器的设计方法··································································· 10

    2.1.1  单词符号的分类与输出形式··························································· 10

    2.1.2  状态转换图············································································ 11

    2.2  一个简单的词法分析器示例····························································· 13

    2.2.1  C语言子集的单词符号表示··························································· 13

    2.2.2  C语言子集对应的状态转换图························································ 14

    2.2.3  状态转换图的实现···································································· 15

    2.3  正规表达式与有限自动机简介·························································· 17

    2.3.1  正规表达式与正规集·································································· 17

    2.3.2  有限自动机··········································································· 18

    2.4  正规表达式到有限自动机的构造······················································· 21

    2.4.1  由正规表达式构造等价的非确定有限自动机·········································· 21

    2.4.2  NFA的确定化········································································· 22

    2.4.3  确定有限自动机(DFA)的化简······················································ 24

    2.4.4  正规表达式到有限自动机构造示例··················································· 26

    2.5  词法分析器的自动生成··································································· 31

    习题2····························································································· 33

    3  文法和语言················································································· 36

    3.1  基本概念··················································································· 36

    3.1.1  文法和语言的定义···································································· 36

    3.1.2  文法产生的语言······································································· 38

    3.2  形式语言分类·············································································· 39

    3.2.1  四类文法的划分······································································· 39

    3.2.2  四类文法的关系与区别······························································· 40

    3.2.3  正规表达式与上下文无关文法························································ 42

    3.3  推导与语法树·············································································· 43

    3.3.1  推导与短语··········································································· 43

    3.3.2  语法树与二义性······································································· 44

    习题3····························································································· 49

    4  语法分析—自顶向下分析方法·························································· 51

    4.1  自顶向下分析原理········································································ 51

    4.1.1  自顶向下分析存在的不确定性························································ 51

    4.1.2  确定的自顶向下分析·································································· 52

    4.2  递归下降分析法··········································································· 56

    4.2.1  算术表达式的递归下降分析器························································ 56

    4.2.2  无二义性的算术表达式递归下降分析器··············································· 58

    4.3  LL(1)分析法················································································ 59

    4.3.1  表驱动的LL(1)分析器································································ 59

    4.3.2  LL(1)分析表的构造··································································· 62

    习题4····························································································· 66

    5  语法分析—自底向上分析方法·························································· 68

    5.1  自底向上分析原理········································································ 68

    5.2  算符优先分析法··········································································· 70

    5.2.1  算符优先文法········································································· 70

    5.2.2  算符优先关系表的构造······························································· 71

    5.2.3  算符优先分析算法的设计····························································· 74

    5.2.4  优先函数·············································································· 78

    5.3  LR分析器的工作原理···································································· 80

    5.4  LR(0)分析器··············································································· 86

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

    5.4.2  LR(0)分析表的构造··································································· 88

    5.5  SLR(1)分析器·············································································· 93

    5.6  二义文法的应用··········································································· 99

    习题5···························································································· 103

    6  语义分析和中间代码生成······························································ 107

    6.1  概述························································································ 107

    6.1.1  语义分析的概念····································································· 107

    6.1.2  语法制导翻译方法··································································· 107

    6.2  属性文法·················································································· 109

    6.2.1  文法的属性·········································································· 109

    6.2.2  属性文法············································································· 110

    6.3  几种常见的中间语言···································································· 111

    6.3.1  抽象语法树·········································································· 111

    6.3.2  逆波兰表示法········································································ 112

    6.3.3  三地址代码·········································································· 114

    6.4  表达式及赋值语句的翻译······························································· 116

    6.4.1  简单算术表达式和赋值语句的翻译·················································· 116

    6.4.2  布尔表达式的翻译··································································· 118

    6.5  控制语句的翻译·········································································· 123

    6.5.1  条件语句if的翻译··································································· 123

    6.5.2  循环语句的翻译····································································· 125

    6.5.3  三种基本控制结构的翻译···························································· 127

    6.5.4  多分支控制语句case的翻译························································· 132

    6.5.5  语句标号和转移语句的翻译························································· 134

    6.6  数组元素的翻译·········································································· 134

    6.6.1  数组元素的地址计算及中间代码形式················································ 135

    6.6.2  赋值语句中数组元素的翻译························································· 135

    6.6.3  数组元素翻译示例··································································· 136

    6.7  过程或函数调用语句的翻译···························································· 139

    6.7.1  过程或函数调用的方法······························································ 139

    6.7.2  过程或函数调用语句的四元式生成·················································· 140

    6.8  说明语句的翻译·········································································· 141

    6.8.1  变量说明的翻译····································································· 141

    6.8.2  数组说明的翻译····································································· 141

    6.9  递归下降语法制导翻译方法简介······················································ 142

    习题6···························································································· 143

    7  代码优化·················································································· 147

    7.1  局部优化·················································································· 147

    7.1.1  基本块的划分方法··································································· 147

    7.1.2  基本块的DAG方法································································· 148

    7.1.3  DAG进行基本块的优化处理····················································· 152

    7.1.4  DAG构造算法的进一步讨论························································ 153

    7.2  循环优化·················································································· 154

    7.2.1  程序流图与循环····································································· 154

    7.2.2  循环的查找·········································································· 156

    7.2.3  循环优化············································································ 161

    习题7···························································································· 169

    8  目标程序运行时存储空间的组织······················································ 173

    8.1  静态存储分配············································································ 173

    8.2  简单的栈式存储分配···································································· 174

    8.2.1  栈式存储分配与活动记录···························································· 175

    8.2.2  过程的执行·········································································· 176

    8.3  嵌套过程语言的栈式实现······························································ 179

    8.3.1  嵌套层次显示表和活动记录························································· 179

    8.3.2  嵌套过程的执行····································································· 180

    8.3.3  访问非局部名的另一种实现方法···················································· 182

    8.4  堆式动态存储分配······································································· 185

    8.4.1  堆式存储的概念····································································· 185

    8.4.2  堆式存储的管理方法································································ 186

    习题8···························································································· 188

    9  目标代码生成············································································ 190

    9.1  简单代码生成器·········································································· 190

    9.1.1  待用信息与活跃信息································································ 191

    9.1.2  代码生成算法········································································ 193

    9.1.3  寄存器分配·········································································· 194

    9.1.4  源程序到目标代码生成示例························································· 196

    9.2  汇编指令到机器代码翻译概述························································· 198

    习题9···························································································· 204

    10  符号表与错误处理····································································· 206

    10.1  符号表··················································································· 206

    10.1.1  符号表的作用······································································ 206

    10.1.2  符号表的组织······································································ 207

    10.1.3  分程序结构语言符号表建立························································ 208

    10.1.4  非分程序结构语言符号表建立······················································ 211

    10.1.5  常用符号表结构···································································· 212

    10.1.6  符号表内容········································································· 213

    10.2  错误处理················································································· 214

    10.2.1  语法错误校正······································································ 214

    10.2.2  语义错误校正······································································ 220

    习题10··························································································· 221

    附录A  8086/8088指令码汇总表······························································· 223

    附录B  8086/8088指令编码空间表···························································· 228

    附录C  习题解答·················································································· 230

    参考文献····························································································· 290

    展开

    前     言

     

        

     

    计算机语言之所以能由单一的机器语言发展到现今的数千种高级语言,就是因为有了编译技术。编译技术是计算机科学中发展得最迅速、最成熟的一个分支,它集中体现了计算机发展的成果与精华。

    “编译原理”是计算机专业的一门核心课程,在计算机本科教学中占有十分重要的地位。“编译原理”课程具有很强的理论性与实践性,读者学习起来普遍感到内容抽象、不易理解。为此,本书采用了由浅入深、循序渐进的方法来介绍编译原理的基本概念和实现方法。在内容的组织上,本书有机地结合了编译的基本理论与具体的实现技术,既注重理论的完整性,化繁为简,又将理论融于具体的实例中,化难为易,以达到准确、清晰地阐述相关概念和原理的目的。各章节的理论阐述具有条理性,给出的例子也具有实用性与连贯性,可让读者全面、直观地认识编译的各个阶段,进而透彻地领悟编译原理的精髓。

    本书立足于“看得懂、学得会、用得上”,以编译核心知识为纲,以实用实现技术为主,以丰富的示例实践为线,侧重于编译理论的具体实现。书中的算法全部采用C语言描述,文法也尽可能采用C语言文法。

    本书共10章。第1章简要介绍编译的基本概念;第2章介绍词法分析的相关内容,主要涉及正规表达式与有限自动机;第3章简要地介绍文法的有关概念;第4章介绍自顶向下语法分析方法——递归下降分析法和LL(1)分析法;第5章介绍自底向上语法分析方法——算符优先分析法和LR分析法;第6章介绍语法制导翻译与中间代码生成的有关内容,给出如何在语法分析的同时进行语义加工并产生中间代码的方法;第7章介绍代码优化的有关内容,主要涉及基本块优化和循环优化;第8章介绍目标程序运行时存储空间的组织;第9章讨论目标代码生成的有关内容,讲述如何由中间代码产生最终目标代码;第10章简要地介绍符号表的组织与错误处理的方法。

    为便于读者正确地理解有关概念,各章配有一定数量的习题,且附录中给出了答案。这些习题大多选自本科生/研究生的考试题,也包括编者结合多年教学实践经验设计的典型范例,力求让读者抓住重点、突破难点,全面、深入地巩固所学知识。

    由于编者水平有限,书中难免存在一些缺点和错误,恳请广大读者批评指正。

     

         

    20223


     

     

     
     

    展开

    作者简介

    本书暂无作者简介
  • 样 章 试 读
  • 图 书 评 价 我要评论
华信教育资源网