ANTLR生成对C AST和解析AST [英] antlr generate ast for c and parse the ast

查看:959
本文介绍了ANTLR生成对C AST和解析AST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做静态分析c上发展项目中我搜索网站ANTLR,似乎有产生对C program.Does AST没有合适的语法文件这意味着我必须做我自己从一start.Or是有一个更快的method.I还​​需要一个树分析器可以遍历由解析器创建的AST。

I am doing static analyze on c program.And I search the antlr website ,there seems to be no appropriate grammar file that produce ast for c program.Does it mean I have to do it myself from the very start.Or is there a quicker method.I also need a tree parser that can traverse the ast created by the parser.

推荐答案

您表示你想要做静态分析来检测缓冲区溢出。

You indicated you want to do static analysis to detect buffer overflow.

首先,写一个文法C是比看起来难。还有所有的东西在标准,然后有什么真正的编译器实际上接受。你必须决定怎样做的preprocessor(它因编译器而异!)。如果你没有得到的语法和preprocessing完全正确,你将无法解析真实程序。 (如果你想要做的玩具语言,这很好,但你并不需要一个C语法)。

First, writing a grammar for C is harder than it looks. There's all that stuff in the standard, and then there's what the real compilers actually accept. And you have to decide what to do about the preprocessor (and it varies from compiler to compiler!). If you don't get the grammar and preprocessing exactly right, you won't be able to parse real programs. (If you want to do toy languages, that's fine, but then you don't need a C grammar).

做了分析,你需要的的一个多AST机器。你需要符号表,控制和数据流分析,可能当地和全球指向的分析,调用图提取和某种类型的范围的分析。

To do the analysis, you'll need far more machinery than an AST. You'll need symbol tables, control and data flow analysis, likely local and global points-to analysis, call graph extraction, and some type of range analysis.

人们似乎就是不明白这一点。

**获取解析器很长的路要走做任何事情与真正的语言有用**

** GETTING A PARSER IS A LONG WAY FROM DOING ANYTHING USEFUL WITH REAL LANGUAGES **

我喊,因为我看到过,过,过。

I'm shouting because I see this over, and over, and over.

如果你想获得与特定的程序分析或改造任务,除非你想你开始你的任务之前,老死的,你最好找有你最需要的东西已经奠定了基础。在一个摇摇欲坠的语法解析器生成一个基础并不奠定了基础。 (不要误会我的意思:ANTLR,YACC,JavaCC的无一不精解析器生成器,他们是伟大的建设解析器一种新的语言他们是伟大的,当投资被提出实施真正的汉语语言解析器生产。但是,他们生产的解析器的,而且大多人都不做生产的一部分。他们不提供由一个长镜头额外的机械。)

If you want to get on with a specific program analysis or transformation task, unless you want to die of old age before you start your task, you better find a foundation that has most of what you need already. A foundation on a parser generator with a creaky grammar is not a foundation. (Don't get me wrong: ANTLR, YACC, JavaCC are all fine parser generators, and they're great for building a parser for a new language. They're great for implementing production parsers for real langauges when the investment gets made. But they produce parsers, and mostly people don't do the production part. And they don't provide the additional machinery by a long shot.)

我们的 DMS软件再造工具包包含上述所有的机器,因为它几乎是总是需要,是实现王室头痛。 (我的团队有15年至今的投资。)

Our DMS Software Reengineering Toolkit contains all the above machinery because it is almost always needed, and it is a royal headache to implement. (My team has 15 years invested so far.)

我们也已经实例化机械形式是专为 COBOL和Java,C,C ++ (在一定程度较小的程度上,语言真的很难),在各种方言,让别人不必重复这个漫长的过程。

We've also instantiated that machinery is forms specifically useful for COBOL and Java, C, C++ (to somewhat lesser extent, the language is really hard), in a variety of dialects, so that others don't have to repeat this long process.

GCC和Clang的是pretty成熟的C和C ++作为替代。

GCC and Clang are pretty mature for C and C++ as alternatives.

这篇关于ANTLR生成对C AST和解析AST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆