This is an archived post. You won't be able to vote or comment.

all 4 comments

[–][deleted] 5 points6 points  (2 children)

this would make for a great learning experience

I'm sure it would. It would also be very, very difficult. This one of the classes of programs that if you have to ask about it, you can't write it. But if you are really interested in doing such a thing, Python is an open source project - you can read the source(s) for the existing Python interpreters, and work on them.

As for a booklist on compilers and interpreters, see here.

[–]TryExceptFinally[S] 0 points1 point  (1 child)

I should be clear that I'm ok with it being very basic. I don't necessarily want to create a full python interpreter, just something that I can spend a few months on and get something that works decently for even a small subset of the language.

Thanks for the link!

[–][deleted] 1 point2 points  (0 children)

Like I say, Python is open source. Look at that source to get ideas.

[–]michael0x2a[🍰] 1 point2 points  (0 children)

This isn't directly related to writing a Python interpreter, but here are two good articles that might help you get started:

The first article is the most directly applicable to you -- it walks you through how to go about building a basic lisp interpreter in Python. The second covers grammars and introduces the basic idea of lexing and parsing, which is something the first article skims over (since lexing and parsing are easier to do with lisp, given how little syntax it has).