views:

66

answers:

2

say i found a good open source software/library written in python. i want to wrap some of the functions or methods that i have created into easy to understand language of my own.

do porter_stemm(DOC) (the DSL) would be equivalent to the function or series of methods written in python.

i want to create a DSL that is easy to learn, but need this DSL translated into the original open source software software.

im not sure if i am clear here but my intention is:

  1. create an easy to learn code language that users can use to solve a problem in a certain niche.
  2. this simple language needs to be translated or compiled or interpretated via some middleware into the original open source software's language (python).
A: 

Typically a DSL would still have the same basic syntax as its host language, and simply extend the language's capabilities. So everything for you is still written in Python, it's just Python with some domain-specific functions, variables, etc.

My experience with DSLs is mostly with the Lisp family of languages. There, a typical DSL might be implemented with Macros, which generate code-patterns that are specific to the DSL. (Plus, functions relating to the DSL). The point is, although the macros and functions may extend the capabilities of the language, they are still implemented in that language.

I suppose you could go a step farther and write an interpreter in Python - but there you still get Python runnability for free, as your interpreter translates your custom language back into Python.

Greg Harman
+1  A: 

Write your DSL's syntax and a parser for it, e.g., in Python, with pyparsing (simpler than the traditional lexx-yacc like approach) -- the parser can produce a tree of semantically meaningful nodes, and then you can (simpler) walk that tree and interpret it, or (a bit less simple) walk that tree and generate equivalent Python code. That's the approach I'd suggest for most host languages. Some host languages (Lisp and Scheme being the main ones) have powerful macros, so building a DSL out of macros is more common in those languages.

Embedding your DSL in the host language basically means you're not really doing a DSL but a more traditional framework, so that's really a different approach (possibly more powerful, but may be not quite as easy to learn for non-programmers;-).

Alex Martelli