%0 Journal Article %T 基于GCC的C语言抽象语法树重建与可视化研究
Study on AST Reconstruction and Visualization of C Language Based on GCC %A 林渤 %A 王枭雄 %A 胡建鹏 %J Software Engineering and Applications %P 654-660 %@ 2325-2278 %D 2021 %I Hans Publishing %R 10.12677/SEA.2021.105070 %X 抽象语法树(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. %K 抽象语法树,GCC,C语言,可视化
AST %K GCC %K C Language %K Visualization %U http://www.hanspub.org/journal/PaperInformation.aspx?PaperID=46158