pradyun/Py2C — pull request #5 by Aurey (2014-05-25 19:02:09+00:00)
Title: Framework for the AST2CPP translator

I added the framework to turn the PyAST generated into C++ code. For some reason, the python.py file containing all the PyAST definitions does not seem to be able to be edited, and I don't know any ply.lex stuff, so I created NewAST and added the changes there. It's trivial to switch back and forth between them, but just to be safe I made translator into translator2.py. I've coded the return clause and string C++ translation in NewAST, and those seem to work fine.

Code: (in translator2.py)
s = """
def HelloWorld():
return("0")
def OhMyGosh():
return("Hallelujah")
def Cool():
return("1+1=2")
"""

Output: (from running translator2.py)
CPPTranslator Initialized!
void HelloWorld() {
return "0";
}
void OhMyGosh() {
return "Hallelujah";
}
void Cool() {
return "1+1=2";
}
( of course, the functions shouldn't be voids; I'll fix that when PyAST supports types other than literals)

Even if this isn't the way you guys wanted the translation to be handled, I'd still like to contribute, so please let me know if you want me.
-Aaron