|
基于GCC的C语言抽象语法树重建与可视化研究
|
Abstract:
抽象语法树(abstract syntax tree, AST)作为一种重要的中间表示形式,在代码静态分析领域有着重要的研究意义。本文通过研究GCC生成的抽象语法树文本内容,给出重建抽象语法树及可视化的方法。GCC编译器生成的抽象语法树内容存在大量冗余,不能直接进行解析。针对此问题,本文提出一种改进的去冗余算法,从根节点中先找到main函数后进行遍历,相比常规的去冗余算法有更高的效率,同时针对可视化操作进行了结构性的优化,能够将原始的文本转换为JSON字符串,配合web树形控件的展示形式实现了可视化界面。
The abstract syntax tree (AST), as an important intermediate representation, plays an important role in the field of static analysis of code. This paper gives a method to reconstruct and visualize the AST based on the textual content of the AST generated by the GCC compiler. The contents of the abstract syntax tree generated by the GCC compiler are heavily redundant and cannot be parsed directly. To address this problem, this paper proposes an improved redundancy removal algorithm, which finds the main function from the root node first and then traverses it. It is more efficient than the conventional redundancy removal algorithm and is easy to convert the raw text of AST into JSON strings. Compared with the conventional redundancy removal algorithm, it has higher efficiency and structural optimization for visualization operation, which can convert the raw text of AST into JSON string and realize a visual interface with the presentation of web tree control.
[1] | 徐伟, 陈凯明, 马建辉, 赵家兴. 计算机专业程序设计课程在线教学改革探究[J]. 软件导刊, 2020, 19(12): 181-184. |
[2] | Richard, M. and Stallman, G.N.U. (2003) Compiler Collection Internals. http://gcc.gnu.org/onlinedocs/gccint |
[3] | 焦秀秀. 基于抽象语法树的C编程题自动评分方法研究及应用[D]: [硕士学位论文]. 西安: 西安理工大学, 2019. |
[4] | 周风顺, 王林章, 李宣东. C/C++程序缺陷自动修复与确认方法[J]. 软件学报, 2019, 30(5): 1243-1255. |
[5] | 冯君远, 赖明钦, 李启良. C语言源代码抄袭识别的研究[J]. 福建电脑, 2013, 29(5): 34-36. |
[6] | Young-Chul, K. and Jaeyoung, C. (2005) A Program Similarity Evaluation Using Keyword Extraction on Abstract Syntax Tree. The KIPS Transactions: PartA, 12A, 109-116. https://doi.org/10.3745/KIPSTA.2005.12A.2.109 |
[7] | 于俊, 李雅洁, 程礼磊, 连顺, 谭昶, 丁德成, 刘淇. 高教程序代码作业抄袭检测的方法研究与实践[J]. 中国科学技术大学学报, 2020, 50(8): 1048-1057. |
[8] | 张启航. 基于抽象语法树的代码缺陷检测技术设计与实现[D]: [硕士学位论文]. 北京: 北京邮电大学, 2020. |