作者投稿和查稿 主编审稿 专家审稿 编委审稿 远程编辑

计算机工程 ›› 2008, Vol. 34 ›› Issue (9): 93-94,9. doi: 10.3969/j.issn.1000-3428.2008.09.033

• 软件技术与数据库 • 上一篇    下一篇

面向对象技术在C编译器OCC中的应用

任 杰1,阳 昕1,石 磊2,陈 渝1,杨维康1   

  1. (1. 清华大学计算机科学与技术系,北京 100084;2. 武警工程学院基础部,西安 710086)
  • 收稿日期:1900-01-01 修回日期:1900-01-01 出版日期:2008-05-05 发布日期:2008-05-05

Application of Object-oriented Technique in the OCC C Compiler

REN Jie1, YANG Xin1, SHI Lei2, CHEN Yu1, YANG Wei-kang1   

  1. (1. Dept. of Computer Science and Technology, Tsinghua University, Beijing 100084; 2. Dept. of Foundation, Engineering College of Armed Police Force, Xi’an 710086)
  • Received:1900-01-01 Revised:1900-01-01 Online:2008-05-05 Published:2008-05-05

摘要: 对面向对象的C编译器(OCC)的整体设计进行介绍。OCC以抽象语法树为中间表达形式。语法树节点分为8大类86种,降低了在采用visitor设计模式进行语意分析时节点功能的耦合度。OCC用简易的垃圾回收器解决了语法树节点动态分配和销毁时的内存泄漏问题。OCC的类型分析模块针对类型声明中9个不同组成部分采用7种处理方式,降低了属性文法脚本的维护难度。

关键词: 设计模式, 抽象语法树, 编译器

Abstract: The architecture of the C compiler OCC is introduced. The Abstract Syntax Tree(AST) served as the intermediate representation, of which the 86 different nodes are grouped into 8 categories and the coupling degree of the semantic analysis with the visitor design pattern is reduced. The memory leak problem during the dynamic allocation and destruction of abstract syntax tree nodes is solved using a simple garbage collector. A type builder module gives 7 different treatments to 9 parts of the type specification, which ease the maintenance problem of the attribute grammar script.

Key words: design pattern, Abstract Syntax Tree(AST), compiler

中图分类号: