Search code examples
pythoncompiler-constructionprogramming-languagesinterpreterpypy

Interpreter design in Python


I am new to Python, and I want to make a small interpretor/compiler with it. just a hobby project initially. I would like to know how good is it in comparison to c/c++ to accomplish such a job? it has highly efficient string processing library built in it. So i guess it would be initially easy to start off (see links bellow) but to build a language will it do well when the complexity really becomes high?

some resources

http://www.jayconrod.com/posts/37/a-simple-interpreter-from-scratch-in-python-part-1

This one is really simple but good to start :

http://www.jroller.com/languages/entry/python_writing_a_compiler_and

Another place to visit :

http://morepypy.blogspot.in/2011/04/tutorial-writing-interpreter-with-pypy.html

http://morepypy.blogspot.in/2011/04/tutorial-part-2-adding-jit.html

the lst one uses pypy though. and I am not familiar with it. I am using cpython


Solution

  • It really depends on how complex your language is. I wouldn't use Python for a C++ compiler, but I found it very convenient for writing code generators that parsed code in one language, specifically the data definition subset of SQL, to generate code in another language.

    Consider using a parser generator, rather than do it all by hand. I find PLY very convenient.