11

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+.

Steve Shaner
  • 115
  • 1
  • 8
  • I know you want to use Python, but if you're looking for the "batteries included" you're going to be best off with F#... that language seems built for building compilers/interpreters. – sholsapp Jul 30 '10 at 17:17
  • 2
    @gnucom: Not only F#, but every language of the ML family is well-suited for language implementation. In fact, "ML" stands for "Meta Language". Haskell has some cool parser libraries (parsec), too. –  Jul 30 '10 at 17:25
  • @delnan: Absolutely. I stand corrected. :) – sholsapp Jul 30 '10 at 17:32
  • 1
    Are you "verifying some specified properties" at runtime or compile time? Just curious. –  Jul 30 '10 at 18:33
  • While it is probably not directly responsive, I'll note that the canonical compiler references question is [Learning to write a compiler](http://stackoverflow.com/questions/1669/learning-to-write-a-compiler). – dmckee --- ex-moderator kitten Jul 30 '10 at 18:37
  • @uncle brad: the proof of concept that gets me a PhD may end up doing neither, but I'm hoping for some compile-time (interpretation-time?) results first – Steve Shaner Jul 30 '10 at 19:00

3 Answers3

7

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 how to start writing a very simple programming language it has good ideas.il.

Community
  • 1
  • 1
sholsapp
  • 15,542
  • 10
  • 50
  • 67
1

maybe you want to have a look at this

AndersK
  • 35,813
  • 6
  • 60
  • 86
0

May I suggest antlr with its python binding?

µBio
  • 10,668
  • 6
  • 38
  • 56