I think you can use python itself for "pre-processing". Here is an (shortened) example from PyPy RPython paper:<br><br># operators: the docstrings contain the<br># symbol associated with each operator<br>class Op_Add(BinaryExpr):<br>

    ’+’<br>class Op_Sub(BinaryExpr):<br>    ’-’<br><br># INIT-TIME only: build the table of<br># opcodes and add the ’eval’ methods<br>def gen_eval(ch):<br>    code = """<br>    def eval(self):<br>        return self.l.eval() %s self.r.eval()<br>

    """<br>    d = {}<br>    exec code.strip() % (ch) in d<br>    return d['eval']<br>OPCODES = {}<br>def build_opcodes():<br>    for name, value in globals().items():<br>        if name.startswith(’Op_’):<br>

            value.eval = gen_eval(value.__doc__)<br>            OPCODES[value.__doc__] = value<br>build_opcodes()<br><br>From the paper:<br>"""<br>The eval method is generated via a call to the helper<br>routine gen_eval, which creates a string of Python code that<br>

performs the desired computation and uses exec to compile<br>this string into a Python method.<br><br>Adding the class object to the OPCODES dictionary is done<br>by simple assignment, using the class docstring as the key<br>

and the class object itself as the value.<br>"""<br><br>You might also want to have a look at PyGirl, the Nintendo Gameboy emulator of the PyPy project written in RPython (a subset of Python that allow static type inference). There is probably some ideas to borrow. The paper on PyGirl also details some of the "pre-processing" trick they used. They sometime call it meta-programming but its all the same, generating code with code :).<br>

<br>See <a href="http://codespeak.net/pypy/dist/pypy/doc/extradoc.html">http://codespeak.net/pypy/dist/pypy/doc/extradoc.html</a> for more info and look-up the rpython and pygirl docs.<br><br><div class="gmail_quote">2009/11/14 greg <span dir="ltr"><<a href="mailto:greg@cosc.canterbury.ac.nz">greg@cosc.canterbury.ac.nz</a>></span><br>

<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">Santiago Romero wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
 Can the above be easily done with another already-existing<br>
application? (example: can m4 do this job)?<br>
</blockquote></div></blockquote></div><br>