Re: [Tutor] Meta language and code generation
On 04/02/2011 06:38 AM, Knacktus wrote: Am 01.04.2011 20:56, schrieb Karim: On 04/01/2011 08:29 PM, Knacktus wrote: Am 01.04.2011 19:09, schrieb Karim: Hello All, I would to ask you if somebody has experience or can give direction in a new project I have. I have a meta language description (in xml) from which I should generate code on different languages. In my case, lisp and tcl. You need to provide more information of your description to get some specific hints. The other day a had a xml file containing a business object model with hierarchy and relations. Then I wrote a code generator to build a module with Python classes for each business item. The code generator created properties for lazily resolving relations modelled via ids in the database and stuff like that. This was very straightforeward using a simple print statements like the following: print "class %s(object):\n" % class_name print " def __init__(self, %s)" % constr_arg ... Cheers, Jan In fact in xml I have something like that: A metafunction in fact kind of x y I have to generate the call_back_do_stuff_function(x,y) in lisp and tcl according to a catalog of specs of what this function must do generically. I can do prints for each metafunctio I read but my concern is is there std libs to help to have good design and methodology. Is it interesting to use command module of something like that, is interesting to use a parser like pylex or pyparsing? I have 50 metafunctions in catalog for now. In fact, my point is to have a great extensive design methodology. Strategy pattern would suit? Other patterns? std modules? No ideas about patterns or standarad lib modules from my side, but a short description of how I would do it: Create an abstraction for the catalogue. That's as far as I can see the hardest part. Here you have to decide if and how to split the things your functions have to do into reusable chunks. Then create code generators for these chunks (using print statements). You can name these functions and store the references in dicts like catalog_comp_name_to_tcl_gen. If you get new functions that need new building blocks you can write new generator functions and extend your dictionaries. The generation of your tcl and lisp "functions-frames" should be straigt forward. You need to link the parameters to the building block generator functions you've created before. When you're done with that, you can improve the design step by step. Too me, this approach works better than thinking to much about design in advance, as often you don't see what you really need unless you've started to code. HTH, Jan Thank you very much Jan! I have a direction. I see the the light now ;o). Karim Lots of question here! Regards Karim Any idea in term of design, examples, links will be appreciated! Kind Regards Karim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Meta language and code generation
Am 01.04.2011 20:56, schrieb Karim: On 04/01/2011 08:29 PM, Knacktus wrote: Am 01.04.2011 19:09, schrieb Karim: Hello All, I would to ask you if somebody has experience or can give direction in a new project I have. I have a meta language description (in xml) from which I should generate code on different languages. In my case, lisp and tcl. You need to provide more information of your description to get some specific hints. The other day a had a xml file containing a business object model with hierarchy and relations. Then I wrote a code generator to build a module with Python classes for each business item. The code generator created properties for lazily resolving relations modelled via ids in the database and stuff like that. This was very straightforeward using a simple print statements like the following: print "class %s(object):\n" % class_name print " def __init__(self, %s)" % constr_arg ... Cheers, Jan In fact in xml I have something like that: A metafunction in fact kind of x y I have to generate the call_back_do_stuff_function(x,y) in lisp and tcl according to a catalog of specs of what this function must do generically. I can do prints for each metafunctio I read but my concern is is there std libs to help to have good design and methodology. Is it interesting to use command module of something like that, is interesting to use a parser like pylex or pyparsing? I have 50 metafunctions in catalog for now. In fact, my point is to have a great extensive design methodology. Strategy pattern would suit? Other patterns? std modules? No ideas about patterns or standarad lib modules from my side, but a short description of how I would do it: Create an abstraction for the catalogue. That's as far as I can see the hardest part. Here you have to decide if and how to split the things your functions have to do into reusable chunks. Then create code generators for these chunks (using print statements). You can name these functions and store the references in dicts like catalog_comp_name_to_tcl_gen. If you get new functions that need new building blocks you can write new generator functions and extend your dictionaries. The generation of your tcl and lisp "functions-frames" should be straigt forward. You need to link the parameters to the building block generator functions you've created before. When you're done with that, you can improve the design step by step. Too me, this approach works better than thinking to much about design in advance, as often you don't see what you really need unless you've started to code. HTH, Jan Lots of question here! Regards Karim Any idea in term of design, examples, links will be appreciated! Kind Regards Karim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Meta language and code generation
On 04/01/2011 08:29 PM, Knacktus wrote: Am 01.04.2011 19:09, schrieb Karim: Hello All, I would to ask you if somebody has experience or can give direction in a new project I have. I have a meta language description (in xml) from which I should generate code on different languages. In my case, lisp and tcl. You need to provide more information of your description to get some specific hints. The other day a had a xml file containing a business object model with hierarchy and relations. Then I wrote a code generator to build a module with Python classes for each business item. The code generator created properties for lazily resolving relations modelled via ids in the database and stuff like that. This was very straightforeward using a simple print statements like the following: print "class %s(object):\n" % class_name print "def __init__(self, %s)" % constr_arg ... Cheers, Jan In fact in xml I have something like that: A metafunction in fact kind of x y I have to generate the call_back_do_stuff_function(x,y) in lisp and tcl according to a catalog of specs of what this function must do generically. I can do prints for each metafunctio I read but my concern is is there std libs to help to have good design and methodology. Is it interesting to use command module of something like that, is interesting to use a parser like pylex or pyparsing? I have 50 metafunctions in catalog for now. In fact, my point is to have a great extensive design methodology. Strategy pattern would suit? Other patterns? std modules? Lots of question here! Regards Karim Any idea in term of design, examples, links will be appreciated! Kind Regards Karim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Meta language and code generation
Am 01.04.2011 19:09, schrieb Karim: Hello All, I would to ask you if somebody has experience or can give direction in a new project I have. I have a meta language description (in xml) from which I should generate code on different languages. In my case, lisp and tcl. You need to provide more information of your description to get some specific hints. The other day a had a xml file containing a business object model with hierarchy and relations. Then I wrote a code generator to build a module with Python classes for each business item. The code generator created properties for lazily resolving relations modelled via ids in the database and stuff like that. This was very straightforeward using a simple print statements like the following: print "class %s(object):\n" % class_name print "def __init__(self, %s)" % constr_arg ... Cheers, Jan Any idea in term of design, examples, links will be appreciated! Kind Regards Karim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Meta language and code generation
On Fri, Apr 1, 2011 at 1:09 PM, Karim wrote: > > Hello All, > > I would to ask you if somebody has experience or can give direction in a > new project I have. > I have a meta language description (in xml) from which I should generate > code on different > languages. In my case, lisp and tcl. > > Any idea in term of design, examples, links will be appreciated! > > Karim, You might want check out Anltr. We were using it to translate from one query language to another. http://www.antlr.org/ http://www.antlr.org/api/Python/index.html -Tino ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Meta language and code generation
Hello All, I would to ask you if somebody has experience or can give direction in a new project I have. I have a meta language description (in xml) from which I should generate code on different languages. In my case, lisp and tcl. Any idea in term of design, examples, links will be appreciated! Kind Regards Karim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor