[Python-Dev] Java-ing Python
Thu, 11 Apr 2002 09:44:06 -0500
For a couple of weeks now, I've been trying to figure out how to translate some
java code to python (reason: my app is in Zope, and I want to add some
functionality which is coded in java ...re-coding from scratch is last resort).
My 'quest' brought me to ANTLR, which eases such source-to-source translations.
And this morning I 'discovered' python's Grammar file. And then lightning
(at least it felt like it ...) stroke: what if I replace Python's Grammar
file with a Java grammar (for example, the java grammar included in the ANTLR
distribution). Hacked appropriately to map java source to the tokens defined
in python's Grammar would in theory make python 'understand' java.
I have no idea yet if such exact 1-to-1 mapping of tokens is at all possible.
Moreover, replacing Python's Grammar file with a Java Grammar will obviously
render any python source totally foreign to the python parser.
Of course, the reason to brutally replacing Python's original grammar is to
provide a fast hack who could fall into place and not break anything.
The costlier alternative seems to hack more heavily the graminit.h and so on
and add the Java Grammar 'alongside' Python's Grammar.
I would like some feedback on this from the list, and would also like to know
if Python provides some easier way to add a Grammar to the language, without
the need to hack the C source ('cause, incidently, I kinda suck at C).