登录

  • 登录
  • 忘记密码?点击找回

注册

  • 获取手机验证码 60
  • 注册

找回密码

  • 获取手机验证码60
  • 找回
毕业论文网 > 毕业论文 > 计算机类 > 软件工程 > 正文

编译器符号表及属性文法的设计与实现毕业论文

 2021-04-14 10:04  

摘 要

经过半个世纪的研究和实践,成就了现在编译技术。在现代计算机科学中,编译程序是屈指可数的抽象概念彻底改变程序编写方式的领域之一,是现代计算机技术中最重要的应用基础研究之一,编译程序的基本任务是将源程序翻译成等价的目标语言程序。编译过程的六个主要阶段任务完全可以分别由六个模块完成,分别是词法分析程序,语法分析程序,语义分析程序,中间代码,代码优化程序和目标程序生成程序。除此之外,一个完整的程序还必须包括相应的表格管理程序和出错处理程序。而符号表的设计是编译技术中无可替代的一个环节。学习和研究符号表技术,并予以实践,具有重要意义的。

符号表是编译程序中用到的最重要的数据结构之一,几乎在编译的每个阶段都要涉及到符号表。符号表自创建后便开始被用于收集符号的属性信息,所以熟悉和掌握符号表及其文法属性已成必然。从20世纪60年代以来,编译器设计就一直是计算机研究发展和开发领域中的一个活跃主题。虽然编译器设计已有很长的历史,并且也是一门相对成熟的计算机技术,但编译器毕竟是一种实现由高级语言源程序至机器或汇编指令的高效映射工具,随着计算机软、硬件水平的飞速发展,使得计算机应用日新月异,程序语言的设计在不断地变化,目标机体系结构也在不断地改进,软件越来越复杂,其规模也越来越大。

尽管编译器设计问题在高级层次上没有变化(或变化很小),但当我们深入其内部研究时就会发现,编译器的内部构造其实也一直在变化。此外,由于我们能够提供给编译器本身使用的计算资源也在不断增加。因此,现代编译器可以采用比以前更耗费时间和空间的算法。当然,编译技术研究人员也在继续努力开发新的、更好的技术来解决传统编译器的一些设计性问题。

属性文法用于描述语法和语义动作,本文属性文法是上下文无关文法的相关文法提供了一种描述语义的形式化表示,分析语法树结点表示的属性信息流传递方向。属性文法是利用语法分析阶段生成的语法树作为标识符信息的中间表示形式,采用从 左到右、从底而上的属性流方向以一趟的方式被直接翻译的实现方案。最后,试验运行代码并与预期结果进行比较,除少部分有误差外结果基本一致,对于不完美的地方仍然需要继续努力修改,在后来的研究中会进行改进优化的。

关键词:编译器,符号表,属性文法

Abstract

After half a century of research and practice, the compiler technology has been achieved. In modern computer science, compiler is one of the most important applications of modern computer technology, which is one of the most important applications in modern computer technology. The basic task of the compiler is to translate the source program into the equivalent target language. The six main stages of the compilation process can be completed by six modules, namely, the lexical analysis program, the syntax analysis program, the semantic analysis program, the middle code, the code optimizer and the target program generating program. In addition, a complete program must include the corresponding form management procedures and error handling procedures. The design of symbol table is an irreplaceable part in compiling technology. It is of great significance to learn and study the symbol table technology and practice it.

Symbol table is one of the most important data structures used in compilers. Almost every phase of compilation involves symbol tables. Since the symbol table has been created, it has been used to collect attribute information of symbols. Therefore, it is necessary to familiarise and master the symbol table and its grammatical attributes. Since 1960s, compiler design has been an active topic in the field of computer research and development. Although compiler design has a long history, and is also a relatively mature computer technology, the compiler is an efficient mapping tool from advanced language source program to machine or assembly instruction. With the rapid development of computer software and hardware, the application of computer is changing rapidly. The design of language is constantly changing, and the architecture of the target machine is constantly improving. Software is becoming more and more complex and its scale is bigger and bigger.

Although compiler design issues are not changed at the advanced level (or very small), when we go deep into the internal research, we find that the internal structure of the compiler has been changing. In addition, the computing resources that we can provide to the compiler itself are also increasing. Therefore, modern compilers can use more time and space algorithms than before. Of course, compiler technology researchers are also working hard to develop new and better technologies to solve some of the design problems of traditional compilers。

Attribute grammars are used to describe grammatical and semantic actions. This article provides a formal representation of the description semantics of the context free grammar, and analyzes the direction of the transfer of the attribute information flow expressed by the syntax tree nodes. The attribute grammar is an implementation scheme that uses the grammar tree generated by the grammatical analysis stage as the intermediate representation of the identifier information, and is translated directly from the left to right, from the bottom to the direction of the attribute flow.

Finally, the test run code is compared with the expected results, with the exception of a few errors, the results are basically consistent. For the imperfect place, we still need to continue the effort to modify it, and the later research will be improved and optimized.

Key words: compiler, symbol table, attribute grammar

目 录

摘 要 3

Abstract 4

第1章 绪 论 1

1.1引言 1

1.2编译程序概述 1

1.3课题研究现状 2

1.4论文的研究内容和意义 3

第2章 编译过程 4

2.1 词法分析 4

2.1.1词法分析程序的识别与输出 5

2.1.2 词法分析编译过程图 5

2.2语法分析 6

2.2.1自顶向下语法分析方法 7

2.2.2 自底向上语法分析方法 7

2.3属性文法 11

2.3.1继承属性 11

2.3.2综合属性 11

2.3.3固有属性 11

2.3.4语义计算 11

2.4符号表 12

2.4.1符号表的实现 12

2.4.2 符号表的操作 12

2.5本章小结 13

第3章 符号表的设计与实现 14

3.1符号表的体系结构 14

3.1.1类型信息 14

3.1.2函数信息 17

3.2声明定义与实现 17

3.2.1 类型说明符 18

3.2.2枚举类说明符Enum specifiers 19

3.2.3类型名称 19

3.2.4类型定义 20

3.3本章小结 20

第4章 属性文法的设计与实现 21

4.1属性文法的赋值形式与规则 21

4.2语法树输出表示 21

4.3符号表作为属性 22

4.4属性文法的处理方式 22

4.4.1树遍历的属性计算方式 22

4.4.2直接属性计算方法 23

4.5本章小结 23

第5章 总结与期望 24

5.1总结 24

5.2期望 24

参考文献 25

致 谢 26

第1章 绪 论

1.1引言

科技发展迅速,计算机应用于生活无处不在渐渐的人们已经离不开网络,在这个互联网时代计算机带给我们便利,帮助我们改造环境,设计生活用品,我们依赖计算机。而这些计算机运行用到某种设计设计语言编写的一系列操作,由软件程序来完成 它们的应用。然而几乎所有的软件都需要某种翻译工具来进行转换成机器可运行 的目标程序,被称为编译器。编译器也是包含在计算机范围内的一种程序,它是把一种源程序翻译成其它的计算机目标程序,使之准备好执行。编译程序在计算机科学与技术的发展史中发挥了重要的角色,是支持计算机的核心技术。

编译器是一个庞大的、繁杂的、系统化的工程,由诸多的子系统和组件构成,而它们是错综复杂的又相互交织在一起,它是一个成功将抽象理论应用于现实问题的例子,是一个包含计算机科学技术的缩影。

1.2编译程序概述

编译程序是现代计算机系统的基本组织部分之一,编译程序的重要体现在与它使得多数计算机用户不必考虑与机器有关的复杂细节,使程序员与设计专家独立于机器,这对如今机器数量的增长的时代至关重要,编译器以一个源程序的表示形式[1]作为输出。编译程序的功能是将高级程序语言源程序转换成低级语言机器语言[2],本过程有几部分组成,需要处理的源程序经过预处理程序转化源程序之后经过编译程序转化成目标汇编语言程序在经过汇编程序生成装配的机器代码最后经过装配程序转化成绝对机器代码。

编译可划分为两个部分:分析和综合。分析部分就是分析源程序的语言结构,收集符号信息,用于分析语义,并以某种中间形式表示出来,即将源程序翻译成一种与机器无关的中间表示。综合部分是将分析部分所产生的中间表现形式,经过优化器和代码生成器所执行的综合任务,加工出机器相关的目标语言程序。编译过程由源程序到词法分析,语法分析,语义分析到中间代码,代码优化,再到目标代码生成。

您需要先支付 80元 才能查看全部内容!立即支付

企业微信

Copyright © 2010-2022 毕业论文网 站点地图