On Apr 24, 2012, at 1:41 PM, Giordano Bruno wrote:
> Any links or code template for doing simple translation from Python to
> Smalltalk (or other programming language for the case).
Jython converts Python to Java byte code, and Iron Python does the same for the
.Net environment.
PyPy converts Python to multiple back ends. For example, it has Javascript as a
proof-of-concept back end.
Cython takes a Python-like language and generate C code which uses the Python
runtime, and Nuitka is a different approach.
HOWEVER! Those handle the deep semantics, like operator overloading and
metaclasses. If you want simple syntactic translation then you can do that with
Python's 'ast' module. Here's how to get the AST:
>>> import ast
>>> compile("for x in [1,2,3]: print x", "<string>", "exec", ast.PyCF_ONLY_AST)
<_ast.Module object at 0x10c6308d0>
>>> module = compile("for x in [1,2,3]: print x", "<string>", "exec",
>>> ast.PyCF_ONLY_AST)
>>> ast.dump(module)
"Module(body=[For(target=Name(id='x', ctx=Store()), iter=List(elts=[Num(n=1),
Num(n=2), Num(n=3)], ctx=Load()), body=[Print(dest=None, values=[Name(id='x',
ctx=Load())], nl=True)], orelse=[])])"
>>>
With some tree walking you can get the basics of what you want pretty quickly.
Since you're probably a Smalltalk fan, you could even dump the AST into text
format, read it into a Smalltalk data structure, and let Smalltalk do the
translation/evaluation.
Andrew
[email protected]
--
You received this message because you are subscribed to the Google Groups
"ply-hack" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/ply-hack?hl=en.