views:

160

answers:

3

Right now I'm writing my PhD proposal to build a language processor for a new specification language for Java (cf. JML, or Spec# for C#) and need to nail down an implementation tool to start development. The research aspects of the language (syntax, semantics, theoretical results) are orthogonal to my choice of implementation, so I'd like to use Python (2.6+) for my own reasons. The end-product will be either a compiler or interpreter capable of verifying some specified properties for programs written in Java.

What's the best framework/library for building compilers/interpreters in Python? Are the "batteries included" for this problem?

Bonus points awarded to solutions that have reference compilers for Java 6+.

+1  A: 

maybe you want to have a look at this

Anders K.
Why do you recommend the ANTLRv2 Python runtime when one also exists for ANTLRv3?
Steve Shaner
Particularly, what tradeoffs are there for Python that aren't already covered in this question? http://stackoverflow.com/questions/633224/antlr2-vs-antlr3
Steve Shaner
Ok, neither seem robust enough for this research. Thanks for pointing me to ANTLR+Python, though!
Steve Shaner
A: 

May I suggest antlr with its python binding?

BioBuckyBall
oops, too slow :)
BioBuckyBall
+4  A: 

I personally can't stand antlr, I use lex/yacc as my parser generator. Here is a Python implementation http://www.dabeaz.com/ply/ that you could use.

That just deals with parsing though, that really doesn't even begin to construct your interpreter. For that, you'll probably be building it from the ground up - I've never heard of a library specifically geared towards this (I would be excited to see some of them, please link me there in the comments if you know of any).

Check out this SO post http://stackoverflow.com/questions/3008375/how-to-start-writing-a-very-simple-programming-language/3009147 it has good ideas.il.

gnucom
I'm picky about the quality of error reporting, so I prefer Anders' ANTLR-based suggestions to these.
Steve Shaner