Parsing C

Alan Kennedy alanmk at hotmail.com
Tue Apr 1 03:07:07 EST 2003


Daniel Timothy Bentley wrote:
> 
> Hey,
> I find myself having to write a C interpreter in Jython.  Are there any
> useful C compilers that are open-source in python?

Is it coincidence that your post appeared in the newsgroup on April 1st
;-) ?

> Or compiler-compilers that have files for a C compiler available?
> 
> Or, compiler-compiler-compilers that have files for a compiler-compiler
> that have files for a C compiler available available?
> 
> Really, I'm looking for a way to get a C compiler and mildly painlessly
> build it to create the AST that my program will look for.
> 
> Oh, and the lexer in addition to the parser would be nice, but I bet
> it's all easy and fully of re-goodness in {p|j}ython.

I think one possible path for you is to use ANTLR, which is written in
Java and thus usable with Jython. There are ANTLR grammar files for C,
C++, and a host of other languages. Also ANTLR is very sophisticated in
terms of the representations that it builds, e.g. AST's, etc, and in
terms of the ways in which you can manipulate these representations, for
optimisation, etc. 

More from

http://www.antlr.org/

-- 
alan kennedy
-----------------------------------------------------
check http headers here: http://xhaus.com/headers
email alan:              http://xhaus.com/mailto/alan




More information about the Python-list mailing list