tags:

views:

524

answers:

5

I looked into Logix and EasyExtend for Python. Logix hasn't been around for a while and it failed to install on Python 2.6. EasyExtend's tutorial is hopeless, the code in the tutorial doesn't even work.

I am looking for something so I can write my DSL. My DSL will be used as a research tool. And I don't want to spend time learning all that parsing and compiler theory.

+1  A: 

You don't need to "learn all that parsing and compiler theory". Parsing isn't as hard as you might think, and Python has lots of parsing tools: Python Parsing Tools. And compiler theory won't apply, since you'll likely interpret your DSL.

Ned Batchelder
+2  A: 

Ned Batchelders list of parsing tools is very comprehensive. I would recommend out of it pyparsing to do your dsl as I have managed ,with little experience of parsing, to make my own. The learning curve is pretty shallow and the resulting code is readable as it steers away from complex regular expressions. There are plenty of examples and tutorials that can be found from the website.

David Raznick
excellent advice, pyparsing is very good.
Francesco
These are all Python specific parsing tools?
Ira Baxter
+6  A: 

It really depends.

It really depends on what you think of when you speak of a DSL. More specifically, is it essential for you to define new syntax? I think this is quite crucial, because if syntax is not essential, then why not use the syntax of the hosting language (Python in your case, I presume)?!

Is it essential to be able to type

rotate circle 45°

or is it just fine to say

rotate(circle, degree=45)

or even

circle.rotateByDegree(45)

IIRC, it was Paul Graham who said any kind of decent programming is actually inventing a language (the term DSL wasn't popular at that times). You define basic functions (the "verbs") and data structures (the "nouns"), and then try to express your solution in terms of these basic functions and data structures (maybe you have layers of these functions and data structures, with each layer closer to your "domain language"). If it is fine for you to express your solution in something like circle = Circle(); circle.rotate(degree=45), you're all done. I think Python has a nice, convenient syntax so I would probably always choose to stay away from inventing new syntax. Several functional languages like Haskell have a parentheses-less, comma-less way of applying functions to parameters so working code really looks like rotate circle 45.

If that isn't quite good enough for you, and you really depend on new syntax, then you might want to consider Lisp macros or Rebol's dialects, before resorting to general grammar and parsing work. Also, several other languages allow you to specify infix operators on the fly.

The crucial question is: How much syntax do you need?

EDIT: I guess the basic distinction I was trying to make was that between an internal and an external DSL; wasn't aware of the terminology at that time.

ThomasH
More importantly, what are the semantics of of the syntax you want to write, and how well do those semantics directly integrate into some existing language you are willing to use? If you are OK with writing C# API calls, then you better be willing to live with procedural semantics and side effects. If you want a constraint system or a side-effect free system, you'll find that limiting yourself to your favorite langauge's computation model will considerably damage the value of your DSL.
Ira Baxter
Yes, it was Graham: http://www.paulgraham.com/head.html
none
+3  A: 

You can use Rebol embedded DSL engine to create DSL in 5 minutes, see several real-world examples here:

DSL Wrapper for yUML, C#, Java Code Generation http://reboltutorial.com/blog/easy-yuml-dialect-for-mere-mortals/ http://reboltutorial.com/blog/create-your-own-dsl-for-java-or-c-part-4-adding-a-semantic-layer/ http://reboltutorial.com/blog/create-dsl-3/

Rebol Tutorial
A: 

Our DMS Software Reengineering Toolkit is an ecosystem for building custom language translators. It provides strong support for defining grammars complete with automated AST construction, symbol table construction, source-to-source rewrite rules, as well as full language grammars (for Java, C#, C, C++, COBOL, many others) to be used for the target of your DSL code generation, or as a foundation if you want to graft your DSL into an existing langauge.

Available in 2009? Available since 1998 :-} and continuing to grow in capability. (Additions in recent years include full, global, control and data flow analyses.)

DMS has been in heavy use for these tasks all along!

Ira Baxter