Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Language Work Benches in Py

Reply
Thread Tools

Language Work Benches in Py

 
 
yoda
Guest
Posts: n/a
 
      09-03-2005
Hi,
I recently read Martin Fowler's article on language workbenches and
domain specific
languages(http://www.martinfowler.com/articles...orkbench.html).
I then had the pleasure of reading Rainer Jowsig's implementation of
the sample in Lisp(http://lispm.dyndns.org/news?ID=NEWS-2005-07-08-1).

The lisp code was so sexy that I was inspired to write a sample in
Python. I'm relatively new to coding in Python so I'd love any barbs,
comments or criticisms about the code. You can find my article here :
(http://billionairebusinessman.blogsp...hands-in.html).

I also made a screen cast of the same
(http://openenterpriseafrica.com/neo/...ython.wmv.bz2).
Unfortunately, I had to make it using a windows machine so it's encoded
as wmv. (If anyone finds it useful and is inspired to encode it in a
more palatable format e.g. mov, I'd be honoured to create a torrent and
host it)

 
Reply With Quote
 
 
 
 
yoda
Guest
Posts: n/a
 
      09-07-2005
I realize that I forgot to post the sample code. Below is my
implementation:

#DSL data
#1234567890123456789012345678901234567890123456789 01234567890,

dsldata=(
'SVCLFOWLER 10101MS0120050313.........................',
'SVCLHOHPE 10201DX0320050315........................',
'SVCLTWO x10301MRP220050329..............................',
'USGE10301TWO x50214..7050329...............................')

#Class mappings
Mappings={'svcl':{
(4,1:'CustomerName',
(19,23):'CustomerID',
(24,27) :'CallTypeCode',
(28,35) : 'DateOfCallString'},
'usge':{(4, :'CustomerID',
(9,22):'CustomerName',
(30,30):'Cycle',
(31,36): 'ReadDate'}}


def generateClass(data):
'generate the class and instance with attributes'

className = data[:4].lower() #1)
mappingData= Mappings[className] #2)
class Klassass #3)
Klass. __name__=className #4)
# print Klass

for key in mappingData.keys(): #5)
fielddata=data[key[0]:key[1]]
print 'actual data->',fielddata
setattr(Klass,mappingData[key],fielddata) #6)
return Klass


def parseData():
'parse the data and generate a list of objects'
classes= [generateClass(item) for item in dsldata]
return classes

def printKlassData(Klass):
print Klass
for key in Klass.__dict__:
print ('attr->%s value->%s')%(key,Klass.__dict__[key])

if __name__=='__main__':
for Klass in parseData():
printKlassData (Klass)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
needed basics of FIFO design and in writing test benches chaitu VHDL 2 02-21-2007 10:29 AM
A language-agnostic language Ed Java 24 03-27-2006 08:19 PM
nvidia SLI benches. Dave - Dave.net.nz NZ Computing 0 10-30-2004 04:18 AM
Python is the best and most popular general purpose scripting language; the universal scripting language Ron Stephens Python 23 04-12-2004 05:32 PM
FFI against VHDL for test-benches Spur VHDL 4 09-15-2003 09:20 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57