Using Python to generate code?

Larry Bates lbates at swamisoft.com
Wed Sep 8 09:59:56 EDT 2004


I use Python to generate quite a bit of HTML and
JavaScript code and it works very well.  If you
can use Python's classes to abstract individual
elements and give each of them a __str__ method
you can build very complex code generator classes
that know how to render their own output.

Larry Bates
Syscon, Inc.

"Tran Tuan Anh" <anhtt at hotmail.com> wrote in message
news:ed89f8f2.0409072251.2152c22b at posting.google.com...
> Dear all:
>
> I need your advice on this matter. I am working on a program which
> takes some pieces of System-C code in and generate some other System-C
> code. (System-C code is just C++ with some special libraries, hence
> you can consider it as C++).
>
> Right now, the generator program is written in C++. And I feel not so
> comfortable with C++. I feel C++ is an overkill. Because, I need to
> generate some code, hence in the program there are a lot of something
> like this:
>
> printf(out, "for (%s = 1, %s < %s, %s < %s )", varName, varName,
> varName1, varname, varName2);
>
> It is just too messy if I have more than 20 lines like this.
>
> So my question is:
> 1. Can Python help to solve this issue?
> 2. Does Python has a parser? It seems to me that there is no-standard
> Parser for Python right now. If it is the case, can I interface Python
> with existing cup and lex?
>
> Many thanks!
> Tuan Anh
> P/S: Also because it is NO big code generator, it only needs to
> generate some simple codes. Hence, using some abstract-syntax-tree
> library is also too an overkill.





More information about the Python-list mailing list