开发者

antlr C grammar to create AST

Is there any C grammar available which generates the AST, which includes all the parser rules using "^" and "开发者_JS百科!" notations?

I went through the book written by Terence Parr, to write such a grammar, but it seems that writing one such grammar for C lang is a time consuming process, so was wondering if its available already which can me save a lot of time!

(A grammar for a smaller subset of C language is also fine..)

Thanks :)


See this. It's straight from the ANTLR 4 source repo: a C11 grammar. It looks pretty compliant.

Of course, it doesn't come with a preprocessor, but handing cpp or mcpp the file first is easy enough.

It also doesn't come with AST rules, but it doesn't look too hard to do (albeit time consuming).


No answers after two weeks.

You are right, building a full parser that builds complete ASTs and handles all the details of C (including preprocessor) covering a variety of dialects of C (e.g., ANSI, GNU C 2/3/4/, Miscrosoft Visual C, Green Hills C)... is actually a lot of work. And unless you invest this work, it won't process any real C programs.

I would expect there to be a full ANTLR grammar for C that did this considering how old ANTLR is. It is surprising that nobody here can seem to identify one; certainly you'd expect to find it at the ANTLR site.

We've put the energy required into building such C parsers (covering all the above dialects), and added computing symbol tables, extracting control and data flows, building call graphs, enabling analyzers, and tree transformations in the DMS Software Reengineering Toolkit with its C front end. This front end has been applied to C applications comprised of 18,000 compilation units to build custom analysis tools.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜