[antlr-interest] grammars with AST support

Thomas Brandon tbrandonau at gmail.com
Thu Feb 7 07:10:44 PST 2008


On Feb 7, 2008 7:21 AM, Peter Bulychev <peter.bulychev at gmail.com> wrote:

> Hello.
>
> I perform research on static analysis and my tool takes on input AST
> representation of programs.
> I want to use ANTRL to produce ASTs for different programming languages
> (C, C++, C#, Java, Python, ...).
> Where can I get grammars which can produce AST?
>
> I have searched http://www.antlr.org/grammar/list, but there are no
> AST-featured grammars, which supports this ability.
>
Search the list I think grammars for all the languages you mention, though
not necessarily with ASTs.
There were some people working on AST producing grammars for Java, search
the list. Or see Johannes for C#. There has been some talk about converting
the ANTLR 2.7 GCC grammar to v3 but don't know that went anywhere. There is
a C grammar for V3 in the examples but I don't know how well tested it is
and from memory it doesn't produce an AST. Unsure about Python though I
think one of the Python implementations may use ANTLR, came up on the list
recently.
It is possible in ANTLR but depending on your needs it could be a rather
difficult task. Writing the parser for a compiler say, while certainly
possible in ANTLR, is a very large task. Handling program errors in a
sensible way is a quite difficult. If you don't need to handle errors
particularly sensibly then the task is easier but still a big undertaking.
It also depends on the language. C# and Java are (for the most part) fairly
clean languages to parse. C\C++ are rather more tricky. Not sure about
Python.
Depending on the details of your project you may be better looking at
alternate solutions. e.g. CodeDOM for .NET, Java Compiler API, GCC's -fdump
for C\C++, one of the Python implementations. Building and maintaining a
language front-end is no small task, ANTLR makes it quite easy to do the
basic parsing but there's a lot more to it than that, depending on the exact
needs.

Tom.

>
> --
> Best regards,
>    Peter Bulychev.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080208/db6064c8/attachment.html 


More information about the antlr-interest mailing list